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.


When you do article marketing, your intention is to increase the number of visitors to your website. It is not our abilities that show what we truly are, it is our choices. I have look for such a article for a long time
Tnx for this incredible post! You saved me a lot of hours!! (y)
Thanks for this, awesome css script.
Thanks for the demo. Maybe someday Exploder will render css correctly.
I wonder how many thousands of hours have been wasted trying to get web sites to look right on this horrible, horrible browser . .
Coool.
Want to change your belove iphone 4 form black to white? Hmm, yes, so am I. but when will white iphone 4 available?
I just heard the gossip that since there’s some technic problems on white iphone 4, iphone 4b is going to release. It that true?
Thanks a lot, this helped me greatly!
Does not work in IE 7–in fact in your example, the popout menus in the drop down do not display.
your gradient code doesn’t work on on IE 8.
Thanks for the great article thought.
I had a beautiful gif background gradient on a very simple login page. Worked well with everything but Firefox. It was all striated! Yuk!
Now it’s terrific in FF, IE, and Safari. Plain background in Opera and Google, but they don’t really matter for now.
This code worked from the get-go. Fabulous. Thanks heaps!
Max Williams (aka maxzebra)
Thank u very much, i am upset for last 1 week thanks thanks……… this helped me greatly!
This is something what I was finding from so many days and finaly got it here. It has been a great help of your that you have shared a great and helpful post here.
Los Angeles Web Design
use endColorstr=’white’ instead of endColorstr=’fff’.
For some reason it likes to make white black.
Following code for Firefox.
background:url(“../logo.png”) no-repeat scroll 0 10px,-moz-linear-gradient(center top , #212327, #424448);
I want to use background image and gradient both in IE.
What is IE compatibiliity code for this?
Is this compatible to safari?
excellent! Had no idea you could gradient with just CSS in ie7/8!
hasret kanımda
How to make these things valid for validation of css3 ?
Brilliant, as usual. Well explained, the gradients worked fro me the first time. I am super ADD too so this is a big task. :)