Gradient Text | CSS-Tricks (original) (raw)

Psst! Create a DigitalOcean account and get $200 in free credit for cloud-based hosting and services.

Comments

  1. Looks very nice. Will do magic with Logos (though it’s only webkit xD)
    • so This method has the one disadvantage/ text-shadow is not compatible with these properties
    • Jake Crawford (Harrisburg, PA)
      Render text twice, absolute position second text to be over top of one another. then give bottom one text-shadow. Done.
    • Nice, Jake! I tried that. Works like a charm! Highfive!
    • This worked for me using
      text-shadow: 4px 4px 4px black;
    • I got mine to work just fine with text-shadow (snippet below):
      {
      text-shadow: -1px 2px rgba(128, 128, 128, 0.5);
      background: -webkit-linear-gradient(whitesmoke, #1e2425);
      background-clip: text;
      -webkit-text-fill-color: transparent;
      }
    • Great fix, how do I keep the background color black? I am using this on a modal and when I -webkit-text-fill-color: transparent; then my black background disappears…
    • I don’t understand how to add an underline transition with background simultaneously with this.
  2. Woah! That’s awesome and thanks for the post! I can use something for my website.
    • Hahah, who else is in love with the new website look
  3. Tried it, and I just got black text with something that looks like it has a text-shadow of 0px -1px 1px #FFF?
    That’s really un-neat, but thats what it looks like! Did I make a mistake? I used the exact code!
  4. The example won’t show as i expected?
    I only looks like a plain header.
    Help anyone?
  5. Hmm, it’s not working if you applied with text-shadow. There gotta be another way. By the way, the “Reference URL” no longer worked.
    • that solution requires either knowing the text in advance for your :after rule, so it won’t work with dynamic output from a CMS, or duplicating your content in adjacent spans. Assuming that you are putting your pretty gradients on your site’s keywords, the duplicate span idea = duplicate content seen by search engines which is not-so-great for SEO.
      text gradients fall firmly into the “nice to have”, I’m glad that i have something pretty to show a client in chrome/safari and the fallback of plain text in other browsers is totally acceptable.
    • I was doing some internet browsing and came across this thread.
      David, you could work around the :after issue in CMSs if you go content: attr(title);. This would work with data attributes as well in case your title attribute is already “taken”.
      Cheers!
    • That’s awesome Aaron and Marvintus. Thanks.
    • Hahaha nothing is ie(8) compatible
  6. Sure it doesn’t work with ie. But I would still use it and apply conditional statements… I’m sure most of you do this.
  7. Dead link. “Reference URL”
    • Thanks, I’ll just remove it, the demo is enough anyway.
  8. thanks for the post!
    awesome as always! :)
  9. Doesn’t work with text-shadows in the same style :(
    I may just have to revert back to using PNGs.
  10. Salmonface – that’s using the :after method too. Dang. So for now, for text, it’s gradient OR shadow/stroke.
  11. Actually, we can use -webkit-text-stroke for now (our context is webkit only).
  12. It doesn’t work in Mozilla and Ie.
    How can i apply this effect in both are above browser?
  13. Woah! That’s awesome and thanks for the post! I can use something for my website.
  14. hi there!
    any way to add text-shadow to text with gradient? i tried to do that but shadow goes in front of text…
  1. Great technique but I’ve just tested this on a retina display iPad and the text looks blurry, especially when zoomed in – like it’s actually at bitmap image.
    I’ll keep playing to see if there’s a solution, unless someone can enlighten me?
  2. I’ve tested the page with the latest Google Chrome (version 19) and the text is completely invisible. Please advice is there another way to accomplish text gradient ?
  3. Looked fine until I added a white text-shadow, then it screwed up. I wish the people responsible for CSS and the browser guys would would just come together for once and fix this stuff… this is elementary page layout stuff since Pagemaker… it’s not rocket science!
  4. Any solutions to add text-shadow to text with gradient?
  5. Great post!
    My Firefox browser is having problems with showing the gradients – does anyone know if there a snippet for FF?
    Thanks! :)
    • Excellent. but works only in chrome. not in firefox.
  6. I wrote a simple SCSS mixin that incorporates this trick w/ a cool non-webkit fallback that mixes your 2 colors @ 50%.
    @mixin lineartextgradient($color1, color2,color2, color2,startPoint:left top, $endPoint:left bottom)
    {
    color: mix($color1, $color2);
    background: -webkit-gradient(linear, startPoint,startPoint, startPoint,endPoint, from($color1), to($color2));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    }
  1. As I mentioned to Alex, there is a way of adding a text-shadow-like effect using an absolutely positioned span inside the heading tag. Here is a working JSFiddle.

    Cheers!
    • It also works in Edge, the new browser that comes with Windows 10, which is, apparently, webkit because you will need the vendor prefix, -webkit-.
  2. this doesn’t works for mozilla, only for the chrome and safari?? do u have any technique to show in mozilla also..
  3. Hi, Any idea for border gradient.
  4. I don’t know if someone already asked this, but is this gradient trick in mozilla? I replaced -webkit with -moz thinking it’d turn out the same, but the gradient appears to be a gradient box behind the letter rather than filling in the letter with the gradient.
  5. What about the cross browser compatibility
  6. It says right at the top: “WebKit only” – that means it does not work in Firefox or Safari, and definitely not in IE.
  7. This fails miserably on the native Android browser. The gradient shows up, but only as one big gradient block.
  8. Great Post !! Keep it Up !!
    But what about Mozilla & Opera…. Any Solution ??
  9. hmmmmmm nice !! but…waiting for all browsers support
    thanks for sharing :)
  10. It has vig problem if you add “text-shadow” property.
  11. Not working in IE10…others are far away
  12. Do u have any technique to show in mozilla also.. it works proper in chorme
  13. This is not “webkit only” now. “Opera” taken this prefix too, but don’t working…
  14. hi it works for me! But is it possible to do a horizontal gradient from here.
    Many thanks!
    Nub
  1. Good work… Keep goiing….
    Thanks
  2. h3{font-family: ‘Black Ops One’, cursive;
color:#999;  
margin-left:200px;  
position:relative;  
margin-top:10px;  
}  
h3 {  

font-size:50px;
background: -webkit-linear-gradient(#fff, #FC3,#FC3,#fff);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
} 41. showing only plain black text!!!!!!!!!!! 42. on chrome and opera is good, but on firefox is not effect :( 43. Plz find a solution for Mozilla text gradient. 44. only work in chrome even not work in mozila. 45. This works with edge, the browser that comes with Windows 10. Thanks!

  1. Cool to use in android browsers.
  2. its not supporting in Mozilla firefox.
    • You are just brilliant… works in both Chrome, Firefox and Safari
  3. hey! This is Only for Chrome….
  1. Hey guys!
    Just to give an update on Firefox here to the next readers..
    WOKING with FF 49.0.2 (on Mac?)..?!
    As I read Firefox gets more and more webkit standards. If IE also supports and gets more webkit – we’re good.
  1. Is there some workaround code so that it will look nice in webkit browsers but still appear as solid text in others? The letters are there in IE, but they aren’t visible unless you highlight them.
  2. It’s awesome! That’s what I was looking for.
    For old browser, like IE, we can use SVG
<svg class="text" xmlns="http://www.w3.org/2000/svg">  
  <linearGradient id="text" x1="50%" x2="50%" y1="10%" y2="100%">  
    <stop stop-color="#EEEEEE" stop-opacity="0" offset="0%" />  
    <stop stop-color="#333333" offset="100%" />  
  </linearGradient>  
  <text x="0" y="0.75em" fill="url(#text)">Example</text>  
</svg>  
.text {  
  width: 310px;  
  height: 72px;  
  font-size: 72px;  
}  
  1. Use this if this not working
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
  2. h1{
    text-transform: uppercase;
    background: linear-gradient(to right, #30CFD0 0%, #330867 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    font: {
    size: 20vw;
    };
    }
  3. Thanks for sharing, I have tried in Chrome 69 64 bit, It’s not at all working.
  4. I’ve created a library maybe 5-6 years ago, maybe come in handy ( at least for inspiration ) for someone, called Gradext.
    Animate gradients on text, linear, radial, horizontal, vertical! anyway.
  5. Nice, possible to make a diagonal gradient with that ?
  6. Nice, thanks!) Just found how to use gradient from side to side with text.
  7. It doesn’t work when “text-shadow” is applied. Text-shadow covers the colour.
  8. What would a fallback be for browsers that just show the text as transparent (Safari mobile)?
  1. This was really helpful! I ended up using it for a font awesome icon and it worked great!
  2. Will It work in IE11, I have tried nut no luck.
    If you can make it for IE11, can you let us know
  3. I wonder how this would be possible on a print medium. If I try to print it or create a pdf via macOS print in safari, It does not show the font text. I have to unset background, -webkit-background-clip and -webkit-text-fill-color to have default document font colors.
  4. man, how do i change the gradient direction using this method?
    Thanks
  1. Hey thanks! But how can we set the gradient horizontally?
  2. I’m using the same code
h3 {  
  background: -webkit-linear-gradient(135deg, #E20001, #ffce22);  
  -webkit-background-clip: text;  
  -webkit-text-fill-color: transparent;  
}  

but when I select the heading using a mouse, the texts disappear and only the blue highlight remains.