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.


Waouh, very nice, thank you au lot !
Nice, thanks. Always like the use of a good gradient from time to time. Was taught in university not to use gradients in design for some reason but I like them and think they can work well when implemented correctly and appropriately.
ho trovato dei buoni sconti su http://www.tecmania.it/ voi ne conoscete altri ?
grazie
The above code is very good for all website developer but, I just want to know can we use this code in horizontal way?
If it is possible to make it. thata will be great code forsoever for all website developer.
Thanks,
Ganesh
filter: progid:DXImageTransform.Microsoft.gradient in script bellow not work in IE 7:
table = document.createElement(‘table’);
table.setAttribute(‘cellspacing’,’0′);
table.setAttribute(‘cellpadding’,’2′);
tbody = document.createElement(“tbody”);
table.appendChild(tbody);
tr = document.createElement(‘tr’);
tr.setAttribute(‘valign’,'top’);
tr.style.cssText= “filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=” #B554FF”, endColorstr=” #B554BB”)”;
tbody.appendChild(tr);
Could you help to solve the issue above?
Many thanks,
Pao,
Not working in opera 10.53 there is only a gray color…
gr8 comment.. thanx alot
the ie 7.0.6 doesn’t work with the crazy grediant which applied to the “tr”
Anybody know how solve it?
Thanks for sample code For Webkit Browsers.
gr8 post
thanks for sharing
anyway whole web design is going to dynamic now will be more fun to worl with CSS 3 & HTML 5
Thanks for sharing going to use on my site on the next update here Thanks again!
Your menu example is great. Thx!
Thank you so much my friend. I rarely find blog posts as useful as this one. Anyone that wants to see this code In action on can check it out here: http://artists.me/members/profile/admin . It’s a gradient from #FFFFFF to #E8E8E8.
Again, thanks for the awesome post.
Wonderful menu!
you forgot one thing… IE 8 changed the property to -ms-filter and the filter command is in quotes.
SVG in combination with background-size is missing. If done correctly, it should work in Opera.
thanks for the tutorial. but chrome (chromium) 6+ (that only i test) have small bug in inset.
Interesting tutorial. Keep up the good work
not working in ie6…
Why did you even bother to check IE6? Anyone who still uses IE6 (and is not being forced to) is, quite frankly, a moron.