5.x common.inc drupal_add_css($path = NULL, $type = 'module', $media = 'all', $preprocess = TRUE)
6.x common.inc drupal_add_css($path = NULL, $type = 'module', $media = 'all', $preprocess = TRUE)
7.x common.inc drupal_add_css($data = NULL, $options = NULL)

Adds a CSS file to the stylesheet queue.


$path: (optional) The path to the CSS file relative to the base_path(), e.g., /modules/devel/devel.css.

$type: (optional) The type of stylesheet that is being added. Types are: module or theme.

$media: (optional) The media type for the stylesheet, e.g., all, print, screen.

$preprocess: (optional) Should this CSS file be aggregated and compressed if this feature has been turned on under the performance section?

What does this actually mean? CSS preprocessing is the process of aggregating a bunch of separate CSS files into one file that is then compressed by removing all extraneous white space.

The reason for merging the CSS files is outlined quite thoroughly here: http://www.die.net/musings/page_load_time/ "Load fewer external objects. Due to request overhead, one bigger file just loads faster than two smaller ones half its size."

However, you should *not* preprocess every file as this can lead to redundant caches. You should set $preprocess = FALSE when:

  • Your styles are only used rarely on the site. This could be a special admin page, the homepage, or a handful of pages that does not represent the majority of the pages on your site.

Typical candidates for caching are for example styles for nodes across the site, or used in the theme.

Return value

An array of CSS files.

Related topics

15 calls to drupal_add_css()
block_admin_display in modules/block/block.module
Generate main block administration form.
chameleon_page in themes/chameleon/chameleon.theme
color_scheme_form in modules/color/color.module
Form callback. Returns the configuration form.
drupal_get_css in includes/common.inc
Returns a themed representation of all stylesheets that should be attached to the page. It loads the CSS in order, with 'core' CSS first, then 'module' CSS, then 'theme' CSS files. This ensures proper cascading of styles…
drupal_maintenance_theme in includes/bootstrap.inc
Enables use of the theme system without requiring database access. Since there is not database access no theme will be enabled and the default themeable functions will be called. Some themeable functions can not be used without the full Drupal API…

... See full list


includes/common.inc, line 1576
Common functions that many Drupal modules will need to reference.


function drupal_add_css($path = NULL, $type = 'module', $media = 'all', $preprocess = TRUE) {
  static $css = array();

  // Create an array of CSS files for each media type first, since each type needs to be served
  // to the browser differently.
  if (isset($path)) {

    // This check is necessary to ensure proper cascading of styles and is faster than an asort().
    if (!isset($css[$media])) {
      $css[$media] = array(
        'module' => array(),
        'theme' => array(),
    $css[$media][$type][$path] = $preprocess;
  return $css;