Last updated August 26, 2009. Created on May 29, 2006.
Edited by chicagomom, Steven, add1sun, m1mic. Log in to edit this page.

Drupal 5.x

Additional styles sheets can be added to the array by using the drupal_add_css() function:

// Repeat this line for every CSS file added.
drupal_add_css(path_to_theme() . '/example.css', 'theme', 'all', TRUE);
// Reassemble the $styles snippet to include the new files.
$styles = drupal_get_css();

In this example, example.css is retrieved from the theme folder. Alternatively, style sheets can be placed in the files directory and accessed by leaving off the path_to_theme() function and using the 'files/subdirectory/example.css' notation.

The drupal_add_css() function can take the following optional parameters:

  1. Path to the style sheet file (Relative to the base_path())
  2. Type of style sheet being added (module or theme)
    • Style sheets are called in order starting with the system styles sheets, then the module style sheets, and then the theme style sheets. If a style sheet was created to override the CSS that came before it, using the theme option will append it to end of the array and will be called last.
  3. The Media that the style sheet should be applied to (all, screen, print, handheld, etc.)
  4. The Preprocess option will aggregate and compress the style sheet if this feature has been turned on under the performance section (TRUE, FALSE)

For Drupal 4.7.x

print $head;
print theme('stylesheet_import', base_path() . path_to_theme() . '/your_extra.css');
print $styles;

So this is the order we end up with:

  1. drupal.css
  2. module CSS (for example, event.css from event.module)
  3. theme CSS (for example, your_extra.css)
  4. style CSS (style.css files from any theme)

Style sheets can override rules applied in any CSS which precedes them. (i.e. style CSS can override everything else, except for user CSS)

Looking for support? Visit the forums, or join #drupal-support in IRC.


mbria’s picture

For those sad times you need to overwrite a theme style from your module (for instance, common styles for every theme), you can try this:

function style_all_themes_menu() {
drupal_add_css(drupal_get_path('module', 'style_all_themes') .'/style_all.css','theme','screen');

I was getting mad until I noticed that was "iconizer" module was doing.

BTW, thanks to it's author for the tip.

jrc21’s picture

Sorry, I'm new to using drupal, but where would I put this snippet? In page.tpl.php header? body? I'm just trying to make a simple theme for my purposes but can't get it to implement my own stylesheet as of yet.