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 is perfect, thanks solved my problem straight away :)
Thanks a lot! I had some display problems with Chrome but now they’re solved. You are my hero :D
hey aleare, did chrome just automatically stop your gradient and begin again halfway down your page? if so how did you fix it? thanks :D
Great information about the Gradient! Right to the point. I exactly needed this multibrowser gradient code.
Thank yOu
Fantastic! Thanx a mil. I would have tried x-repeating a pixel wide image, lol.
Cheers for this, having some problems with firefox4 repeating a vertical gradient however.
good one! very helpful! Thanks!
by the way, really love your site!
Awesome trick. Thanks!
I can’t get webkit to render a gradient on the ≤html≥ level element. Is this to be expected? It works in FF and IE. How do I fix?
3
Awesome trick. Thanks!
Very nice. Especially the menu! Can’t wait to implement this on my site!
hello ,
My name is daniel and I own nigerian forum
I’m an ardent reader of your posts and not just to leave leave without writing a comment this time around, I love the informations you share through this post especially where you wrote ” 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. ”
Keep it up friend.
Recent surveys, children of depressed mothers’ negative patterns of activity occurring in different brain reveals. This is for children of mothers who take more risks in the future is going to have depression.
Great Fix !!
Anyone know when IE will step up to the plate and support color-stop, gradient angle, and radial gradient so we can do the cool menus in IE as well? First it was fonts and now this – so frustrating.
Had no idea this could be done with CSS, thanks!
This works perfectly, thank you. I would like to use it as the background of a website, which also uses a watermark image centered in the background, but it does not seem to be working. Is this not possible with a gradient?
I used your CSS button gradient page to perfect some buttons at http://www.geoffreymyers.com/correspondence..html and found through testing that the IE gradient syntax does not recognize CSS color shortcuts. For example if you call #eee you get no results, but #eeeeee works fine. Just FYI.
thanks Mike, good spot!
Really it is very useful for who are looking to implement gradients with using css. I love your site a lot Great combination of colors and font. Great trick. Thanks a lot
Thanks for this tutorial, works fine for me :)