Files
30-seconds-of-code/snippets/gradient-text.md
2018-03-03 15:05:35 +10:00

1.1 KiB

Gradient text

Gives text a gradient color.

HTML

<p class="gradient-text">Gradient text</p>

CSS

.gradient-text {
  background: -webkit-linear-gradient(pink, red);
  -webkit-text-fill-color: transparent;
  -webkit-background-clip: text;
}

Demo

Gradient text

<style> .snippet-demo__gradient-text { background: -webkit-linear-gradient(pink, red); -webkit-text-fill-color: transparent; -webkit-background-clip: text; font-size: 2rem; font-weight: bold; margin: 0; } </style>

Explanation

  1. background: -webkit-linear-gradient(...) gives the text element a gradient background.
  2. webkit-text-fill-color: transparent fills the text with a transparent color.
  3. webkit-background-clip: text clips the background with the text, filling the text with the gradient background as the color.

Browser support

⚠️ Uses non-standard properties.