DEV Community

Paramanantham Harrison
Paramanantham Harrison

Posted on • Edited on • Originally published at learnwithparam.com

3

Gradient text style using CSS

Follow me on Twitter, happy to take your suggestions on topics or improvements

Gradient backgrounds started the trend, nowadays websites have more gradient colors for many elements after gradient become widely supported on modern browsers.

One such aspect is styling text with gradient color. Let see it in action

.gradient-text {
  // set the background color
  background: linear-gradient(to right, #ff8a00 0%, #da1b60 100%);
  // background color masked along the text and clip away the rest
  -webkit-background-clip: text;
  // make fill color to transparent so that masked background color will be shown
  -webkit-text-fill-color: transparent;
}
Enter fullscreen mode Exit fullscreen mode

Browser compatibility

  • This is only supported in WebKit based browsers. For other browsers, the color property can be the fallback option to render color related to the gradient color.
  • -webkit-text-fill-color is a non-standard CSS, so have fallback color property to support every browser without causing accessibility issues on non supported browsers.

Apart from IE, all major browser support this solution. Hope you learn a trick to show a text with gradient color on your site 😋

Note: This article was originally written for my blog. I am republishing it here for the amazing DEV community.

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay