The CSS gradient feature was introduced by Webkit for about two years but was rarely used due to incompatibility with most browers. But now with the Firefox 3.6+, which supports gradient, we can style create gradient without having to create an image. This post will show you how to code for the CSS gradient to be supported by the major browsers: IE, Firefox 3.6+, Safari, and Chrome. Also, check out my updated dropdown menu (demo) using CSS gradient.
For Webkit Browsers
The following line of code is for webkit browsers such as Safari, Chrome, etc. It will display a linear gradient from top (#ccc) to bottom (#000).
background: -webkit-gradient(linear, left top, left bottom, from(#ccc), to(#000));

For Firefox 3.6+
background: -moz-linear-gradient(top, #ccc, #000);

For Internet Explorer
The following filter wlil only be read by IE:
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#cccccc', endColorstr='#000000');

Cross-Browser CSS Gradient (demo)
Put the three lines of code from above together and the result is a cross-browser gradient box. Note: I added a background rule at the very top in case the user is using a browser that doesn't support the feature.
background: #999; /* for non-css3 browsers */
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#cccccc', endColorstr='#000000'); /* for IE */
background: -webkit-gradient(linear, left top, left bottom, from(#ccc), to(#000)); /* for webkit browsers */
background: -moz-linear-gradient(top, #ccc, #000); /* for firefox 3.6+ */
CSS Gradient Dropdown Menu
Below is a pure CSS gradient dropdown menu using CSS3 text-shadow, radius-border, and box-shadow (no Javascript or image)
Internet Explorer Limitations
Internet Explorer gradient filter doesn't support color-stop, gradient angle, and radial gradient. That means you can only specify either horizontal or vertical linear gradient with 2 colors: StartColorStr and EndColorStr.
Final Remarks
Please note not all browsers support CSS gradient. To be safe, you shouldn't rely on CSS gradient when coding the layout. It should only be used for enhancing the layout.


This does not work in the current version of Firefox (3.5.10).
tnx :) very simple and very helpfull…
@Danny Internets: Really? 3.5.10 is the current version of Firefox? What about 3.6.6? BTW, Firefox 4 beta is out…
Nice article. Thanks for taking time to create this article.
Not really “cross-browser” if your proposed hack doesnt work in Opera. ;)
If you’re a professional web designer: stop hacking and wait till an implementation is released by W3C.
Works great in IE, Chrome, and Safari.
Does not work well in Firefox.
Excellent and informative. Thanks for taking the time, don’t worry about those who don’t appreciate the effort.
Hahahhahaah. IE 6.
tha’s simple and usefull… thanks…
Hahahhahaah. IE 6.
it uses the filter:?
anyway, really helpful.
i just searched for gradients with alpha support, but rgba and #00000000 in the filter did it.
I’m finding this works real sweet if you want to get earlier versions of IE working – http://css3pie.com/
Thanks, exactly this is I was looking for! One mention: the picture gradient is also cross browser and can be dithered which is a litle bit better.
Thanks so much for these tips. It’s incredible that IE doesn’t support so many things when it comes to CSS. I hope soon they realize the importance of this. Why do they refuse to cooperate with things that other browsers support?
Very nice, thanks for sharing.
Filter doesn’t seem to work in IE. What ever I change the hexadecimal value too it still renders blue.
When this filter is applied in IE, text smoothing is disabled (tested in IE8), which is not so nice for users with text smoothing enabled as it’s a very obvious difference in text rendering, the best option here may be to have a fallback background image for browsers other than Firefox, Chrome, and Safari. This would be done by specifying the background image as the background property as the fallback in the example above.
Cross browser? Does not work in latest Opera and Chrome on Win.
thanks, very usefull
very helpful. clear and to the point, with no obfuscation. thank you!
Is there a way to give a gradient to text (not a background gradient).