Gradient text
Fill text with a CSS gradient using background-clip, with adjustable colors and angle.
Color 1#6b46ff
Color 2#00e5ff
Angle90deg
<h1 class="grad-text">Gradient text</h1> :root {
--c1: #6b46ff;
--c2: #00e5ff;
--angle: 90deg;
}
.grad-text {
font-size: 52px;
font-weight: 800;
background: linear-gradient(var(--angle), var(--c1), var(--c2));
-webkit-background-clip: text;
background-clip: text;
-webkit-text-fill-color: transparent;
color: transparent;
} How it works
The text becomes a “window” onto a gradient:
- A
linear-gradientis set as the element’s background. background-clip: textclips that background to the shape of the glyphs.-webkit-text-fill-color: transparent(pluscolor: transparentas a fallback) makes the actual text color see-through, so the gradient shows through the letters.
Always include the -webkit- prefixes — Safari and Chromium still require them
for background-clip: text.