Feature
Post

Category
Design


5 CSS Shadow Tips

When used properly, shadows can make a good design look great. The key, of course, is the phrase “when used properly”. If you haven’t experimented with CSS shadows, here are some quick ways:

Shadow to Text using text-shadow

h3 {text-shadow: 0.1em 0.1em #999}

In this example, we are defining a grey (#999) shadow, positioned slightly to the right (.1em) and slightly below (.1em) the h3 text. The definitions are:

  1. The color of the shadow.
  2. The x-coordinate of the shadow.
  3. The y-coordinate of the shadow.
  4. The blur radius of the shadow. (not used in this example)

*Note that the coordinates are relative to the position of the text. Also, you can define the color either before or after the coordinates. Learn more about the text-shadow property at the W3C.

Drop Shadows

You can use a PNG for your shadow, as illustrated here (less code), or use pure CSS (more code), as described here. Finally, WordPress users will want to take a look at the WordPress Shadows Plugin.

Moving along: because we love tips around here, here are five tips on ways to make them work well for you:

A little goes a long way.

You may be tempted to add shadows to everything. Don’t. By restraining yourself, and apply shadows only to a few key elements, you can make the latter really “pop”.

Add subtle shadows to text.

I did say restrain yourself, but at the same time, using subtle shadows on all your text can look great. For example, the letterpress effect looks beautiful and can enhance readability- which is always a good thing.

Go lighter.

Stay away from using black as your shadow- it looks unnatural, and can make your text more difficult to read. Commonly used colors are #666, #999, and #CCC.

Experiment with multiple shadows and other techniques.

As shown in the W3C examples, you don’t have to limit yourself to just one shadow per element. Another technique is to use shadows to create text outlines (good for white text on a light background). Play around a bit, but don’t overdo it.

Test, test, test.

Finally, remember that text-shadow is not fully supported on all browsers yet. Make sure your design still looks as good as possible with lots of testing on different browsers at different resolutions.

Do you use CSS shadows?


  1. By Alex Aguilar posted on March 21, 2010 at 7:46 pm
    Want an avatar? Get a gravatar! • You can link to this comment

    Didn`t know that we are able to put shadow with CSS…
    Or..is this a new feature of CSS 3?

  2. By Mark Eagleton posted on March 23, 2010 at 2:35 pm
    Want an avatar? Get a gravatar! • You can link to this comment

    Here is the RGBA version of the above rule that works in Webkit, Opera and Geko browsers:

    h3 { text-shadow: rgba(0,0,0,.5) .1em .1em .1em; }

    I find I have more control with rgba, especially when creating highlight and emboss effects for text.

  3. By Billee D. posted on March 23, 2010 at 3:54 pm
    Want an avatar? Get a gravatar! • You can link to this comment

    Thanks for the read, Lorraine. I would have to say that I disagree with one concept:

    Stay away from using black as your shadow- it looks unnatural, and can make your text more difficult to read.

    In my own experience I have found that black (and white) work rather well when you specify the color in RGBA syntax and apply a low opacity:


    h1 {
    text-shadow: 0.055556em 0.055556em 0.083334em rgba(0, 0, 0, 0.3);
    }

    Specifying the color of the shadow in RGBA syntax allows the semi-transparent, all black shadow to blend into the background color it sits above. You can check out an example I put together here: http://dl.dropbox.com/u/126928/text-shadow-test.html

    By sticking with RGBA black for the text shadows you can easily change the background color without having to change the text shadow color. It blends nicely into any background. I’m pretty sure I first saw this done on Wilson Miner’s website. It’s a pretty safe bet that the browsers that implement text-shadow also have RGBA support as well. There are even ways to fake it in IE using the proprietary filter syntax.

    Thanks for the read! :)

  4. By Jon L. posted on March 25, 2010 at 9:20 pm
    Want an avatar? Get a gravatar! • You can link to this comment

    Good point, Billee – I’ve also found the low opacity black shadow to be extremely useful.

  5. By Scott Foley posted on March 29, 2010 at 5:34 am
    Want an avatar? Get a gravatar! • You can link to this comment

    Great article. Now if IE would get on board it would be even better!

  6. TrackbackPuppy Training Tips: Get A Jump Start Training Your New PuppySome links for light reading (23/03/10) | Max Design