CSS3 Box Shadows

css3 box shadows

Shadows have been around since the beginning of CSS2, however the only browser supporting them then (and continually now) was Safari. Shadows can be applied in CSS3 to borders, images as well as affecting text as well.

The CSS3 box-shadow is written box-shadow: Apx Bpx Cpx #XXX;
- Apx = x-axis
- Bpx = y-axis
- Cpx = cast length / feathering
- #XXX = colour as usual

CSS3 Box Shadow

This is a panel set with a 5 by 5 pixel box-shadow, cast by 7px.

  1. CSS3 Border Shadow
  2. #my_CSS3_id {
  3.   border: 5px solid #c4c8cc;
  4.   -moz-box-shadow: 5px 5px 7px #888;
  5.   -moz-border-radius-bottomright: 15px;
  6.   -webkit-box-shadow: 5px 5px 7px #888;
  7.   -webkit-border-bottom-right-radius: 15px;
  8. }

This effect can also be applied to images… image

An example for those on alternative browsers, not seeing the border-shadow effect..

 

The Zen Elements CSS3 Series

Thank you for reading!
@zenelements // Alex

Like this article?

Subscribe to our rss, follow our tweets or please help us spread the work & share this with your friends!

Thank you for all your support; have a cookie!

18 Comments on “CSS3 Box Shadows”

  1. Nick Cowie 13.01.2009 at 4:13 am

    There is a little bug with Chrome when box-shadow and border-radius is combined, shows in your example but not as disastrous as mine http://nickcowie.com/2008/google-chrome-is-frustrating-me/

  2. Zen Elements 13.01.2009 at 9:13 am

    @Nick, hello. Thank you for stopping by and giving your feedback. Always appreciate it.
    I see how you mean in your example for those CSS buttons, which is a good idea in itself. It is a great nuisance that even the newer browsers are giving poor support to the progression of CSS3 so I agree wholeheartily with when you argue ‘why we should care?’ in your post. If we want to see CSS3 (and the future generation languages), we should care and show the browsers we care. *waves a fist at them all*

    Alex | Zen Elements

  3. Mountain/\Ash 20.01.2009 at 10:33 pm

    These style elements also work for Mozilla/Firefox but you have to add the vendor-specific “-moz” prefix. These are working fine for me using Firefox 3.1b2.

  4. Zen Elements 21.01.2009 at 11:54 pm

    Thank you for the update. I will try get my hands on that version asap and amend after clarifying. Can see this will be a tricky series to keep tabs on so hurry up browsers and get compatible! ;)

  5. alex 06.05.2009 at 7:12 am

    Nice work on CSS3, more articles please

  6. css ajax styles 08.09.2009 at 9:53 am

    yes very nice tutorial but the issue is we can not apply them due to browsers compaitibility.

  7. Marco 12.02.2010 at 2:49 pm

    box-shadow doesn’t work for me either with G Chrome… and when combined with radius, there’s a bug in firefox too.

  8. Bertrand 01.04.2010 at 3:44 pm

    (Sorry I’m late in the bandwagon, Google brought me here) Thanks for the tutorial! Just wanna point out Safari is slowing down when using long shadow (like 100px and more). Maybe the other browsers too. Not that I plan on doing this but it’s great know… at least I think!

  9. DJ RyThEm 09.04.2010 at 11:52 am

    Hey there, nice tutorial! i have a question though and I’m not exactly sure if it’s possible or not but is there away to have the box shadow on the left and right of a box rather then the right/bottom? i’ve tried several times to get this to work but no luck… iv been working with CSS for 5 years now and all i can say is WOW THINGS CHANGE!

  10. Zen Elements 09.04.2010 at 3:02 pm

    Hello and thanks for your comment and feedback!
    I’m afraid you will be pushed to find a solution to your left/right requirement of the box-shadow property, as control is only given to direct the cast of the shadow as supposed to warp it. One possibility though, while you will get a little cast above/below, is to experiment using two containing layers:

    .box1 {-moz-box-shadow:3px 0 3px #333; width:#px; height:#px;}
    .box2 {-moz-box-shadow:-3px 0 3px #333; width:#px; height:#px;}

    I hope this helps!

  11. borntowinanwar 17.05.2010 at 7:28 am

    Nice Article. Very helpful article.
    i enjoyed.
    Thnaks

  12. Joe 03.06.2010 at 1:26 pm

    You can combine box shadows within one layer by separating the values with commas. Applying this to the example above, one would use:

    box1 {-moz-box-shadow:3px 0 3px #333, 3px 0 3px #333; width:#px; height:#px;}

  13. dorys 08.03.2011 at 1:28 am

    Just did Joe’s trick on my website and it worked perfectly.

  14. Werbung Netz 21.03.2011 at 8:07 pm

    Thanks for the nice Information. I create a new Theme for my Blog and search Online for solutions.

  15. James of BWS 31.03.2011 at 4:34 pm

    In reference to DJ RyThEm’s question, and Zen Elements response, I have had a limited degree of success creating a shadow to the left and right (and probably to the top and bottom as well, but they’re off the page).

    For my page, I wanted shadow on either side to create a “paper” look. This done the trick quite nicely.

    -moz-box-shadow: 0px 0px 50px #000

  16. sawebdesigns 25.04.2011 at 12:34 am

    This is great I could apply this right away to my new project

  17. web design 22.08.2011 at 3:09 am

    This is a great tutorial. This helps me a lot. Thanks.

  18. Roy M J 13.01.2012 at 4:08 pm

    Very nice.. Just what i needed..

 

Leave a Reply

(required; who are you?)

(required; we'll keep it safe!)

(optional; promote your site!)