Go to homepage

Projects /

November 24, 2020

Text Gradients

By CodyHouse
400 HTML, CSS, JS components. Download →

How to create text gradients in CSS.

To apply a gradient color to your text, first, you need to create a background gradient:

.text-gradient {
  /* color: linear-gradient(to right, darkblue, darkorchid); 👈 not working */
  background: linear-gradient(to right, darkblue, darkorchid);
}

then, you need to clip the background using the text as a clipping mask, and hide the text:

.text-gradient {
  background: linear-gradient(to right, darkblue, darkorchid);
  color: transparent;
  background-clip: text;
}

To progressively support all browsers:

.text-gradient {
  /* 👇 show a solid color in older browsers (e.g., IE11) */
  color: darkblue;
}

/* 👇 show the text gradient in modern browsers */
@supports (--css: variables) {
  .text-gradient {
    background: linear-gradient(to right, darkblue, darkorchid);
    color: transparent;
    -webkit-background-clip: text;
    background-clip: text;
  }
}

This technique allows you to apply gradients to single words or multiple text lines.

Here's an example:

Level up your CSS skills

Each month we email a 1-minute CSS tutorial to 20K developers

Awesome! We just sent you a confirmation link by email

Error - please try again or contact us

Your email address is already subscribed

Project duplicated

Project created

Globals imported

There was an error while trying to export your project. Please try again or contact us.