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.


Works nicely. Thank you for your listing.
Thanks so much for sharing! Enjoyed it, and used it.
Thanks for this. I got the gradient css for IE to show up, however, it does not validate under the W3C standards.
Please write a new post about gradients with the updated w3c syntax and non-prefixed gradients that work in IE10 ect.
I would really appreciate it.
work all browser very nice. thanks
Thank you so much brother.
Thank You for this, I managed to implement this for the header of my site this is basically what I put in:
.header-container {
background: #e0e0e0; /* for non-css3 browsers */
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=’#e0e0e0′, endColorstr=’#ffffff’); /* for IE */
background: -webkit-gradient(linear, left top, left bottom, from(#e0e0e0), to(#ffffff)); /* for webkit browsers */
background: -moz-linear-gradient(top, #e0e0e0, #ffffff); /* for firefox 3.6+ */
Seems to work very well take a look if you’re interested you can see the white at the bottom give it some depth.
http://www.careerorbits.com
Affordable Packages ..
Does anyone have a fix for the scrolling issue in Firefox? The code for IE works great, keeping the background static when scrolling, but the background scrolls in Firefox.
I need for firefox, thank you so much for a very useful tutorial.
Great help!
A small question:
How do I do it, if I need to make a gradient form bottom to top, in IE?
Thanks,
I was told that IE does not support gradient styling. Glad I visited this page. Highly appreciated.
Hello!,,,,,
thank u for this code this was really helpfull for me.Thank a lot.
ggfggg
Excellent post. All css gradient are awesome :)
look so great,,,nice job,Thanks a lot!,,,
I don’t think it gets much easier than using CSS Hat with Photoshop. If you have Photoshop. :) I review it and do short tutorial here.
http://twelvetwo.net/how-to-create-css3-gradients-in-photoshop-without-images/
what a great post. All the great experiences are in front of the eyes.
really enjoyed the whole article and learned a lot from this post.
Thanks :)
perfect thenks :)
Excellent post…!!!
I always avoided using gradients due to images and large amount of CSS but this is a different case. Only 4 line of CSS we can get our desired gradient scheme. This works fine in all the browser except opera. For opera we have to write this line
background-image: -o-linear-gradient(rgb(170,170,170),rgb(0,0,0));