CSS guides

Put a gradient inside text and preserve a printable fill

·

The gradient covers a text element’s background, and text clipping reveals it only inside the glyphs. Keep a solid color available for environments that suppress backgrounds.

Text Gradient Generator

Apply the two-stop letter fill

Select Reset example. The text uses a 90-degree linear gradient from #B42318 at 0% to #1D4ED8 at 100%. The left side starts red and the right side ends blue. Change the sample phrase to see how the gradient spans the text box.

Download text-gradient.css and apply tm-gradient-text to a heading or inline span. The background is clipped to the text. Test the actual size and line breaks where you will place it.

Apply the two-stop letter fill
ControlWorked value
Angle90 degrees
First stop#B42318 at 0%
Last stop#1D4ED8 at 100%
Fallback color#263D73

W3C CSS Images Level 4, gradients and color interpolationW3C CSS Backgrounds Level 4, clipping the background

Verify the fallback in print or forced colors

The exported class starts with color #263D73. It sets the lettering to transparent only inside a feature query that checks both text clipping and the exact gradient syntax.

Open the browser’s print preview. The text returns to #263D73 with no gradient background. In forced-color mode the stylesheet uses the system text color.

W3C CSS Conditional Rules Level 3, feature queriesW3C CSS Color Adjustment Level 1, forced colors

Change the transition or the center

Add a stop at 50% to alter the center. For a hard edge, put two different stops at the same position. Use Center X and Center Y to move the center of a radial or conic gradient.

Stops interpolate in sRGB. A color such as #1D4ED880 includes alpha. Check translucent stops over the final background because the background affects their appearance.

W3C CSS Images Level 4, gradients and color interpolationW3C CSS Backgrounds Level 4, clipping the background

Common questions

Do the sample words appear in the downloaded stylesheet?

The CSS contains style values and a class. Apply that class to your own text.

Why does the radial preview look different on a wider title?

Its center is positioned relative to the element’s box, so different width or wrapping changes where color appears inside the glyphs.

Sources

Put it into practice.

Related guides