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).

0

1 Answer 1

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/

Sign up to request clarification or add additional context in comments.

3 Comments

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).
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?)
Why not to use modern linear-gradient syntax: background-image:-webkit-linear-gradient(#fff, #111);?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.