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.


Nice one. It is a really useful.
Wow the CSS Gradient Dropdown Menu example is amazing. Too bad it’s hosed in IE 7- but absolutely amazing that you can achieve that w/out the use of images.
Great work!
Thank’s a lot for all tutorials and tips
Awesome post, just a small bug I’ve discovered on IE 8 – Gradients with a border cut out the bottom border for some reason.. If anyone know’s a fix that would be great :)
It still amazes me that we’ve come all this way with CSS3 and we still can’t standardize on presentational code.
An issue here is that when you put the gradient into a div, and do a border-radius onto it for IE (whether using IE9 beta standard support or a JS solution like curvy corner) the gradient is not stopped by the rounded edge so you end up with a the gradient display over the rounded border. Is there anyway around this??
Wonderful menu!
Thanx its awesome script. Gradient in IE was the major problem but using this sceript that problem is solved thanx a ton.. :)
Thank you so much for the great tutorial!
The style is working in ie7 perfectly but not in ie6.Do i need to have some other setting.
Chikezie you complete and utter moron. You really should do a little reading before exposing your stupidity so openly.
I was reading something else about this on another blog. Interesting. Your position on it is diametrically contradicted to what I read earlier. I am still contemplating over the opposite points of view, but I’m tipped heavily toward yours. And no matter, that’s what is so great about modernized democracy and the marketplace of thoughts on-line.
lovely site, very informative
Very useful & nice. Love!
ovely site, very informative, Thank you so much for the great tutorial!
very nice ..like it..good work.
Thank you for the useful information, however, you didn’t include how to differentiate between a horizontal or vertical gradient in IE: filter: progid:DXImageTransform.Microsoft.gradient(GradientType=1, startColorstr=’#cccccc’, endColorstr=’#000000′); for horizontal, and replace the 1 with a 0 for vertical. Here’s my source: http://technet.microsoft.com/en-us/library/ee692647.aspx
Thank you!
To all those who can’t figure it out – it doesn’t work in Opera. O. does not support css gradient yet. This article is a bit flawed, for not mentioning this at all.
You CAN get a nice gradient without a bitmap though, using SVG (w/h 100%/100% and a gradient of your choice) as a background-image. ;) If you use the same start/stop colors, it’ll look exactly the same as in webkit/Firefox using css3.
Awesome tutorial, thanks for this bro.
Your post is very nice and insightful. Have just started implementing this feature.