4

I'm trying to get some text to have a gradient colour, but I haven't a clue how. I'm trying to get it like this:

Gradient image

The only thing I have tried is -webkit-mask, but I couldn't get that working how I wanted it to. The other thing would be -webkit-gradient in the color property - is that possible?

Cross browser compatibility is fairly important, but not the end of the world. I'd prefer the text to be a solid colour in IE than to convert the entire thing into an image (there is quite a bit of text like this, some of it dynamic).

callumacrae
  • 8,185
  • 8
  • 32
  • 49

1 Answers1

7

For webkit based browsers (Chrome & Safari) :

.text {
  font-size: 20px;
  background: -webkit-gradient(linear, left top, left bottom, from(#fff), to(#111));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

For IE & others:

http://www.webdesignerwall.com/demo/css-gradient-text/

Ryan McDonough
  • 9,732
  • 3
  • 55
  • 76
  • Thanks. Do you know of a way to do it other browsers, too? I'd like it if it worked in WebKit and Firefox minimum (although IE would be extremely nice). – callumacrae Aug 31 '12 at 13:05
  • Thanks, marked as solution. I won't use the link, as I would prefer it to just display a little differently than take away the ability to select text (although I guess that I could have another layer of text over all that with opacity 0?) – callumacrae Aug 31 '12 at 19:44
  • Why not to use modern `linear-gradient` syntax: `background-image:-webkit-linear-gradient(#fff, #111);`? – Pavlo Sep 20 '12 at 13:41