27

Is there a way to create a cross-browser, pure CSS3 text color gradient?

So, no png's. No 'webkit' only.

EDIT: To be more precise: It's CSS3 only, and it's for text, not box gradients.

EDIT: I found this solution, but it's only for webkit.

Kriem
  • 8,666
  • 16
  • 72
  • 120
  • across which browsers? the ones that support CSS3? – zzzzBov Jan 19 '11 at 20:04
  • Is the background a solid color? – Lea Verou Jan 19 '11 at 22:55
  • Nah, I forgot that pngs won't do. How about an SVG solution? It's supported by all CSS3 supporting browsers, doesn't need any images and is quite accessible. – Lea Verou Jan 22 '11 at 02:47
  • 1
    [Here's an SVG example](http://stackoverflow.com/questions/3634663/masking-an-image-with-selectable-text-with-svg-possible/3636303#3636303) - it uses an image rather than an SVG gradient, but that should be easy to change. – robertc Jan 24 '11 at 19:49
  • 1
    It's easy, you can refer to this article: http://www.webdesignerwall.com/tutorials/cross-browser-css-gradient/ – Jay Jan 19 '11 at 19:59
  • That's limited to box gradient only, I'm afraid. I'm looking for text gradient. – Kriem Jan 19 '11 at 20:17

4 Answers4

13

There is no cross-browser way to do this outside webkit because only webkit currently has a background-clip: text, and this extension to background-clip is not on standards track (as far as I am aware). If you want to relax your CSS3 requirement, you can accomplish the same effect cross-browser with Canvas (or SVG), but then you're talking about HTML5-capable browsers only.

Michael Mullany
  • 30,283
  • 6
  • 81
  • 105
5

There is no "pure" CSS way at the moment, but there is a way using CSS and some duplication of content. See my server side css gradient text solution here, which doesn't require JavaScript or plain background. You can also do this client side using JavaScript, see what Dragonlabs has done here.

Gus T Butt
  • 197
  • 2
  • 4
  • Very impressive and intuitive. Thanks for this option. – Joseph Marikle Mar 04 '13 at 15:05
  • Sorry fo the double comment, but I thought it might be useful to quick add my variation of your solution: http://jsfiddle.net/P8k58/. I used a few tricks to get it to work correctly and for my purposes I used a text shadow to finish off the effect. For the purpose of just creating a shine, however, this could easily be done with CSS content only (IE 8+ at best). – Joseph Marikle Mar 04 '13 at 15:39
  • @JosephMarikle Thanks. And I like your use of :before and :after . – Gus T Butt Oct 09 '13 at 11:09
0

Best solution at the moment is to use a solid color as non-webkit fallback and then use the following technique ( requires webkit ):

h1 {
  color: $333;
  font-size: 72px;
  background: -webkit-linear-gradient(#eee, #333);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
<h1>Example</h1>
sean2078
  • 5,131
  • 6
  • 32
  • 32
  • I already pointed out that it "requires webkit" .. Did you have a better solution? Works in FF, Chrome and Safari .. @user2602584 poor user – sean2078 Jan 11 '18 at 22:26
0

As I've already pointed out as a comment in zzzzBov's response, there is a way to achieve a text gradient in CSS3 only.

If you take the PNG solution a bit further, you can do the same trick with css3 gradients.

Of course this does only work for text that is on a uniform background color.

enyo
  • 16,269
  • 9
  • 56
  • 73