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.
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));
background: -moz-linear-gradient(top, #ccc, #000);
The following filter wlil only be read by IE:
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#cccccc', endColorstr='#000000');
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+ */
Below is a pure CSS gradient dropdown menu using CSS3 text-shadow, radius-border, and box-shadow (no Javascript or image)
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.
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.
Zia Rahman
I loved it. Thanks for posting this.
Alex
A nice little technique!
Thorsten
Cool. Thanks for posting this.
Manuel
Thanks for this great post :-) the example image of the CSS Gradient Dropdown Menu is very nice.
Kristof Neirynck
While internet explorer doesn’t fully support gradient angle it does have the GradientType property.
It has two possible values:
0 vertical (default)
1 horizontal
When you apply a filter in internet explorer it renders the text in that element with jaggys instead of using cleartype. Your menu has this problem on rollover.
Also see Gradient Filter on msdn
naran_ho
Interestingly, the only bad thing is Explorer always crashing. ;)
nelojin123
labai ivairu, isradinga!
Jordan Walker
Great demo and tutorial.
Chris Trygstad
Good stuff! This is what I did and it works great. I even went a step further and built a IE-specific stylesheet for the filter gradient fix. I’ve seen some examples use “background-image” instead of “background”. I would think “background” is right, and this hopefully confirms it. Any evidence that points to “background-image” being a better solution?
Alex Yamaguti
Nice tut…thanks for sharing!!! ✌
Andreas Rauscher
Very nice tut, i think this make my work a bit faster in future.
Thx for sharing this!
Crossbrower Goddess
Nice tutorial, thanks! Just and FYI for folks out there. The demo only works properly in IE 8. Gradient works in IE 7, the drop-down has issues, and his doesn’t work in IE 6 at all (which really should die but some clients refuse to upgrade).
Laurent
The biggest issue with using gradients for IE is that it breaks cleartype which makes the text ugly and unreadable half the time. The problem showed up in IE7 but it wasn’t fixed in IE8. Microsoft should just quit trying to make browsers already.
Greg
“It should only be used for enhancing the layout.” I think this is right on. CSS3 only styling should be an enhancement until the majority of browsers are using CSS3. well put
Deluxe Blog Tips
It’s not really cross-browser. It doesn’t work on latest version of Opera 10.50. It’s clear that the CSS code considers only FF, Chrome, Safari and IE and forgets Opera :)
James W
If you’re using multiple effects with IE which rely on filter:, they all need to be in the same filter: declaration. I had different classes for rotation, shadows, etc, but IE would only apply the last applicable class in the stylesheet. I had to add IE classes for each combination of filter: rules.
It’s too bad Opera hasn’t implemented CSS gradients, especially with Opera Mini topping the iPhone app store charts.
Boris
Have you guys seen/used http://csscorners.com for this stuff? doesn’t have the IE gradient code but who uses IE anyway
hawkman
Oh my goodness, why can’t Firefox use the same syntax as Webkit chose? Way to make this harder than it should be, guys. :-/
Massimo
Really nice technique; I think I’ll use it in the near future. Thanks
Tami
Filter = Proprietary code = bad. It is not a standard and shouldn’t be used. Some things really don’t need to be cross browser – if you have to use a gradient in IE, fall back to an image background.
Seiichi
Very useful! It dispenses with some gradient images.
Thanks for great tuts.
Mia Holte
With now more than 100 million Opera users, this can’t be considered a cross-browser technique.
Hiro
Nice job, but i think it’s not very useful in daily work!!!
Alexander
Can anyone tell me which W3 specification does the background gradient figure in, because I failed to find it in http://www.w3.org/TR/2009/CR-css3-background-20091217/#backgrounds (CSS Backgrounds and Borders Module Level 3)?
Because if it’s not part of the specification currently, then I don’t see the point of people complaining about browser implementation differences.
Ken Hamric
Took 32 screenshots across Windows Xp, Vista, Win7, and Ubuntu and OSX and made a slideshow so you can see the rendering on the popular browsers on each platform. See results here.
nazpro
fabulous…i love your topics ^_^
Jerome Bohg
Wow, never realized this feature. Thanks for sharing! Will use this in the future.
Clément Roy
Nice article (especially about ie filter).
Although there is a little typo error:
“The following filter WILL only be read by IE:” ;-)
monica of hola!design
Great post! I wanted to learn more about this technique, it’ll very useful for a project I’m working on. CSS3 is truly awesome! Thanks for explaining it so well.
Thiago
Amazing.
Hope to see more!
Joe
Nobody uses opera!
Get over it.
Great tut friends!
Matt Bridges
Excellent post! I have one point, though.
It seems to me that the IE filter only works for vertical gradients, thus limiting the amount of quasi-CSS3 available in IE. If there is another way of rotating the gradient for IE, that would be convenient to know, but I would wonder how many developers and designers care about CSS3 effects in IE…
Again, excellent post, and I LOVE the demo!
Felicity
Could you use this together with jQuery’s ‘support’ to display more traditional techniques for non-supported browsers?
David
Come on IE – get with it! :)
Cook
wonderful stuff…….
Marty
Thanks!
I love that css is finally making it easy to do things that could only be done graphically before… It’s a great age for website design!
Anders Bagnegaard Kristensen
Nice blog!! ajax and wordpress, this is an inspiration!!
ximi
If you want an appropriate fallback for browsers that aren’t supporting any of these techniques simply define a plain background-color before you define the gradients (e.g. background-color:#ccc;)
Lee
Nice. Love the menu bar.
Nashville Website Designer
Excellent technique. Cross browser is getting easier all the time. I’d be interested to see numbers on cross-browser frontend development time. I know I’ve spent waaaaaaay to many hours on it myself.
CPO - Drupal
Wow very nice collection! thank you very much.
Matt Anderson
This is great! I have been looking for a way to take gradients from images to code. I knew you could do it, but my knowledge of “heavy code” is pretty limited. I love it though.. thanks for sharing!
Louise
Hi, dear!
I really loved this post! I was looking for something like this. But…. I was testing and in my Opera, and it didn´t appear anything… =(
Someone could give a hand on it?
Tks!!!
Rabaya Bagum
I wonder whether it is possible to get gradient in horizontal direction?
Thanks.
gclub
I try to follow the examples already. Results have recently been encouraging.
sbobet
Work is not different. Based on competency of users.
Florida web design company
Wonderful! Trying it on a website.. will update if I come up with anything new. Thanks!
Michael Mior
This doesn’t seem to work in Firefox 3.5.9 :(
Max
There is a really nice PHP class that will create gradient image on the fly http://planetozh.com/blog/my-projects/images-php-gd-gradient-fill/ – I’ve used it a few times for my css backgrounds. I’m sure with a little skill the class can be expanded to have more options and patterns.
Lee
Very cool.
cleawalford
Thanks – will try it on a website soon!
Nick Dunn
@Michael Mior, the introduction states “but now with the Firefox 3.6+…” — it isn’t supported in any older Firefox version.
asd
thx for gradient tips
Guilherme Voigt
Im using Coda for codding in my 2 macs, but this gradient thing didnt seem to work. All my browsers re updated! I get a STRANGE result!!!
Guilherme Voigt
well, problem solved :) i was previewing in an empty document. LOL
marina
io solitamente acquisto on line , mi piace perche acquisto da casa , ho molta scelta e posso confrontare i prezzi , l ultimanente ho acquistato una FOTOCAMERA REFLEX NIKON su http://www.tecmania.it , unsa samsung , ricevuta a casa , bellissimo ……
Fotografia Ślubna Gdańsk
Very useful tut. Thanks a lot!
Cristian Ferrari
-ms-filter: “progid:DXImageTransform.Microsoft.gradient(startColorStr=’#444444′, EndColorStr=’#999999′)”; /* for IE8 */
filter: progid:DXImageTransform.Microsoft.gradient(startColorStr=’#444444′, EndColorStr=’#999999′); /* for IE6 & 7 */
Ming
This is great, but when it first loads the gradient does not fill up the whole screen initially. It vertically repeats the gradient like venetian blinds (different row heights across browsers) and then when the rest of the page loads it corrects itself. Unfortunately I can’t show you what is happening because the site is not live. It’s like I need a preloader or something. I tried a div that covers the page and then hides it with body onLoad, but that didn’t work. Any ideas?
jb
Ming, did you get an answer to your venetian blind gradient problem? My cross-browser gradient works fine if I set it from topright to bottomleft, but on straight topto bottom, I get the blinds. And it doesn’t go away. Help?
Web Design
Love it thank yOU@
Mikael
Waouh, very nice, thank you au lot !
Andy Griffiths
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.
vanessabionda
ho trovato dei buoni sconti su http://www.tecmania.it/ voi ne conoscete altri ?
grazie
Ganesh
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
Pao Im
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,
steve
Not working in opera 10.53 there is only a gray color…
zubair sota
gr8 comment.. thanx alot
Sun
the ie 7.0.6 doesn’t work with the crazy grediant which applied to the “tr”
Anybody know how solve it?
Web Design Seo
Thanks for sample code For Webkit Browsers.
Satish Borkar
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
George Lucas
Thanks for sharing going to use on my site on the next update here Thanks again!
fan
Your menu example is great. Thx!
Jarad
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.
pit
Wonderful menu!
stovak
you forgot one thing… IE 8 changed the property to -ms-filter and the filter command is in quotes.
Thany
SVG in combination with background-size is missing. If done correctly, it should work in Opera.
TMUkmkd
thanks for the tutorial. but chrome (chromium) 6+ (that only i test) have small bug in inset.
Design Hippo
Interesting tutorial. Keep up the good work
Freelance Website Design
not working in ie6…
NightKev
Why did you even bother to check IE6? Anyone who still uses IE6 (and is not being forced to) is, quite frankly, a moron.
Danny Internets
This does not work in the current version of Firefox (3.5.10).
def.
tnx :) very simple and very helpfull…
tdpt
@Danny Internets: Really? 3.5.10 is the current version of Firefox? What about 3.6.6? BTW, Firefox 4 beta is out…
code pixelz media
Nice article. Thanks for taking time to create this article.
Florian
Not really “cross-browser” if your proposed hack doesnt work in Opera. ;)
If you’re a professional web designer: stop hacking and wait till an implementation is released by W3C.
Lisa
Works great in IE, Chrome, and Safari.
Does not work well in Firefox.
Willie Hartman
Excellent and informative. Thanks for taking the time, don’t worry about those who don’t appreciate the effort.
Justin
Hahahhahaah. IE 6.
kai
tha’s simple and usefull… thanks…
david
Hahahhahaah. IE 6.
it uses the filter:?
anyway, really helpful.
i just searched for gradients with alpha support, but rgba and #00000000 in the filter did it.
Sniffer
I’m finding this works real sweet if you want to get earlier versions of IE working – http://css3pie.com/
Weblap.ro
Thanks, exactly this is I was looking for! One mention: the picture gradient is also cross browser and can be dithered which is a litle bit better.
Jason Williams
Thanks so much for these tips. It’s incredible that IE doesn’t support so many things when it comes to CSS. I hope soon they realize the importance of this. Why do they refuse to cooperate with things that other browsers support?
Some Funky Dude
Very nice, thanks for sharing.
David
Filter doesn’t seem to work in IE. What ever I change the hexadecimal value too it still renders blue.
Aaron S
When this filter is applied in IE, text smoothing is disabled (tested in IE8), which is not so nice for users with text smoothing enabled as it’s a very obvious difference in text rendering, the best option here may be to have a fallback background image for browsers other than Firefox, Chrome, and Safari. This would be done by specifying the background image as the background property as the fallback in the example above.
Felix Nagel
Cross browser? Does not work in latest Opera and Chrome on Win.
Sławek
thanks, very usefull
Andrew
very helpful. clear and to the point, with no obfuscation. thank you!
Adam Clark
Is there a way to give a gradient to text (not a background gradient).
D.A.J
Nice one. It is a really useful.
jeff
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!
MB
Thank’s a lot for all tutorials and tips
Ron
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 :)
Chikezie
It still amazes me that we’ve come all this way with CSS3 and we still can’t standardize on presentational code.
crashfellow
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??
ospop shoes shop
Wonderful menu!
Deepti
Thanx its awesome script. Gradient in IE was the major problem but using this sceript that problem is solved thanx a ton.. :)
Lauren O'Donovan
Thank you so much for the great tutorial!
Grande
The style is working in ie7 perfectly but not in ie6.Do i need to have some other setting.
Craig
Chikezie you complete and utter moron. You really should do a little reading before exposing your stupidity so openly.
mary
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.
yereverluvinunclebert
lovely site, very informative
Kobeef
Very useful & nice. Love!
ایمان
ovely site, very informative, Thank you so much for the great tutorial!
Las Vegas Web Design Company
very nice ..like it..good work.
Adrian
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!
Xupicor
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.
The Best-Best of me
Awesome tutorial, thanks for this bro.
Sayela
Your post is very nice and insightful. Have just started implementing this feature.
Mr.willsons
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
Koos
Tnx for this incredible post! You saved me a lot of hours!! (y)
jeterboy
Thanks for this, awesome css script.
Jeff Sebring
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 . .
Zain Shaikh
Coool.
Henry Peise
Want to change your belove iphone 4 form black to white? Hmm, yes, so am I. but when will white iphone 4 available?
Juno Mindoes
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?
Matija
Thanks a lot, this helped me greatly!
Christopher
Does not work in IE 7–in fact in your example, the popout menus in the drop down do not display.
Ryan Vars
your gradient code doesn’t work on on IE 8.
Thanks for the great article thought.
Max Williams
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)
shyam
Thank u very much, i am upset for last 1 week thanks thanks……… this helped me greatly!
Melvins
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
Daniel M
use endColorstr=’white’ instead of endColorstr=’fff’.
For some reason it likes to make white black.
Dhan
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?
gtagamer
Is this compatible to safari?
Jon
excellent! Had no idea you could gradient with just CSS in ie7/8!
Uçak Bileti
hasret kanımda
Manish Runwal
How to make these things valid for validation of css3 ?
ft leonardwood
Brilliant, as usual. Well explained, the gradients worked fro me the first time. I am super ADD too so this is a big task. :)
Ben
I must admit that I enjoyed reading your creative article as you did put pen and paper together to write such a flowing article
chekwan
how about Opera.??
Jamie R
Thanks for posting this article. I was almost ready to give up and go back to button images rather than gradients. You saved me a lot of time.
HeaterHut
Daniel — I think the problem is that IE doesn’t like it when you try to use the abbreviated 3 digit hexcode for the color, as compared to the full 6 digit code. Try ‘ffffff’ instead of ‘fff’ and it should work!
shyam
I want left to right gradient.
seo
This is a really great problem resolved, because cross-browsing it is a big issue at this point.
But i don’t see how you can control the gradient’s dimensions, or -for instance – to repeat or not, to take 80% or 100% of background’s height – maybe you have an ideea?
Tanks!
joe
i just visited this website right now and find it nice . the design, i was really amazed on how did they make it possible to build a site like this. is there a tutorial on how something like this site could made possible. example is this comments list. showing comments the way it shows here was really creative. is there some one who could give idea on how to build something like the way the comments shows here. the design was really amazing
li
1321423 rq 214 132
css splash
Is left – right gradient possible? Web Design Inspiration Gallery
Newlineinfo
Really a great tutorial, i used this gradient effect. Thanks a lot dude!
Vector
Wow, great tip! Thanks for sharing, using this for checkout buttons without images for my shopping system :D.
Red Blue Websites
Just what I needed right now. Thanks.
seo
really interesting gradient and the code works like a charm!
this cross-browsing issue it’s a very sensitive one, i have a lot of trouble with all these versions of browsers…
J K
This article will prove useful to many people.
However, the IE filter will only work for versions 5.5 to 7. You need the -ms prefixed version for IE8.
-ms-filter: “progid:DXImageTransform.Microsoft.gradient(startColorStr=’#cccccc’, EndColorStr=’#000000′)”;
pneumatig
This week Opera releases version 11.10 with css gradients support :)
What about IE9 ??
Sarah
Many thanks for sharing, nice tip..
How To Put On A Condom | How To Get Taller
Your updated dropdown menu in the demo using CSS gradient is amazing!
How To Get Taller | How To Put On A Condom
This article taught me how to code for the CSS gradient to be supported by the major browsers: IE, Firefox 3.6+, Safari, and Chrome. Must read! From blog to blog!!!
mine
Dropdown menu looks cool in browsers. In IE9, li’s don’t take the border-radius, so they are plain rectangles.. Just another thing that is great but you cannot use it generally without a hack. Thank you, microsoft! Maybe in IE10.
Website Design Sheffield
This is perfect, thanks solved my problem straight away :)
Aleare
Thanks a lot! I had some display problems with Chrome but now they’re solved. You are my hero :D
harv
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
Ranjeesh
Great information about the Gradient! Right to the point. I exactly needed this multibrowser gradient code.
Thank yOu
TheCyberBug
Fantastic! Thanx a mil. I would have tried x-repeating a pixel wide image, lol.
decia
Cheers for this, having some problems with firefox4 repeating a vertical gradient however.
Aaron Zipagan
good one! very helpful! Thanks!
Aaron Zipagan
by the way, really love your site!
Mike
Awesome trick. Thanks!
Eddie Rowe
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?
2
3
MyBB
Awesome trick. Thanks!
Simon
Very nice. Especially the menu! Can’t wait to implement this on my site!
Daniel
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.
dexx
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.
Atul
Great Fix !!
Heather
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.
Rob
Had no idea this could be done with CSS, thanks!
Eric
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?
Andrew Myers
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.
mark
thanks Mike, good spot!
Srinivas Thammineedi
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
Kyper
Thanks for this tutorial, works fine for me :)
Dinesh
Internet explorer gradient is not working in ie8. Other wise every thing is good.
J.T.
It might be due to the message ie8 displays above the website:
“To help protect your security, Internet Explorer has restricted this webpage from running scripts or ActiveX controls that could access your computer. Click here for options.”
You need to accept the running of scripts and ActiveX controls in order to make it work.
In case this does not work you can try a different approach with the use of -ms-filter instead of filter:
-ms-filter: “progid:DXImageTransform.Microsoft.gradient(startColorstr=’#cccccc’, endColorstr=’#000000′)”;
Linda
This works great. Is it possible to implement two vertical gradients for a background? For example, Gradient1 is in the background to the left of the main content/body and Gradient2 would be to the right?
Kevin
How would you added transparency to the gradient?
like have the top of the gradient black at 0.8 transparency and have the bottom of the gradient black at 0.2 transparency
Matt
Try substituting the hex code for RGBA codes — i.e., RGBA(0,0,0,.8) for the .8 transparency black. Just a thought, not tested.
michael
You define alpha transparency in IE filters via the hex value, like:
#AARRGGBB, where AA is the alpha transparency level (00 is transparent, ff is opaque) and RRGGBB are your RGB values. http://msdn.microsoft.com/en-us/library/ms532879(v=vs.85).aspx
alan
For me this only worked in IE8 after adding width and height css attributes.
Even if i use 100% IE8 required it :(
But thanks for the code!
Jared
This is all groovy and works perfectly, but interestingly the w3c CSS3 validator throws an error for gradient values attached to background-image, background-color, and background. Haven’t found a way around this and I’m just going to ignore it I suppose… I just love seeing the green “Congratulations!” bar when validating my markup and html :D
Mont Blanc Pen
What is friendship?Mont Blanc PenWhy do we call a person our friend? When do we call someone a very good friend?
OnLine
Hy,
Thank you for this article.
It’s seems in Opera doesn’t work css gradient.
spring valley vitamins
Thank you. for this articles.:)
Oswald
Hi
Thank you so much for this, it helped a lot; I’ve been looking all over the web for gradient backgrounds for quite a while!
Thanks again
Dee
Thank Man.
Darian Brown
Just a heads up on a typo under the “For Internet Explorer” section. You typed wlil instead of will.
Cheers,
D
SEO
Thank you for that very interesting.
Manisha
No, It does’t work in IE9. The Drop-shadow effect does not work in IE9. So this is not CROSS BROWSER at all!
I am not sure why should someone use if it is not browser compliant?
iphone 1st gen
Thanks so much for giving everyone an extremely spectacular opportunity to read articles and blog posts from this web site. It is usually so excellent plus packed with amusement for me and my office mates to visit the blog at minimum 3 times in one week to read the new tips you will have. And of course, I’m actually motivated concerning the extraordinary principles you give. Certain 1 areas in this post are truly the most suitable I’ve had.
TimKola
just to let you know to add for IE10
IE10 will be supporting gradients its the same as mozilla with the -moz but with -ms
example below
/*IE10*/
background: -ms-linear-gradient(left top, #017AC1, #00bcdf);
hope you found this helpfull
Barbara Tallent
Thanks Tim! I just tried our site on IE10 and was baffled by the whole gradient thing. Your info worked great!
orhanbt
This is verry good
bankaciyim.com
ihtiyaç kredisi
ev kredi
konut kredisi
uygun kredi
masrafsız kredi
kredi oranları
bireysel kredi
masraf ücreti
kredi hesaplama
kredi hesaplama
taşıt kredisi
Tüketici kredisi
Logan
Thanks for the cross-browser one, it was just what I needed.
jumancy
How to make gradient for IE from left to right, NOT from top to bottom
Gemini Shadows
To do this, you will need to add a GradientType parameter to the code. The default GradientType is 0, which is vertical. If you set it to 1, as below, it should be horizontal.
filter: progid:DXImageTransform.Microsoft.gradient(GradientType=1, startColorstr=’#cccccc’, endColorstr=’#000000′);
Hope this helps out.
geo
works like a charm, i can manipulate from every corner of the div tag. f$$k internet explorer, didn’t tested yet. but far as i know, webkit scripts won’t be read. why MS , why ?
Franz
Great work. Keep it up !
Dallas Web Designer
Thanks for the tips. I used this in one of my designs today ;)
Greg McGee
Thanks for this snippet! Works like a charm with no alteration.
diz
Don’t follow these blindly anymore. All major browsers support official syntax for CSS gradients.
Use something like:
-webkit-linear-gradient(…)
-moz-linear-gradient(…)
-o-linear-gradient(…)
-ms-linear-gradient(…)
linear-gradient(…)
No need for old webkit crap (unless you really want to stay compatible with old webkit).
And “filter” might be useful too as IE supports CSS gradients from version 9 only.
Franky
Agreed witz Diz, this solution is everything but cross-browser. It uses a filter for IE, and two vendor-specific prefixes for webkit and firefox … you cannot get any less cross-browser.
really
are you an idiot or just not know what your talking about?
npc
I dunno, just putting the 3 lines in the post didn’t work in every browser for me, but after using Diz’s method it worked.
Dated
Look at the date of the post before complaining that something doesn’t work. In the world of web browsers and CSS3 support, do you really expect a post that’s over a year old to still be completely valid?
Karunakar
Thanks for the Gradient Tips I Used for an Tool Tip and it’s working fine.
Ather Rehan
That was amazing….
But what for Opera and safari ? :(
Lin
See: Safari IS built on webkit
Juvy Cagape
Best post, with using this trick I think no need to use ‘canvas’ tag of HTML5 if you want browser compatibility, cheeeeers.
xbox 360
Thanks for the information of interest.
Ravi Thakur
thanks.. this solve my problem..
Tieson
Sure solved my IE woes!!! Thanks for a great post!
Devendra
Thanks for this code.
commend
thank you! good post.
have a quick question. is it possible to load a image if the browser is non css type? and how to do it? thank you again!
devendra
thanks for this code…
André Thiago
Very useful tips!!! Thanks for sharing this.
Khaled Bin A Quadir
Thanks :)
It’s a great CSS3 feature!
thetoast
Here’s a complete example;
background: #e0e0e0;
background: -moz-linear-gradient(top, #e0e0e0 0%, #fff 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#e0e0e0), color-stop(100%,#fff));
background: -webkit-linear-gradient(top, #e0e0e0 0%,#fff 100%);
background: -o-linear-gradient(top, #e0e0e0 0%,#fff 100%);
background: -ms-linear-gradient(top, #e0e0e0 0%,#fff 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr=’#e0e0e0′, endColorstr=’#fff’,GradientType=0 );
background: linear-gradient(top, #e0e0e0 0%,#fff 100%);
custom tailor
nice tip…..
Biltong
Thanks, nice tip used today.
toilet roll holder
That’s a great step-by-step tutorial. Thanks for sharing your knwledge!
Morne
Im trying to apply a gradient as a background to a table row but this does not seem to work in IE. My implementation does not allow me to use a gradient image. Any suggestions please
Marilize
IE Sucks big time – everyone get Mozilla or Chrome
Freaking IE sucks
Mitya
No mention of Opera’s approach. A shame to see another dev article ignoring what is a solid and very innovative browser.
Ron
Solid and innovative, fine, but it has about the same market percentage right now as IE6.
Chris
But as of now, around maybe 50 percnet (it was either 46 or 53, can’t remember) of internet users are using IE. I don’t like IE, but people still use (can’t imagine why, but OK, since most people don’t change browsers, and others actually ‘like’ IE….but I’m not here to judge….just give you the numbers) it.
Rissy
Many people still use IE b.c it is the internet browser that comes already on the CPU’s … BOOO!!! My fav is Flock (Firefox) =D
Gary
Opera’s layout engine appears to render just fine, whether it picks up the Mozilla or Webkit directions for layout. I wouldn’t worry too much; maybe it wasn’t worth a mention because Presto just works.
Marilon
What about you Marilize ? Do you suck big time ?
Kunal
Thanks a lot !, this was very help full
Garfield
great , just great
worked perfectly.
now to find a rounded corners hack for IE.
G
Ron
CSS3PIE
Alex
>now to find a rounded corners hack for IE.
I recommend this http://css3pie.com/
Works like a clock.
Imran Naqvi
no gradient in opera
rizwanabbasi
Gradient for all browser
background-image: -webkit-gradient( linear, left bottom, left top, color-stop(0.10, #124f7e), color-stop(0.90, #3b89c5) );
background-image: -moz-linear-gradient(center bottom, #124f7e 10%,#3b89c5 90% );
background-image: -o-linear-gradient(90deg,rgb(18,79,126),rgb(59,137,197));
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=’#3b89c5′, endColorstr=’#124f7e’); /* for IE */
background-color:#124f7e;
Robin
Gradient for ALL browsers:
background-image: -khtml-gradient(linear, left top, left bottom, from(#ee5f5b), to(#c43c35));
background-image: -moz-linear-gradient(top, #ee5f5b, #c43c35);
background-image: -ms-linear-gradient(top, #ee5f5b, #c43c35);
background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #ee5f5b), color-stop(100%, #c43c35));
background-image: -webkit-linear-gradient(top, #ee5f5b, #c43c35);
background-image: -o-linear-gradient(top, #ee5f5b, #c43c35);
background-image: linear-gradient(top, #ee5f5b, #c43c35);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=’#ee5f5b’, endColorstr=’#c43c35′, GradientType=0);
MAAZ
IS IT SUPPORT FOR IE7 – 8 – 9
O'Dejoye
Rounded corners are easily created in IE9 as in the following line of css example:
box{
border-radius:15px; //for IE9 and Opera
-moz-border-radius:15px; //for firefox
}
Try on other browsers to see how it works.
Adam Pery
See nice custom menu line-gradient example here:
http://www.xhtml.co.il/en/Tools/Linear-Gradients-Custom-Menu
It is really helpful
Pav
great work thanks
John
Well done, Thank you
fjjiaboming
Kill IE!
Elijah Clark
thanks, been looking for this all day.
Bradley Collins
thanks… very helpful for seasons greeting background let me try this…
Thomas
Yes all this works on the latest browsers, however I need to find something compliant for ALL browsers and versions. Try putting gradients on IE6. pfft.. IE is super gay…. damn you microsoft, damn you.. Any one have any ideas?
Thomas
Oh and pie will eventually give you problems down the way, and modinizir is useless too…….
Dan Avery
Thanks! I have been wrapped in an IE form nightmare and couldn’t get IE9 to accept any background color to the input fields until I ran across this fix. Now I have not just a color but a gradient. You rock!
sap netweaver
Thanks! this was helpful. How do a get the gradient to appear from left to right for IE?
seolsearchkaty
I have a piece of code in my site that uses the gradient code and I can’t work out how to make it compatible with Chrome. I have tried various codes but am not having any luck. Can anyone help?
http://netstorepro.com/digthis/book-now
Specifically, I am having problems with the button:
#griddler .button {
background: -moz-linear-gradient(center top , #53CC13 0%, #4CBF10 49%, #3FBA00 50%, #3BB000 100%) repeat-x scroll 0 0 #3BB000;
}
and the the background of the pricing area.
spring valley vitamins
definitely, a BIG BIG deals.thx, for article
Nik
Damn on u IE !!
Serwat
Hey Mitya I just saw this and coded it for Opera…background: -o-linear-gradient(top, #06F, #006); Note that these were my color choices. Good point though.
shishir
not work at opear….
shishir
@Serwat sorry its works….
kb667
Opera browser was missed,
i use this for all browsers, tested on :
IE 8.0 , FireFox 12.0 , Chrome 18.0 , Opera 12.0
background-color:#55aacc;
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=’#55aacc’,endColorstr=’#ffffff’,GradientType=0);
background:-webkit-gradient(linear,left top,left bottom,color-stop(0%,#5ac), color-stop(100%,#fff));
background: -moz-linear-gradient(top,#5ac,#fff);
background-image: -o-linear-gradient(#5ac,#fff);
Jared - Regina Web Design
Very nice. Any idea on how to do cross background gradients and also use a background image?
Ivo
I can’t answer to your question, but why don’t you use for example: 2 s
Oren
Is there a way to control when the gradient effect begins and where it ends? I want it to make the transfer earlier…
Thanks,
Oren
Ivo
I tested this:
mozilla-> background: -moz-linear-gradient(50px, #FFF, #000);
result:
the gradient starts at 50th pixel from left to right
1st pixel->#FFF background color ->50th pixel -> gradient to the right end of the element
—————————————————————————————————-
Chrome
background: -webkit-gradient(linear, 0 120, 0 180, from(#F00), to(#000));
result:
linear gradient from top to bottom -> first 120 pixels are #F00, from 121px to 179px is the gradient, then from 180px to the end of the element the color is #000
—-
background: -webkit-gradient(linear, 120 0 , 180 0, from(#F00), to(#000));
result:
same as above, but from left to right
Bianca
So how would I do a gradient from top to bottom so that the bottom gradient starts at 50% for -moz? If I set -moz-linear-gradient(50%, #FFF, #000); it is from left to right, but I want it to go from top to bottom…
Guy
Hi Bianca, in case you’re still looking for a solution, simply inform at what point you want the gradient to start (the XX%):
background: -moz-linear-gradient(top, #cccccc XX%, #ffffff);
jayson
i think i found the answer to your question
jayson
http://css-tricks.com/examples/CSS3Gradient/
Rich
What if I wanted to have two gradients on the same element… Taking the example above, what if I wanted to extend it by having white gradient into black on the top AND bottom? Is this even possible?
Ivo
/* The old syntax, deprecated, but still needed with the -o, -ms and -webkit prefixes*/
background: linear-gradient(top, blue, white 80%, orange);
mizilla 10
/* The new syntax needed for Firefox 10 onwards, with the -moz prefix */
background: linear-gradient(to bottom, blue, white 80%, orange);
Dora
Felt so hopeless looking for answers to my qusiteons…until now.
Ivo
background-image: linear-gradient(bottom, #000000 47%, #00FF00 74%, #FFFFFF 87%);
background-image: -o-linear-gradient(bottom, #000000 47%, #00FF00 74%, #FFFFFF 87%);
background-image: -moz-linear-gradient(bottom, #000000 47%, #00FF00 74%, #FFFFFF 87%);
background-image: -webkit-linear-gradient(bottom, #000000 47%, #00FF00 74%, #FFFFFF 87%);
background-image: -ms-linear-gradient(bottom, #000000 47%, #00FF00 74%, #FFFFFF 87%);
background-image: -webkit-gradient(
linear,
left bottom,
left top,
color-stop(0.47, #000000),
color-stop(0.74, #00FF00),
color-stop(0.87, #FFFFFF)
);
Brian Wrightson
Really useful; thanks!
Rajesh Jha
How can i use multi gradient in same element. plz give me solution.
Ivo
As I told to Rich:
background-image: linear-gradient(bottom, #000000 47%, #00FF00 74%, #FFFFFF 87%);
background-image: -o-linear-gradient(bottom, #000000 47%, #00FF00 74%, #FFFFFF 87%);
background-image: -moz-linear-gradient(bottom, #000000 47%, #00FF00 74%, #FFFFFF 87%);
background-image: -webkit-linear-gradient(bottom, #000000 47%, #00FF00 74%, #FFFFFF 87%);
background-image: -ms-linear-gradient(bottom, #000000 47%, #00FF00 74%, #FFFFFF 87%);
background-image: -webkit-gradient(
linear,
left bottom,
left top,
color-stop(0.47, #000000),
color-stop(0.74, #00FF00),
color-stop(0.87, #FFFFFF)
);
Martin @ Web Task Technologies
This is awesome. No more need for a big image editing program!
ifeanyi
nice one. still mad at ie flops
Rohini
hmmm ..Thanks really very useful .. :)
Craig
I think the systax for Firefox 10+ has changed, which is bad because all firefox browsers need the the -moz prefix. https://developer.mozilla.org/en/Using_gradients
Jules
For anyone interested in a gradient generator that creates the SVG code (required by IE9) for ANY CSS linear or radial gradient, see http://www.visualcsstools.com. There’s a free and a cheap version.
Glan
One big thing which is missing is from this article which you can do these days is stacking of multiple image values (aka gradients) in a single background.
For example:
background-image: linear-gradient(left, rgba(0,0,255,0), rgba(0,0,255,1)), linear-gradient(top, #FFF, #000);
If you want to explore the potential of multi-layered gradients check out:
http://glan.github.com/CSS-Patterns-Workbench/#2301441 (use a webkit browser).
and
lea.verou.me/css3patterns/
mouse
This doesn’t work quite as expected when applied to the body element:
body {
background: #F00000; /* for non-css3 browsers */
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=’#cccccc’, endColorstr=’#000000′); /* for IE */
background: -webkit-gradient(linear, left top, left bottom, from(#ffffff), to(#000000)); /* for webkit browsers */
background: -moz-linear-gradient(top, #FFFFFF, #000000); /* for firefox 3.6+ */
margin:0;
height:100%;
width:100%;
}
In Chrome, I get a gradient down to the end of whatever is filling the body, then it repeats the gradient until the bottom of the window. Is there a way to extend the gradient to the bottom regardless of the content? And also to have it be similar to a background url in a no-repeat fashion so the gradient covers the current window size, and the content of the page can scroll without scrolling the gradient? Currently, I can do this with a some javascript, but it would be nice if it worked with the CSS styles.
Example of issue @ http://tamaratemple.com/cgi-bin/gradient-example.cgi
Caroline
Same problem for me. It seems fine the first second but when my website are fully loaded the gradient starts to divide. :(
Francis Boudreau
Wonderful tip.
Thanks!
gavin
I came across the weirdest effect with this gradient application. when applied IE8 creates kind of a “knockout” effect on my text. in otherword i can see right through my text to the background image.
iam creating flip cards with css3 trasition and animation. and when the card flips there are buttons on the back of the card the buttons have a class applied to it with the gradient. and white text. but the text and border creates the knockout effect in ie8….. any suggestions on what my be causing this?
Bryan
Thanks for article. I used your filter code for Explorer and I can now see my gradient background in my header. I inserted the filter code into my footer CSS b/c it also uses a gradient background, but some reason it’s not showing up still on Explorer.
Any idea’s?
Lam
Awesome!
Con
Sorry guys, but how do i apply the ie code so that the gradient goes from left to right instead of top to bottom. Any help would be greatly appreciated. Thanks.
raj
but this gradient not working on opera browser
Andrew Jackson
You did a great job, thanks a lot.
Ailton
Bro..you solve the day!
Thanks a Lot!
Chris
hmmm… The css dropdown menu doen’t work for IE 7 :-(
Meera and Jaideep Kibe
Hi, I loved your site.
I want to create a linear gradient for the background/viewport. I am able to successfully do the linear gradient in divs. and other such containers. Mt problem is how to make the linear gradient stretch in the background
Thanks
TechbulletsPH
You can apply the background in the body tag like:
body{
…Your gradient background css code here :)
}
streamdr
Thanks TechbulletsPH. Top man :)
Ric Torres
The problem with background gradients is often that they must either be a fixed width (100%) or must be set to auto, which then ruins the relative size-ability of its child divs. My solution was to give ALL parents a 100% height, starting with
html,body { position:absolute; top:0; left:0; height:100%; width:100%; /* and gradient goes here */
}
Once this is set, the gradient starts over after 100%, so to keep everything contained
.body_double {
height:100%;
width:100%;
overflow:scroll; /* the fun begins!!! */
overflow-x:hidden; /* no thanks, sideways scroll */
}
.container { /* parent div to all percentage-sized contents. */
width:90%;
HEIGHT:98%; /* now I can safely place a 2% height footer, outside of this div, that stays at the bottom of .body_double */
margin:0 auto;
float:none;
text-align:center /* for IE centering */
}
.MainLeft { /*first child to .container*/
position:relative;
HEIGHT:100%;
width:66.666667%;
float:left;
clear:left;
}
.MainRight { /*second child to .container*/
position:relative;
HEIGHT:100%;
width:33.333%;
float:left;
}
Footer goes outside of .container and has a 2% height, but remains within .body_double, your gradient is fixed while appearing fluid, and your page scrolls at the y-axis. THE ONLY Setback I can find, is that a scroll bar is inevitable. So far, this is the best answer I can find for a background gradient at 100% while also maintaining a re-sizable child div. Anybody who knows an easier way is my hero.
Ric Torres
I meant to say “fixed height” above, at the very beginning…
Ric Torres
I take it back. That was a stupid solution. Against my own will, I tried a fixed position background image (1px by 1800px) repeat-x, using the background-size:contain rule. Much more success. The fixed position image in the background allows inner divs to be any length, because it stays as the full-size background no matter how scroll works.
Wolfgang
I tried using your pure css navigation bar and the colors when you hover over something or when a button is set to current does not work in Google Chrome. Is there a remedy to this?
jules
Hi,
I left a comment a couple of months ago regarding a program I’ve written that can generate the CSS and SVG code for all possible CSS linear and radial gradients.
The good news is, I’ve since learnt Javascript and converted the program to an online web app at visualcsstools.com.
You will need a modern browser to view the page. If you use IE, you’ll need IE9+, which can handle SVG graphics. If you have the IE10 preview, you’ll be able to see the output in both CSS and SVG.
All other browser users should be fine assuming that your browser version is pretty much up to date.
If you have any comments, then please email me at the address provided on the web page.
Cheers,
Jules
Gayatri
This was really helpfull for me.Thank a lot.
eliph26
Thanks!:)
abhishek
can you help me for making text gradient masking.
Devendra
thank u for this code ,, thank u very much.
abhisekh ranjan
can it work with magento
Rajesh
Thanx a ton…
lavanya
hi, i want gradient to be supported by all browser types.
Please help me.
thanks.
Georgi Yankov
Thanks, very useful article and well explained!
pouya
ok,thanks,very good
Alexa
is there a way to create a gradient background without the use of -moz-?
K
what if you what a gradient with multiple colors? How do you put that into the code?
Logan
Yay finally found a code that works in all browsers – been having a hell of a morning trying to get this figured out. Thanks :)
Yates de lujo en Ibiza
The good news is, I’ve since learnt Javascript and converted the program to an online web app at visualcsstools.com.
You will need a modern browser to view the page. If you use IE, you’ll need IE9+, which can handle SVG graphics. If you have the IE10 preview, you’ll be able to see the output in both CSS and SVG.
All other browser users should be fine assuming that your browser version is pretty much up to date.
If you have any comments, then please email me at the address provided on the web page.
Uds
Thank you.. Thank you.. Thank you..
Scotty
Thanks so much, awesome tutorial!
Patrice
OK thanks
security
Very useful! Thank you
Rich
That is awesome. Thanks so much for posting that. I was just about to get into photoshop to create the old school gradiant image that is a nightmare when vertical as it’s never the right length and I thought to myself, now that was years ago we had to do that. Perhaps there is a CSS technique by now. And there you were, thanks mate
Rich
Alquiler yates Ibiza
Thanks so much for posting that. I was just about to get into photoshop to create the old school gradiant image that is a nightmare when vertical as it’s never the right length and I thought to myself, now that was years ago we had to do that.
Sam
This is actually great! I have been searching for this a long time.
brian
you forgot about Opera.
i use this solution
ERVIN
Thanks for the great advice and tutorial! I did find that Opera was left out of the picture and the same gradient effect is achievable via:
background-image: -o-linear-gradient(top,rgb(100,100,100),rgb(200,200,200)); /* Opera CSS3 */
Thanks!
Sanjay
Hiiiiiiii
lbt
Thank you, very usefull!
himu
Thanks for the post.
want to know more on this topic.
CockpitSeeker
You forgot about IE 8 that uses -ms-filter for god knows what reason…
Ex: -ms-filter: progid:DXImageTransform.Microsoft.gradient(
startColorstr=#550000FF, endColorstr=#550000FF
The weird hex code coulours (with 8 digit instead of 6) is just for transparency…
I got this at http://stackoverflow.com/questions/2293910/css3-transparency-gradient
vagabond
i just want to make it 334 (comments) …and awesome tutorial
djanggo
many thanks man, it really help me a lot :)
Chloe
tyty. was just about to revert to using a photoshop gradient image as a background which likely would of looked horrible and taken much more time :s
Ivan
Thanks for this. I got the gradient css for IE to show up, however, it does not validate under the W3C standards.
Zainal
work all browser very nice. thanks
OammieR
Thank you so much brother.
kombi
However, in IE, the background won’t stay fixed, extends the length of the body and doesn’t seem to respond to the background-position 0px 100px. Any advice on a workaround would be greatly appreciated.
DymoLabels
hello sir
i really like the CSS site
thanks for sharing this blog
thanks