I’m currently working on a design that uses text-shadow and box-shadow, with RGBA in place to create the shadow color. I wanted to tweet about this technique because it’s simple and awesome, but to my surprise I couldn’t find a good, quick tutorial that covered the use of both text and box-shadow, along with RGBA. So I decided to create one.
I learned this technique from Dan Cederholm’s Handcrafted CSS book, so if you’re able I’d recommend just going out and grabbing that, as he explains it much more elegantly and thoroughly than I ever could.
Text-shadow
Applying text-shadow to elements is easy, and coupled with RGBA it works beautifully. Since both text-shadow and RGBA are supported by Safari, Firefox, Konqueror, and Opera, why not start playing with them now?
Text shadow is sexy.
If you’re using one of the aforementioned browsers, you should see a nice drop shadow on the text above. (If you’re not — why?) This drop shadow is created using the following code:
text-shadow: 1px 1px 1px rgba(0,0,0,.4);
Breaking it down
- The first
1pxindicates how much the shadow should be offset horizontally; in this case we’re telling the shadow to appear one pixel to the right. Using-1pxwould move the shadow one pixel to the left. - The second
1pxindicates how much the shadow should be offset vertically; in this case we’re telling the shadow to appear one pixel lower than the text. Using-1pxwould move the shadow one pixel above the text. - The third
1pxvalue tells the shadow how much it should blur. Using0for this value would create a solid drop shadow, which has a blocky, high-contrast effect. Using only this value (ex.text-shadow: 0 0 1px rgba(0,0,0,.4);) would create an outer glow. rgba(0,0,0,.4);gives the shadow its color. In this case we’re using(0,0,0), which is the RGB value for black, and we’re giving that black an opacity of 40%, or.4.
Why use RGBA for the shadow color?
Using RGBA instead of a solid color for the shadow is great because it allows some of the page’s background color to bleed through. This means that the shadow will blend nicely with the page’s existing color scheme, and if you ever change up the site’s background color your shadows will change too. If you’re unclear about how rgba works, check out Drew McLellan’s 24ways article.
So now you should be able to implement text-shadow and RGBA in your designs. This technique is very powerful, as it can be used to make text jump off the page:
Text shadow is sexy.
or appear to be set into the page:
Text shadow is sexy.
Box shadow
Once you know how to use text-shadow + RGBA to achieve drop shadows, you’re well on your way to mastering box-shadow. The syntax is exactly the same, so box-shadow: 0 1px 10px rgba(0,0,0,.1); will create a black shadow at 10% that’s centered horizontally, one pixel down, with a ten pixel blur.

Misty the one-toothed cat thinks box shadow is awesome.
Box shadow is supported in Safari and Firefox 3.5, but like border-radius it requires the use of vendor-specific properties. So assuming we wanted to add a drop shadow to an image in Safari and Firefox, here’s how we’d code it:
-webkit-box-shadow: 0 1px 10px rgba(0,0,0,.1);
-moz-box-shadow: 0 1px 10px rgba(0,0,0,.1);
box-shadow: 0 1px 10px rgba(0,0,0,.1);
You’ll notice I included the standard box-shadow property; this is in place for future browsers who may one day support this property.
There you have it! Once again your shadow blends nicely with the background because you’re using RGBA, and creates a kick-ass 3-D effect with minimal markup.
Box-shadow and text-shadow may not be for every project, but since they’re so easy to implement and browser support for these features is growing, why not try them out?
I can hear some of you naysayers yelling about Internet Explorer, but really is it so bad if some users get to see shadows and some don’t? The design won’t be broken for IE people, they’re just missing out on a few visual treats that other users will see.
If you’re not sold on the argument that we should reward users who choose modern browsers, check out Dan’s Handcrafted CSS book, Aaron Gustafson’s A List Apart article and Andy Clarke’s multiple well written articles on the subject.

Me on January 15, 2011 at 5:48 am
Text shadows is useful but only in places where you want an image to stand out that little bit more.As some one already pointed out too much shadow is a bad thing. With using CSS3 shadow people will have to sort out that detail them selfs. So taken that in to account Text shadow can be sexy at times.
RayRogers on February 6, 2011 at 10:54 am
Shadows and CSS3 works in Chrome but not as good I think.
Rohit Mishra on February 8, 2011 at 9:39 am
Thanks a lot for another great tutorial. This website has been my gateway to HTML 5 and CSS 3.
Solar Monster on April 21, 2011 at 12:21 pm
I like the letter press ideas, I wanted to let you know I’ll be using it on my site!!
- Aaron
Bloodstock Tickets on June 15, 2011 at 3:26 pm
I will be using this effect when I get my site up and running. Thanks for this tutorial, never underestimate the power of CSS!
-Joe
Rob Benwell Wiki on July 29, 2011 at 6:26 pm
I have been browsing online more than three hours today, yet I never found any interesting article like yours. It is pretty worth enough for me. In my view, if all web owners and bloggers made good content as you did, the internet will be much more useful than ever before.
Esp Bass on August 2, 2011 at 3:48 pm
Hello there, just became aware of your blog through Google, and found that it is really informative. I am gonna watch out for brussels. I will be grateful if you continue this in future. Numerous people will be benefited from your writing. Cheers!
Oliver on August 16, 2011 at 9:44 am
I agree. The cat is definitely stashing some pieces of eight!
Diseño Web Terrassa on September 24, 2011 at 8:55 am
Thanks for the info, I have been helpful.
PD: That cat’s a little scary xD
DMC on December 22, 2011 at 7:51 am
People who use IE hate the internet. Fact.