Drop shadow with CSS for all web browsers
One of the most common CSS effects is using shadows in various ways. Before, we needed to resort to images, but now we can offer this to all major web browser with CSS!
Web browser support
Believe me or not, but all of these web browsers we can offer shadows with CSS:
- Firefox 3.5+
- Safari 3+
- Google Chrome
- Opera 10.50
- Internet Explorer 5.5
The standards way
As we all know, a majority of the web browsers implement features in a standardized way, while others don’t (although they are getting better at it). Previously, in the W3C specification CSS Backgrounds and Borders Module Level 3 box-shadow
was described, although at the moment, it’s not in there for some things to be discussed further. Anyway, this is how the implementation looks:
.shadow { box-shadow: 3px 3px 4px #000; }
The first value describes the x-offset (could be a negative value as well), the second the y-offset, the third the radius of the shadow and the fourth the color of it. Opera 10.50 (currently only available on Windows) is the first web browser to have an implementation without a vendor-prefix, whereas Firefox, Safari and Google Chrome all need it for now. So, this code makes it work in all those web browsers:
.shadow { -moz-box-shadow: 3px 3px 4px #000; -webkit-box-shadow: 3px 3px 4px #000; box-shadow: 3px 3px 4px #000; }
What about Internet Explorer?
Luckily enough for us, there are a couple of filters we can use to make this work: The DropShadow filter and the Shadow filter. The problem with the DropShadow filter is that the shadow is solid, and not fluffy as desired, although it offers easy values for X and Y. The Shadow filter on the other hand offers a nice shadow, but instead of x and y offset, we need to specify direction and strength the set the length of the shadow.
So, this is how we make it work in Internet Explorer:
.shadow { /* For IE 8 */ -ms-filter: "progid:DXImageTransform.Microsoft.Shadow(Strength=4, Direction=135, Color='#000000')"; /* For IE 5.5 - 7 */ filter: progid:DXImageTransform.Microsoft.Shadow(Strength=4, Direction=135, Color='#000000'); }
The combined styles
This all the CSS for various web browser collected in one rule:
.shadow { -moz-box-shadow: 3px 3px 4px #000; -webkit-box-shadow: 3px 3px 4px #000; box-shadow: 3px 3px 4px #000; /* For IE 8 */ -ms-filter: "progid:DXImageTransform.Microsoft.Shadow(Strength=4, Direction=135, Color='#000000')"; /* For IE 5.5 - 7 */ filter: progid:DXImageTransform.Microsoft.Shadow(Strength=4, Direction=135, Color='#000000'); }
What it looks like
Here you can see shadows applied via CSS for an element:
Honorable mention: CSS3 Please!
An easy way to automatically generate these styles and others, cross-browser, is available in the excellent service CSS3 Please! by Paul Irish and Jonathan Neal. Just enter your value, watch its rendering, copy the code and you’re good to go!
A little caveat is that they are currently using the DropShadow filter for IE, but I’m sure that will be updated soon. If you have any feedback about that service, please let Paul know in his post Introducing… CSS3Please.com.
Nice that it's posible but you need a height on the element div in IE7 and IE6. Many times i don't know the height of the element… Unfortunately!
John,
I have only tested in compatibility mode for IE 7 and there it works without height. Otherwise, I'm certain filters will be applied as long as you trigger hasLayout for the element, i.e. adding <code>zoom: 1</code> or <code>height: 1%</code> to it.
Really? Cool!
I don't tested in hasLayout for now. If it would work, thumbs up!
Btw, i found another problem, you can use the class with the filter only for 1 time. If you have multiple items in IE (6 & 7), it will only work in the last block… Is this a problem by hasLayout? 🙂
John,
Nope, it should work for any number of elements with the same class.
What will happen the day MSIE starts to support the standardized rules? Will it ignore filters? Will it honour the cascade and overwrite them using the filter rules?
There are still a few questions like these that needs to be answered.
Lars,
All good questions. My guess, though, is that it will be around for quite some time – don't know much about anything becoming deprecated in IE. So far.
<cough>performance sucks with filters</cough>
😉
Morgan,
Ha ha! 🙂
In all seriousness: yes, it can. It does depend on how much you use it, which filters etc. It all comes down to testing in your own context.
The only problem I see with filters is that when you apply a filter to an element in IE, IE turns off ClearType which makes any text (like in your example) pixelated. ClearType is turned off in IE7 and IE8 when a filter is used on an element. Filters do not turn off ClearType in IE6. This is why for an internal corporate project I worked on which required shadows and IE, I used graphics.
Tanny,
Good point. The turning off ClearType behavior can be an issue.
Thx for the shoutout, Robert. We'll be swapping in Shadow soonly!
Paul,
No worries – you do many great things, and definitely deserve the acknowledgement for it.
[…] Drop shadow with CSS for all web browsers […]
Thanks, it works perfectly.
[…] CSS Drop-Shadow – ebenfalls für alle Browser. […]
amado,
Good to hear!
[…] Drop shadow with CSS for all web browsers – Robert's talk […]
[…] Drop shadow with CSS for all web browsersA tidy collection of all the proprietary box-shadow methods for all modern browsers (AND IE 5.5+). Nice post. Wednesday, March 24, 2010 Filed under: Link Love 947No Commentshttp://www.mattheerema.com/links/2010/03/interesting-web-citings-for-march-24th/Interesting+Web+Citings+for+March+24th2010-03-25+01%3A00%3A00Matt + Share Tags:4gadobeapplebiblebox-shadowbrowserscompatibilitycross-browsercsscss3data-visualizationDesigndietdrop-shadowebooksevidencefoodgraphicshtchtc-evohtml5ideaillustrationinterfaceipadkindlephotoshopprocrastinationproductivityresearchsprinttutorialsuiusabilityuxzefrank […]
[…] via Drop shadow with CSS for all web browsers – Robert’s talk. […]
All Browser = Reality = Great Post.
Thanks man.
Domenico,
Glad you liked it. 🙂
[…] Drop shadow with CSS for all web browsers – Robert's talk "One of the most common CSS effects is using shadows in various ways. Before, we needed to resort to images, but now we can offer this to all major web browser with CSS!" (tags: CSS) […]
Not tried it yet, but certainly will.
We will tell our students to just copy this in rather than explaining every step.
Can`t wait for IE6 to DIE
Carl,
Well, that's nice, but it's important for them to know how and why things work too, in my opinion.
[…] Drop shadow with CSS for all web browsers […]
Good stuff! I wrote a similar article not long ago (Cross-browser drop shadows using pure CSS) which also mentions making the shadow subtler to prevent the horrible hard corners.
Nick,
Ah, nice! Thanks for the tip!
Great things, thx for understanding IE filter.
hey guys , amazing css effects here http://www.weble.net/amazing-css-effect-displacem… . subject is image view displacement method
kkatusic,
Thanks!
carr,
Yes, just like the Coke can thing that was going around.
I can haz… really.. really? I can't wait to see reporters talking like this.. rofl lol lmao omg gtfo
Anthony,
It's coming, soon… 🙂
[…] Drop Shadow With CSS For All Web Browsers […]
[…] Drop Shadow With CSS For All Web Browsers […]
I tried using the above mentioned technique to get drop shadows in IE for a page with a lot of elements and a lot of jQuery.
What I experienced was, the performance degraded a lot to the point of the page not working anymore in IE.
Tried flipping drop shadow on and off and observed a significant change in javascript performance for the page. Probably only happens on very javascript heavy pages, but I just thought I'd mention it.
Cheers,
Nis
Nis,
Absolutely, filters are a performance risk in IE in conjunction with lots of elements, heavy scripting etc.
Thanks for mentioning it too!
Hi, the CSS3Please is great and useful, but as I use TextMate, i thought it would be even better if I could generate the snippets right in the editor (even loosing the ability to preview it). So I've packed the snippets into a simple bundle and here it is:
CSS3-Please-TextMate
Filipe,
Awesome! Thanks for sharing!
This code doesn't work in Mac Opera 10.10 nor Camino.
is there a code to enable that for those browsers????? thanx in advance.
Art,
Sorry, for Opera you will need the latest upcoming version 10.50. With Camino, it depends on which Gecko version it's based on, but it's available from Firefox 3.5 and up.
[…] Drop shadow with CSS for all web browsers – Robert's talk (tags: css css3 shadow cross-browser dropshadow webdesign howto tutorial webdev drop-shadow box-shadow) […]
[…] Comment on Drop shadow with CSS for all web browsers by Napi … […]
[…] Drop shadow with CSS for all web browsers – Robert’s talk / cssz shadow […]
Does not working on my firefox.
Sisir,
Make sure you have Firefox 3.5 or later.
I tested it with IE Version: 6.0.2900.2180.xpsp.050329-1536 but the shadow only reflects on the text on the element "div"
Ronald,
Yes, that could happen. Please try wrapping the text within another element, and the effect might disappear.
[…] Drop shadow with CSS for all web browsers […]
[…] Vía | Robert’s talk […]
This worked great for me! Thanks!
works great, in firefox. but i will cross check it later. Thanks!!!
great technique, but I got a problem on IE6, the shadow are over the content of my div and not on my div 🙁 i followed the steps, and the shadow is in the way content (without spaces) and in the content I have inputs and more…. but they got the shadow not my div on the IE6, any possible solution? 🙁
Drop shadow with CSS for all web browsers ,thanx.
Thank you so much for these great tips. My website will benefit from this. Shadows are a nice subtle way to add some depth.
Thanks again, your time is appreciated!
juan,
Try adding content do the element, and you might get a different result.
Jason,
You are welcome!
[…] Drop shadow with CSS for all web browsers – Robert’s talk […]
[…] out the website, Robert Nyman came to the conclusion that the proprietary Microsoft filter for Shadow looks much prettier than DropShadow, so I forgot about blogging myself as his solution doesn’t rely on unsemantic markup and is […]
[…] found a really excellent technique, here: http://robertnyman.com/2010/03/16/drop-shadow-with-css-for-all-web-browsers/ . This technique fit the bill perfectly for me, in that it used CSS and was cross browser […]
This is an awesome resource. Thank you very much for posting it.
I was sad to discover that setting a shadow in IE affects the width/positioning of the div. In my case I was adding a shadow to the right side of a div that was dynamically positioned with a right value and adding the shadow pushed the div that many more pixels to the right.
Obviously there are many ways around this but still another reason to be disappointed in IE.
Nate,
Thanks, glad you like it! And yes, IE is alway a beast to handle.
Sweet stuff. Thanks!
[…] Kaynak: http://robertnyman.com/2010/03/16/drop-shadow-with-css-for-all-web-browsers/ […]
what's this "IE" people are talking about. Are you talking about the new browser Microsoft is coming out with? 😉
Thanks! this was usefull for us! 😉
I am keen to learn this technique. As a newbie I have spent 45mins trying to get this to work. I have copied / pasted every variation I can think of and now I'm stuck. Can you please clearly explain – like I'm a 6yr old – how I get this to work. Thanks
UPDATE – last email address was incorrect –
I am keen to learn this technique. As a newbie I have spent 45mins trying to get this to work. I have copied / pasted every variation I can think of and now I'm stuck. Can you please clearly explain – like I'm a 6yr old – how I get this to work. Thanks
Richard,
You can take a look at http://robertnyman.com/css3/drop-shadow/drop-shad…
[…] […]
[…] From this site […]
[…] in there for some things to be discussed further. Anyway, this is how the implementation looks: view sourceprint? 1..shadow { 2. box-shadow: 3px 3px 4px #000; […]
Awesome, I was finding drop shadow for IE.
This works perfect for me
Thank you very much! I needed to do a dropdown menu with a shadow, and this is exactly what I was looking for. I guess that's why it's number 1 on google. 😉
You're welcome!
Thanks for article!!! You save my time 🙂
oivoodoo,
Glad it was of help!
[…] haven't tried it but take a peek at this: Drop shadow with CSS for all web browsers – Robert's talk Reply With Quote + Reply to Thread « Previous Thread | Next […]
This is cool trick for shadows and previously i used this trick also,I need shadows for all four sides in IE. Is there any trick?????
I need shadows for all four sides in IE. Is there any trick?????
I got all four sides shadow in IE..Try this.. 🙂
.shadow-ie {
filter: progid:DXImageTransform.Microsoft.Shadow(color='#e3e4e7', Direction=45, Strength=6)
progid:DXImageTransform.Microsoft.Shadow(color='#e3e4e7', Direction=135, Strength=6)
progid:DXImageTransform.Microsoft.Shadow(color='#e3e4e7', Direction=225, Strength=6)
progid:DXImageTransform.Microsoft.Shadow(color='#e3e4e7', Direction=315, Strength=6);
}
sam,
Thanks for the suggestion!
Robert,
Most Welcome…. 🙂
If possible add this stuff in your top content area,(i.e) means your trick demonstration area,so that user can easily find this cool stuff, instead of scrolling the long thread.
I like your comment area, while typing can see the preview also, its cool!!! very nice…
thanks. I’ve tried, Firefox and Chrome work like charm but my IE7 doesn’t seem working. .
[…] One draw back is that this doesn’t work with IE. For an IE solution, check out robertnyman.com post for IE shadows using filters. […]
Couldn’t get you? which one doesn’t work.. robert post will works on two sides and here my post is works on all sides..
PS:Shadow color need to be choose’d based on the background color.
keith,
If you have any demo site or similar where it doesn’t work, please share it here.
Thanks so much for this! Works perfectly with my unordered lists !! Koodos!
Leslie,
Great!
Exactly what I was looking for. Thanks it helps me for one of my project as a programmer it speeds my development.
[…] more about it over here at Robert Talks Tagged with: -moz-box-shadow • -webkit-box-shadow • box-shadow • […]
Goddamn you Internet Explorer.
[…] Source: http://robertnyman.com/2010/03/16/drop-shadow-with-css-for-all-web-browsers/ […]
Anyone have any bad reaction with this code and Flash.
After implementing this my Flash logo animation slowed considerably and is choppy on page load.
Any ideas?
Thanks!!
Oh and this is only an issue in IE. Here’s my test host where I am trying to work out the issue:
TEST SERVER
Sorry to spam…..there seem to be glitches across most of the different browsers. Chrome seems to be displaying it the best.
Generally the issue is a slower animation and wobbly motion created by the shadow effect code in place.
Anyone have any suggestions to fix it?
Thanks!
Eric,
Sorry, I have no idea when it comes to web browser implementations and using this in conjunction with Flash. Please register bugs with the web browser vendors.
Ya it’s reacting badly with several things. Obviously the Flash I mentioned, but also with my Spry menu animations, and even some fonts within the areas I am trying to shadow.
It seems to want to put the shadow on my fonts as well.
I found the text-shadow style but when I make that one 0 it makes all my shadows disappear. Guess I still have to hunt for a more suitable shadow technique. This one’s bugged.
At last!! Easy and simple… thanks!
I want it in FF 3.0, and how?
When I noticed this article about cross browser drop shadows I immediately started to implement it in my website. So far I was already using the old fashioned way yha only shows drop shadows in IE only.
When updating my script with the snippets above I faced a problem which I would like to have solved. On my website I created rounded boxes using the nifty corner script (www.html.it/articoli/nifty/index.html). I would like to add the drop shadow to those boxes, but it only seems to work with rectangular boxes. Do you have a solution?
Thanks for your support
OMFG!! I just wanted to learn how to make a drop shadow. WHy the hell does IE have to me sooo complicated.
frank,
I’m sorry, there’s no easy way to do that.
Frans,
If you have web browser support for CSS drop shadows, you definitely have it for CSS border-radius as well (for rounded corners). So, for those web browsers, just don’t use the script and rely on CSS instead.
Thanks man! Cheers!
This was a HUGE help and sooooooooo simple to do! LOVE IT! The only thing I haven’t been able to figure out is how to get the drop shadow to go to the other side (left & bottom) when I have a left aligned image. Have tried playing with the rules (px & direction settings) and can’t get it to work. Anyone know how? Thanks!
it is very useful. i need shadows on 4 edges. Mozilla i made it on four sides.
IE 6 what would be the direction if i need 4 sides??????
pls help me
Thanks, excellent post.
I noticed that in IE the element to which the shadow is applied, needs to have a background color set. Otherwise the shadow is inherited by child elements (including text).
nice. thanks!
This is a great script thank you. I couldn’t get it working originally in IE but setting a height eventually got it showing. Thanks 🙂
You saved my time. Thanks for sharing.
Looks simple enough. Thanks for posting.
-Dan
you have made my life so much more easier.
Thanks!
This works perfectly, thanks. I had never seen the non-IE drop shadows before.
[…] Robert Nyman’s article on cross-browser implementation of box-shadow. […]
Hi, I had this strange thing happening…
FOR THE FIRST TIME I LIKE IE MORE THAN THE OTHERS!
Does anybody have a solution for the next problem:
A decoration of a repeated TRANSPARENT png shows better in IE than any other browser:
http://www.izipages.com/test/page.php?type=1
For IE I use the filter and for others the box.shadow
Thanks in advance.
Lovely solution for making shadow, but the only thing that annoys me whit this is that in IE there will be a security question about allowing it.
Unalom?z?,
No, there shouldn’t be a security warning in IE. Do you get that in this CSS drop-shadow demo page?
Hi,
Great article, helped me a lot!
I am wondering about the IE filters. To me it seems that IE8 is ignoring the one marked IE8 in the example and also uses the one marked IE 5.5-7.
Anybody sees the same behavior?
Thanks, Robert
Robert,
Glad it helped!
If you experience that problem, try switching the styles around, i.e. have the one for IE8 last.
Thanks! This is wonderful! I had wanted to get shadows on both sides of my main content div in firefox, but am unsure how exactly to go about doing this…any suggestions?
thanks again!
Thank you! Now only if I can animate alpha levels in ie8…
Thanks! That’s been very helpful. Too bad it doesn’t work in IE.
Thank you Robert for the excellent info. And thank you Ronald K (comment #105) for that essential tip to set the background color. This technique saves time in a web design project, and allows us to add features that we just wouldn’t do before.
Thanks for the code.
It works with all browsers on this site (Firefox, IE8, IE7).
But on my own site, it works only with Firefox and IE8. No shadow with IE7 and below. Strange.
[…] The drop-shadow code listed in that post wasn’t dramatic enough for me, so I found this solution on drop shadows for all web browsers. The only thing you have to do is make the first number in each row -3px so that the shadow appears […]
Just a note on the IE Shadow plugin: when the X and Y offset on box-shadow are both zero, then the shadow acts as a glow in all directions. You then need to switch to the Microsoft “Glow” filter instead, since the Shadow filter makes the direction (and angle) mandatory.
Erik,
The shadow is set generally for the element with an offset and shadow length, so you need to work with that and try what works how you want it.
Michael,
Animating the levels, i.e. setting the filter value dynamically, should be a good approach to animate the alpha level.
Em,
It works well in IE – please try the code mentioned above in the post.
David,
You’re welcome!
Mobiiliveeb,
Please try and compare the code and see if you can spot the differences.
Jason,
Interesting, thanks for the tip!
I am not a programmer but I am as a graphic artist doing a lot of websites, I have been teaching myself more and more. I want to express my gratitude for people like you. This little, simple, CSS class, that actually works, was a lifesaver. Dreamweaver’s version sucks and never works right. Your version is spot on. !!! Thank you and many praises.
Bo,
Glad to hear it made things easier for you!
Thank you so much! I LOVE CSS, and when people like you share tips and tricks like this. Works perfect. Thank you!
Anything Graphic,
You’re welcome. 🙂
if shadows do not show up in IE 7 a good way to ensure the hasLayout gets set is to simply add
zoom: 1;
as another parameter set in the CSS class.
Hi: I am adding a jquery slideshow inside the shadow div in another div. I get a wierd offset in IE8 as soon as the active x warning is clicked. The image appears about 10px up and 10px to the left. Works great in all other browsers (big surprise right!) Do you have any ideas what might cause this? Thanks.
Julian,
Absolutely, that can be needed.
Dana,
Not sure why you would get an ActiveX warning? But no, I don’t have any idea about that.
[…] Color=’#000000′); } This drop shadow effect with CSS for all web browsers! Online Demo: http://robertnyman.com/2010/03/16/drop-shadow-with-css-for-all-web-browsers/ Bookmark on Delicious Digg this post Recommend on Facebook Tweet about it Tell a friend Tags: […]
Hi,
Is there any way to get this working with curvy corners in IE8? I have it working in every other browser with curvey corners, even IE7, but when i test it in IE8 the div that I apply the style to disappears.
Apart from this issue It is a nice way to create the effect.
As you can imagine, the fact that it doesn’t work in the one version of one browser is extremely frustrating for me. I believe that it is todo with the rendering of the corners in IE8 though.
Nick,
Not sure what you mean with curvy corners. In CSS, border-radius for rounded corners isn’t supported until IE9.
Are you maybe talking about an image-based solution?
[…] […]
[…] older versions of Internet Explorer, then you’ll need to add in the IE-only Shadow filter. Read here to find out […]
[…] older versions of Internet Explorer, then you’ll need to add in the IE-only Shadow filter. Read here to find out […]
[…] older versions of Internet Explorer, then you’ll need to add in the IE-only Shadow filter. Read here to find out […]
[…] […]
[…] older versions of Internet Explorer, then you’ll need to add in the IE-only Shadow filter. Read here to find out […]
[…] older versions of Internet Explorer, then you’ll need to add in the IE-only Shadow filter. Read here39 to find out […]
[…] older versions of Internet Explorer, then you’ll need to add in the IE-only Shadow filter. Read here to find out […]
Thanks for the tips! Really worked out here. Helped me fix some drop shadow stuff I was convinced I had setup right, but I had the wrong formatting. Great article.
Leif,
Thanks, glad it helped!
hi there.. thanx for sharing this.. i have applied the same but its showing the shadow only on the left side. and i want it to show on all the sides. plz advice.. aslo it shows shadow on text aswell.. i have put the css on the MAIN div.. but some how its showing on everything..
plz advice.. thanx
aman,
Impossible to tell. Do you have a URL to an example?
[…] older versions of Internet Explorer, then you’ll need to add in the IE-only Shadow filter. Read here to find out […]
Thank you for this article. Finally writing code is starting to be fun again. Any time you can reduce a graphic and still get the same result is AWESOME
Thequestor,
Thanks, glad you liked it!
[…] older versions of Internet Explorer, then you’ll need to add in the IE-only Shadow filter. Read here to find out […]
CSS Sahdow For IE with tutorial here
There is one problem. IE tries to add shadow to every element inside that div. So text etc. will have shadows too (unless we specify not to). Headache 🙁
baco,
Yep, IE is not fun to develop for.
Any thoughts on how to apply this to text?
Cool . . . sorted it :o)
Rasika,
For more modern web browsers, you have text-shadow in CSS. For IE, you need to do some filter trickery.
Fantastic tutorial. Many thanks!! Have just used it in a new website I’ve created and it’s worked a dream first time. far better than the multiple div’s I’ve seen elsewhere.
[…] Drop shadow with CSS for all web browsers – Robert's talk Who doesn't love a drop shadow? Especially when done with CSS3? Make it work in all browsers. No extra image required. (tags: dropshadow css3 css webdesign howto) […]
Hi all brainy tech guy.
I was wondering if someone have a solution for the IE bug where all content is being pushed due to the shadow effect?
I have a centered div which I apply the shadow filter to for example 20px on all sides. Then the content of this div moves 20 px to the left. Please help guys.
Can’t wait for IE9 and the others to die!!! 😉
[…] for 2011-03-05Chad Udell Posted on March 7, 2011 Category: DiscoverDrop shadow with CSS for all web browsers – Robert's talkWho doesn't love a drop shadow? Especially when done with CSS3? Make it work in all browsers. […]
John,
Thanks, glad you like it!
Martin,
I’m sorry, I don’t why that happens.
Cool! CSS shadow works for all browsers is great! Save time creating shadow images which is a pain as always. Thanks!
Hi: Having trouble with an offset of the main div content in IE only. No surprise there. I am also having trouble with IE only showing drop shadows on two sides. Any ideas? Thanks.
Toan,
You’re welcome!
Dana,
Sorry, don’t know why.
[…] you would like to read more about using IE shadows to try to make it work, try these articles: Drop Shadow on all Browsers and RGBA Generator of […]
thanx it helped me a lot, but still i have got one problem with it, i used curvycorners within my div but the shadow effect does not follow the curves. what can i do with it.
tmann,
I’m sorry, I can’t help you with that.
Hi,
thanks for the tipp, but filters seem still to be very buggy or/and not that helpful for each IE.
The turned off clear-type is just one example.
i also encountered the problem that some a:hovers didn´t work properly anymore.
For example a hover in a ul-list (“a” was set to “display:block”) this was working, but changing the color on hover had some strange effects in IE9. First its working for 1/100 second or whatever, but then its not working anymore.
Without filters everything is ok.
Now, I decided that people, who are using IE have to live without any shadows.
Marc,
Definitely, it’s all up to each context and use case to try it out and see if it is worth it.
I managed to get the shadow on all four sides. The only problem is I have a flash embed in the main div tag. The flash shows up to the left and up about 15pixels. If you use a static image it shows up perfectly. Any help would be appreciated. Thanks.
Dana,
I’m sorry, I don’t know which problem the Flash movie can create, in conjunction with the shadow.
[…] Color=’#000000′); } This drop shadow effect with CSS for all web browsers! Online Demo: http://robertnyman.com/2010/03/16/drop-shadow-with-css-for-all-web-browsers/ Bookmark on Delicious Recommend on Facebook Tweet about it Tell a […]
BUG
In the general case be sure to place the IE8 code AFTER the IE7 code otherwise I doesn’t work. I experienced it
Bjorn,
Interesting. I haven’t experienced that, but if that works for you, great! Thanks for sharing.
ya, it’s working……..
Thanks, I am suffering w/IE 8 (corporate mandated) browser and this helps me to add some pizzaz to Sharepoint pages!
Glad it makes things better for you!
Talk about valuable info. I always have a challenge making style cross browser compatible. i need this kind of info to get better at it. Thank you!
nice shadow..
its not workn as it brng a txt shdw also
Obviously this is BROKEN in ie7 for sure.
http://samples.msdn.microsoft.com/workshop/samples/author/filter/Shadow.htm
browse that in ie7, it’s blank!
anyone?
Art,
I don’t have IE7 available right now, and their demo might be broken. However, the code above here will work.
[…] Note: This CSS class is based on a cross-browser drop shadow effect described in Drop shadow with CSS for all web browsers. […]
Hi. My issue is that most of my nested items are getting a shadow in IE7 as well. For some reason, some text in <p> tags has shadows, while some do not. And the divs inside the div I want to have a shadow all have shadows too. How do I fix it so that only the div I am applying a shadow to has a shadow?
Maru,
It’s a bit tricky. You need to work with several elements overlaying each other or maybe just avoid shadows for IE7 users then.
I was wondering if there was a way to apply a “glow” to an element that would appear on all four sides instead of just a 2-sided shadow. Thanks !
Ehab,
By not setting any background offset (i.e. using 0 instead) you will indeed create a glowing effect.
I’ve been using this for a while for my drop shadows – so much nicer than having to rely on images and pretty simple to use. However I’ve not stumbled across an odd one in IE (7, 8 & 9). I’ve got a div with the drop shadow on it, and I have some divs inside – for some reason if I use the gradient filter on these internal divs I get the drop shadow applied as well. Have you experienced this? Is there some way to use the gradient filter, but NOT have the shadow filter inherited?
Kaz,
Hmmm. Sorry, not sure how to do that, unless you explicitly override it in the inner divs.
[…] Solution found here: http://robertnyman.com/2010/03/16/drop-shadow-with-css-for-all-web-browsers/ […]
Hello,
I’m always in troubles when trying to implement the shadow effect to my website, but your tutorial did the trick. The result can be seen at my website.
Thank you for sharring.
Regards,
Michael (Who’s building an online business)
Thanx for code..
how do i get the drop shadow where there is no offset in IE v. 5-8??
Kevin,
It could possible be solved by applying hasLayout or similar (if I understand your question correctly).
do anyone know how to add the drop shadow but have no angle on it just like a soft drop shadow around a whole image?
Kevin,
Set the first two parameters to 0 to not have any side-specific offset.
thankyou so much… the drop shadow combination for all browsers has worked really well on http://www.seemeagain.com – thankyou for this post 🙂
Teddy,
Glad to hear it was useful for you!
[…] are nearly over! Once IE catches up in the race it will be a new design world altogether. Thanks to http://robertnyman.com/2010/03/16/drop-shadow-with-css-for-all-web-browsers/ for the code hookup! x_x .drop_shadow { -moz-box-shadow: 3px 3px 4px #666; -webkit-box-shadow: […]
Great website, now is my favorite 🙂
Thank you for the simple and clear description.
Greetings!
I want the shadow effect for IE browser four sides but the sample code i used from this website but it shows for only L sized shape. please help me for four sides.
Thanks,
Vikram
vikram,
As far as I know, I don’t think that is possible.
Hey Robert,
Well indeed its really a nice work that you have done.
To answer vikram, i think its possible but shadow on four sides is not working in IE.
If you increase the shadow radius then it will display on four sides. Example:
moz-box-shadow: 1px 1px 10px #000;
-webkit-box-shadow: 1px 1px 10px #000;
box-shadow: 1px 1px 10 #000;
This CSS works in Mozilla, Google Chrome but does not work for IE.
Any suggestion will be appreciated.
Thanks
[…] (example grabbed from http://robertnyman.com/2010/03/16/drop-shadow-with-css-for-all-web-browsers/) […]
Faisal,
Right, you can also have 0 as the first value to make it work. However, the question was specifically for IE, and for that I don’t know of a solution.
Thanks for a great cross-browser solution!
Is there a reason that -ms-filter is followed by quoted material, but filter by unquoted material? Or just an oversight, or doesn’t matter?
-ms-filter: "progid:DXImageTransform.Microsoft.Shadow(Strength=4, Direction=135, Color='#000000')";
filter: progid:DXImageTransform.Microsoft.Shadow(Strength=4, Direction=135, Color='#000000');
Jean,
Thanks!
The quotes are indeed supposed to be there.
I have div ID:Father inside of which div ID:Son, iside of which an image.
I put this code in the ID tag of the div ID:Son. In IE it works fine: The shadow is applied to the image inside of div ID:Son, but In FF6 the shadow is applied to the div ID:Father. The whole father div gets a shadow. How can i fix this please?
adumi,
Can you share an example online somewhere so we can see it in action?
[…] http://robertnyman.com/2010/03/16/drop-shadow-with-css-for-all-web-browsers/ .shadow { -moz-box-shadow: 3px 3px 4px #000; -webkit-box-shadow: 3px 3px 4px #000; box-shadow: 3px 3px 4px #000; /* For IE 8 */ -ms-filter: “progid:DXImageTransform.Microsoft.Shadow(Strength=4, Direction=135, Color=’#000000′)”; /* For IE 5.5 – 7 */ filter: progid:DXImageTransform.Microsoft.Shadow(Strength=4, Direction=135, Color=’#000000′); } […]
Hi Robert-
I just got access to IE 7 & 8 browsers, and actually it doesn’t work with quotes, the quotes need to be removed for both. So:
-ms-filter: progid:DXImageTransform.Microsoft.Shadow(Strength=4, Direction=135, Color='#000000');
filter: progid:DXImageTransform.Microsoft.Shadow(Strength=4, Direction=135, Color='#000000');
Jean,
From my testing, the quotes work and should be there for IE8: http://msdn.microsoft.com/en-us/library/ms533754%28v=vs.85%29.aspx
The ie 6 does’t change the properties. Why?
[…] http://robertnyman.com/2010/03/16/drop-shadow-with-css-for-all-web-browsers/ […]
gud Tutorial Really helpfull
Great but is this filter is important, i mean is there anything else like simple coding.
[…] http://robertnyman.com/2010/03/16/drop-shadow-with-css-for-all-web-browsers/ […]
[…] Cross-Browser CSS Drop Shadow – An easy-to-implement method of getting css drop-shadows to work in all browsers in most situations. […]
Thanks Robert – this works in FF so far. I will try it on IE tomorrow…. IE is the STRESS! 🙂
It definitely works. I checked with IE 5.5 – 9. Thanks a lot:)
Julian,
Good to hear!
Thaaaaaaanks a lot my bro. Its works for me on all major browsers.
How to achieve the shadow you have on the main document of this website, which nicely separates the background color #333333? The way you explained above? Thanks!
AJ,
The CSS for that is:
box-shadow: 0pt 0pt 10px rgb(0, 0, 0);
Thank you very much, exactly what I’m looking for right now.
I’m a desktop software developer for a long time.
Recently, stared playing web design and development .
Still wondering why MS products most of the time needs exceptional handling.
Every time I do test my pages on major browsers, they gave almost the same results, but IE needs special handling !
Thanks again Robert 🙂
Asssem,
Thanks, glad you like it!
Tested this in IE8. For me, it DID present a Security Warning bar and I had to “Allow…” IE8 to display the shadows. I clicked Allow, they looked fine. Now that I have allowed it once, IE8 appears to not ask me anymore, even on your sample page. For my project, I decided no shadows in IE8 is fine, I’d rather not alert my visitors with a possible Security Warning.
IE8 Tester,
That’s not the default behavior in IE, though. It depends on your security settings.
I have used your dropshadow solution with succes I think, but when I validate the css, I get 8 errors. Is there a way to validate it without errors?
Here is a link where I used it:
http://www.tijdschriftvoorseksuologie.nl/nieuw/inloggen.html
Iris,
You will get errors, since Microsoft filters and web vendor prefixes aren’t regarded as valid code. It still works, though, so the validation errors aren’t anything to worry about.
[…] Drop shadow with CSS for all web browsers […]
I used this code for my website, but when i combine it with curvy corners script for IE the corners disappear and only the shadow remains.
what to do about this?
Mister,
Sorry, can’t help you there. Not sure what that script does.
Thank-youuuuuu!
Hi, i have one problem in IE 8 & 9: by css settings for table “collapse” is shadow not visible. when i set to “separate” -> the shadow is visible.
Joe,
You’re welcome!
Eugen,
That might very well be a problem in IE. Try setting the shadow on the containing element or similar instead then.
The filter shadow in IE is just so @#$! ugly!
You may want to take a look at this:
http://whattheheadsaid.com/2011/05/creating-a-nice-text-shadow-in-internet-explorer
which he uses
Blur
to create shadow, and it’s much better.BTW, I like your picture of Hong Kong! (especially that ????)
Derek,
It is ugly indeed. Luckily. box-shadow is supported in IE9 and up.
But yes, blur can be an option too for older versions of IE.
And glad you like the Hong Kong header!
Great post. I wonder if there is a way to put shadow in a rectangular shape. Say in the bottom of an image, in the middle part, the shadow is in its longest size, but as it goes to the edges, it becomes shorter and shorter. On the corners, there are no shadows? Any idea?
Are you talking about an effect similar to the one in my code playground?
[…] Nyman explains why you need all those declarations here on his website, Robert’s […]
thank you so much …this is working perfectly
RAtnakar,
Good to hear!
Very very helpful and time saver – thanks
Simple dimple,
You’re welcome!
Very helpful! Thanks!
Nate,
Good to hear!
Thanks for the code!!! Saved me a lot of research!!!
Kristina,
You’re welcome!
Hi,
Using the above styles i have achieved the drop shadow but i want the drop shadow in IE browser “Left shadow & bottom shadow”.
Please let me know if any one done this.
santhosh,
Sorry, no idea. However, box-shadow has been available in Internet Explorer since version 9.
[…] One of the most common CSS effects is using shadows in various ways. Before, we needed to resort to images, but now we can offer this to all major web browser with CSS! Web browser support This article is also available in Bulgarian Believe me or not, but all of these web browsers we can offer shadows with CSS: Drop shadow with CSS for all web browsers – Robert's talk […]
[…] Robert's Talk – Drop Shadow With CSS For All Web Browsers Filed under: CSS, HTML, Programming Leave a comment Comments (0) Trackbacks (0) ( subscribe to comments on this post ) […]
It works! Its amazing how just adding a subtle shadow around a few elements can make the site look so much more professional, while also drawing attention to important elements on the page. Well done. Thanks!
Aaron,
Glad to hear it was useful!
[…] was nothing spectacular. Shadows seemed not to be a problem either. A quick search brought us to this post by robertnyman that had just the stuff we […]
Great Post!
It work in IE 8… Thanks.
ShweRoom,
Good that it works for you.
If an end user is still using IE in 2012, they deserve to have an ugly web experience.
Stop dumbing down your code for them and force them into the modern era.
mrme,
Internet Explorer is going to be around for a long long time, and it does keep on improving just as all web browsers. This is an interim solution till it gets there.
It would be nice to copy that conglomeration as plaintext, but the line numbers and little green returns mean I’ll have to edit it anyway.
Jim,
If you hover the code area, there will be a icon on the right for code. Click it and you will get plaintext.
Thanks for the great tut and explanation. This is exactly what I was trying to achieve. Need to play with it a little to get the shadow on the left, rather than right, but thank you!
Michael,
Good to hear that it was helpful!
Ty brother
Nithin,
You’re welcome!
[…] http://robertnyman.com/2010/03/16/drop-shadow-with-css-for-all-web-browsers/ […]
I’ve created a tutorial and sample page on my website with examples of some pretty slick uses of the css box shadow property. Check out the tut and live demo here: http://studentwebhosting.com/tutorials/amazing-css3-box-shadow-examples/
Andrew,
Cool, thanks for the tip!
Hello, I have a question, where exactly should i put this shadow code into my style.css to get shadow around whole my page?
I try to do it for 2 days ;/.
I have this code, I know I have to put it in style.css but I don’t know where which line.
I would be very thankful!
OMFG… IE MUST F**** DIE.
Performance of filters sucks (so does the IE JS engine btw) and background-colors need to be set for this to work ‘correctly’.
I’ve decided to only support IE8+, and for certain design problems, I’ve stopped supporting IE as a whole. No regrets 😛
Thanks though, for again finding out (from a.o. this site) that IE sucks as bad as it does.
My two pennies for all devvers out there: STOP supporting IE. End of discussion.
Users of IE: Get a real browser!
Charlie,
You need to apply this CSS to the most outer element on your page if you want that effect.
roger,
Well, IF you do want to support IE, this is a way to make this work in older versions of it.
Wow 2.5 years old but still so relevant. Thanks! Unfortunately not working for me at all. I DID try making sure IE8 filter is after IE7- filter in my stylesheet. But neither are working at all :.[
Wondering if it’s my testing env being Win7?
Otherwise, I have other filters running in the same rule. Is that a problem?
Here it is:
-webkit-box-shadow: 1px 1px 10px rgba(0,0,0,0.85);
-moz-box-shadow: 1px 1px 10px rgba(0,0,0,0.85);
box-shadow: 1px 1px 10px rgba(0,0,0,0.85);
/* For IE 5.5 - 7 */
filter: progid:DXImageTransform.Microsoft.Shadow(Strength=4, Direction=135, Color='#000000');
/* For IE 8 */
-ms-filter: "progid:DXImageTransform.Microsoft.Shadow(Strength=4, Direction=135, Color='#000000')";
background-color:#fff;
/* for background gradient */
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#d6e1a3', endColorstr='#ffffff');
background: -webkit-gradient(linear, left top, left bottom, from(#d6e1a3), to(#fff));
background: -moz-linear-gradient(top, #d6e1a3, #fff);
Julian,
I believe that the last filter declaration kills the first one. For several filters, I think you need to separate them by commas or similar in just one property: Creating Multimedia Effects with Visual Filters and Transitions
Really Nice post. Thanks for share.
[…] Drop shadow with CSS for all web browsers […]
dear friends I want to place shadow to an png image. could it be? please help.
Yes, you should be able to do that.
hello – at the same page with image with shadow there are and social icon
can it be to remove the shadow from social icons?
my css
.sharing{background:url(https://lh4.googleusercontent.com/-at7TzPplw04/ToxNxytIWZI/AAAAAAAABeY/shhuelzMynk/sharing_network.png);display:block;height:81px;margin:40px auto 0 auto;position:relative;width:102px}
.sharing ul.share_left{height:30px;margin:0 auto;position:absolute;right:95px;top:30%;width:250px;z-index:80}
.sharing ul.share_right{height:30px;left:98px;margin:0 auto;position:absolute;top:30%;width:250px;z-index:80}
.sharing ul li{display:block;float:right;font-size:13px;height:30px;line-height:30px;margin:0 5px;width:40px}
.sharing ul li a span{display:block;left:0;position:absolute;text-align:center;top:31px;width:250px}
.post img{-moz-box-shadow: 2px 2px 3px #000;
-webkit-box-shadow: 2px 2px 3px #000;
box-shadow: 2px 2px 3px #000;
/* For IE 8 */
-ms-filter: “progid:DXImageTransform.Microsoft.Shadow(Strength=4, Direction=135, Color=’#000000′)”;
/* For IE 5.5 – 7 */
filter: progid:DXImageTransform.Microsoft.Shadow(Strength=4, Direction=135, Color=’#000000′);max-width:609px;}
from .sharing must be remove the shadow
Panos,
Not sure I understand what you mean. If there are shadows in the actual images/icons, you can’t remove them. If the shadow is set through CSS setting box-shadow to none or similar should work.
iam try to make css like this
.sharing image shadows {display:none; !important}
Panos‚
Ok…
Well, you need to put together your CSS so you know which images have shadow applied. There’s no way to automatically detect it.
[…] Box Shadow for IE7 and IE8 How to Simulate CSS3 box-shadow in IE6-8 Without JavaScript and Drop shadow with CSS for all web browsers. […]
Hi Robert, I hate to tell you this, but your page on CSS drop shadow techniques has been hacked by a prescription medication SEO spammer. I hope you can get rid of the hack because I’ve been referring to this page for awhile now and have found it very useful.
Kevin,
Which page would that be?
yeah. It work. Very simply ^^
[…] Drop Shadow With CSS For All Web Browsers google_ad_client = "ca-pub-4085781408395472"; /* 728×90 */ google_ad_slot = "8630977240"; google_ad_width = 728; google_ad_height = 90; .daumview_flash_widget{ text-align: center; } .tt_plugin_daumView { display: none; } @media (max-width: 800px) { .tt_plugin_daumView { display: block; margin: 13px auto 6px; width: 56px; height: 55px; } .daumview_flash_widget{ display: none; } } Thanks for rating this! Now tell the world how you feel via Twitter. (Nah, it's cool; just take me back.) MOODTHINGY ?? ?????? (??? ??? ??? ???!) […]
Really Nice Drop Shadow CSS Here!
Thanks alot for this article, I will be putting it on my website for a new look 😀
Regards
Alphabet Signs!
Wow, excellent trick for the horrible ie browsers…
Sweet. Easy to add and it looks great. Thanks for sharing.
You can also use this guys it will be more easier with this :-
if you want to add it to a created element, then use this, its an example:-
#divContent {
box-shadow:1px 1px 4px #000;
-moz-box-shadow:1px 1px 4px #000;
-webkit-box-shadow:1px 1px 4px #000;
}
If creating a class then:-
.divShadow {
box-shadow:1px 1px 4px #000;
-moz-box-shadow:1px 1px 4px #000;
-webkit-box-shadow:1px 1px 4px #000;
}
Hope this helps you
David,
Sure, but the point was to make it work in older versions of IE as well. Hence all the information and code in the blog post.
thanks robert. but if i want to give shadow on all sides then ?????/
nasir,
You control that with the length of the shadow. See more at MDN’s box-shadow page.
Love this! Thank you!
inline css for html on IE8 ?
all the css3 stuff are awesome. Some of the html5 resources are helpful like geolocation.
Thanks for the article
Simple explanation, for that we begin is of great help to be able a more agreeable aspect to our web.
Regards and thanks
Great and easy article, thanks so much Robert!
I’m just getting problems with Explorer. I think it’s because of “direction” (which you settled 135). In case we don’t want direction to it, so that it’s just centered, what can I do? I’m using “0” but it just shows up.
pau,
Thanks! And not sure. I’d try a low value, but in essence, it comes down to experimentation.
Thank you so much brother .. i was looking for this 2 codes -moz-box-shadow | webkit-box-shadow
Drop shadows are always sooo impossible in IE. Thanks so much for sharing.
Perfect! A brief/succinct CSS drop shadow explanation (for images) to what I was trying to figure out. Thank you Robert
~Robert
[…] ???????? […]
Hi Robert. 🙂 Unfortunately it does not work for me in IE 8 and lower. I also tried to display your page in Internet Explorer 8 to check if your example “I can haz shadow” is displayed correctly but it isn’t… where can be a problem?
Jindrich,
Sorry, no idea why that could be. It’s been quite a long time since I used it myself.
its nt working in ie 7
Try best css box shadow codes easy guide http://www.vickyhertz.com/use-box-shadow-css.html
Great, it worked.
CSS Shadow with image
http://www.corelangs.com/css/box/image-shadow.html
css tutorial
[…] older versions of Internet Explorer, then you’ll need to add in the IE-only Shadow filter. Read here to find out […]
[…] older versions of Internet Explorer, then you’ll need to add in the IE-only Shadow filter. Read here to find out […]
Fantastic. I was looking for a system that is as compatible as possible . Thanks so much
You are providing solutions for box-shadow & it’s quite different than drop-shadow…..