How to Create a CSS Text Gradient (Color Text Effect)
Gradient text with background-clip, current browser support from MDN's data, and the contrast check most tutorials skip: the classic coral-to-lavender demo gradient scores under 3:1 on white.
The Technique
.gradient-text { color: #A18CD1; } /* solid fallback */
@supports (background-clip: text) or (-webkit-background-clip: text) {
.gradient-text {
background: linear-gradient(135deg, #FF6B6B, #A18CD1);
-webkit-background-clip: text; /* Chromium before 120 */
background-clip: text;
color: transparent;
}
}
The gradient is painted as the element's background, background-clip: text trims it to the glyph shapes, and a transparent text color lets it show through. MDN's compatibility data lists unprefixed background-clip: text in Chrome and Edge 120, Safari 14 and Firefox 49, so the -webkit- line only matters for older Chromium. color: transparent works as well as -webkit-text-fill-color; both produced identical pixels in our test.
Contrast Is Checked Per Color, Not Per Gradient
Every part of the text has to be readable, so each gradient color must pass on the background behind it. For the usual demo gradient:
| Stop | On white | On #0B0D17 (dark) |
|---|---|---|
| #FF6B6B | 2.77:1 | 6.98:1 |
| #A18CD1 | 2.92:1 | 6.63:1 |
On white both stops fail even the 3:1 that WCAG 2.2 allows for large text (24px, or 18.66px bold); on a dark background both pass 4.5:1. Pastel gradients on light pages are the common failure. Pick stops that each pass, which on white usually means darker, more saturated colors.
High-Contrast Modes
A frequent worry is that transparent text vanishes in Windows high-contrast mode. We rendered the heading in Chromium with forced-colors: active emulated: the browser replaced the transparent color with the system text color and the heading kept the same amount of ink (6,755 vs 6,446 dark pixels in our screenshot test). To control the result instead of relying on the override, add:
@media (forced-colors: active) {
.gradient-text { background: none; color: CanvasText; }
}
Animated Gradients
Sliding background-position across a 200%-wide gradient creates a shimmer. It repaints the text every frame, so keep it to one short headline, stop it after a few cycles or on hover, and wrap it in @media (prefers-reduced-motion: no-preference).
Building One
The CSS Text Gradient previews linear, radial and conic gradient text with your own words and copies the CSS. Check each stop in the Contrast Checker against your real background before shipping.