CSS Gradient Text with background-clip

Build linear, radial, and conic CSS gradients with a visual editor. Drag color stops, pick presets, and copy ready-to-use CSS, Tailwind, or custom property output.

CSS Gradient Text with background-clip

Gradient text is a masking technique rather than a special text feature. Setting background-image to any gradient function defines the fill, and background-clip: text restricts that fill to the text outlines rather than the full element box.1 Without background-clip: text, the gradient appears behind the text like any background; with it, the gradient shows through the letterforms only, treating each character as a mask.

The text color itself must be transparent to let the background show through. Omitting transparent leaves the text color painted over the gradient, hiding the effect entirely. This technique uses only stable CSS properties and requires no JavaScript. All major browsers have supported background-clip: text for several years, though the property still requires the -webkit- prefix in older WebKit contexts.

Copying a gradient from a design tool and applying it as text fill takes only the three CSS properties described below, making this one of the fastest visual upgrades you can add to a heading or product name. The CSS Gradient Builder on this page outputs the background-image value ready to paste into your stylesheet.

What this page covers

  • background-clip: text needs the -webkit- prefixed version too for older WebKit builds
  • background-size: 200% 100% required for the shimmer animation technique
  • Contrast check at both ends gradient text can pass WCAG at one end and fail at the other

Opens the CSS Gradient Builder with this page's checklist shown at the top of the tool.

Open in the tool →

The three-property pattern

Three properties produce gradient text: background-image sets the gradient, background-clip: text clips the gradient to letterforms, and color: transparent lets the background show through.1 Applying background-clip: text without color: transparent produces no visible change because the browser paints the text color over the background. Consequently, the order of properties in the stylesheet does not matter, but all three must be present.

Browser prefix handling

The -webkit-background-clip: text declaration is still required for broad WebKit compatibility. Modern build tools include it automatically via autoprefixer. If you hand-write the CSS, write both -webkit-background-clip: text and background-clip: text. Similarly, write both -webkit-text-fill-color: transparent and color: transparent to cover older Safari versions that do not honor the standard property name for text fill color. When you build a reusable heading component, keep the prefixed and standard declarations together so future edits do not accidentally remove one half of the masking pair.

Accessibility and inline element scope

background-clip: text has no inherent accessibility problem: screen readers read the text normally and the visual appearance does not affect announced content. However, gradients with insufficient contrast between the text color and the page background can fail WCAG contrast checks. The gradient stops may pass contrast at one end of a word and fail at the other. Test contrast across the full range of the gradient, not just at a midpoint.

Gradient text works on block and inline elements. Applying it to a span inside a paragraph scopes the gradient to that span's content box. Because the background starts at the element's origin, a short inline span clips only a portion of the gradient, which can produce unexpected color results when the span is near the end of a line. Building on this, prefer applying gradient text to heading elements with predictable widths rather than arbitrary inline spans. The background-image origin anchors to the element's content box, so a span that wraps only the last few words of a sentence shows only the tail end of the gradient rather than the full color range.

Contrast testing workflow

Check the lightest and darkest stops against the actual background, not a neutral placeholder. A heading on a dark hero may pass at the bright edge and fail at the dark edge, while a card label may do the opposite. If either extreme fails, narrow the lightness range, add a subtle text shadow, or place the heading on a solid panel, then adjust the gradient until both ends pass contrast before exporting the final value. Running a contrast check at every 10% position along the gradient catches failures that a single midpoint check misses, especially for gradients that pass through a wide lightness range from dark to bright.

Animating gradient text

Two practical approaches exist for animating gradient text, each with distinct trade-offs in browser support and visual quality. Choosing between them depends on whether you need to move the gradient across the letterforms or change the stop colors themselves. background-position animation shifts a wider gradient horizontally through the text mask and works in every modern browser without any custom property registration, while @property color interpolation enables direct stop color animation but requires Houdini API support in the browser.

Background-position animation

Background-position animation is the most performant method for animating gradient text. Set a background-size larger than the element, such as 200% 100%, and animate background-position with a CSS @keyframes rule. This slides the gradient across the letterforms without triggering layout or paint operations beyond the background layer, which keeps the animation smooth even on lower-powered devices.2 The technique works by painting a gradient wider than the element and then shifting which portion of the gradient is visible through the text mask, so the compositor handles the animation on the GPU without involving the main thread on each frame.

The technique works by painting a gradient wider than the element and then shifting which portion of the gradient is visible through the text mask. Because the browser only repositions an existing texture rather than repainting the gradient on each frame, the compositor can handle the animation on the GPU without involving the main thread. Consequently, background-position animation is the recommended starting point for gradient text animation unless you need to interpolate the stop colors themselves.

@property color interpolation

The @property approach offers more control. Registering a custom property as a color with @property allows direct color interpolation between gradient stops in a @keyframes rule.3 Without @property, the browser cannot interpolate between two background-image values and snaps between them at 50% of the transition. Furthermore, the @property method supports OKLCH color interpolation in the animation keyframes, enabling smooth hue travel around the OKLCH color wheel rather than the dull sRGB path through grey.

Reduced motion and static fallbacks

Both animation techniques are continuous motion, so they need a motion-aware fallback rather than an unconditional animation. The prefers-reduced-motion media query reports whether the user has asked the system to minimise non-essential animation, and the recommended pattern is to run the gradient animation only when that query does not match.4 Wrapping the animation assignment in @media (prefers-reduced-motion: no-preference) keeps the effect for everyone else while leaving the heading as static gradient text for users who opted out.

Why a static fallback is also the print fallback

Print stylesheets and forced-colors modes both flatten animated backgrounds, which means the heading can end up rendered as transparent text on an empty box, since color: transparent and background-clip: text together assume a painted background exists. A fallback that restores a solid color value under @media print keeps the heading legible in exported PDFs and screenshots, and the same rule doubles as the reduced-motion fallback. The practical structure is a base rule with transparent fill, an animation applied only inside a no-preference media query, and a print override that restores a solid text color.

Contrast carries over to the fallback

Whichever way the heading is rendered, the contrast requirement is the same: 4.5:1 for normal text and 3:1 for large-scale text, where large scale means at least 18pt or 14pt bold.5 Because the criterion measures contrast rather than hue, a gradient that looks vivid can still fail at its lighter end, so the same per-stop check that catches the animated version catches the static one.

When to use this

Use gradient text for hero headings, product names, and decorative labels where a single flat color is not enough. Avoid it on body text: the technique reduces legibility at small sizes and fails contrast checks on complex gradients.

Examples

Product name heading with brand gradient

Apply the three-property pattern to an h1 or h2. Use a two-stop gradient matching brand primary and secondary colors. Test contrast at both ends of the word on the actual page background color.

Animated gradient on a call-to-action label

Set background-size: 200% 100%, then animate background-position from 0% to 100% over 3 seconds with ease-in-out. This creates a shimmer effect that keeps the text readable throughout the cycle.

Gradient text inside a card component on a dark background

Dark backgrounds increase perceived contrast for gradient text. A blue-to-purple gradient at 0.7 lightness reads poorly on a white card but clearly on a dark surface. Adjust gradient stops for the actual background rather than assuming the gradient works on all surfaces.

Sources
  1. 1.

    Mozilla Developer Network, "background-clip," developer.mozilla.org, accessed June 2026. https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/background-clip

  2. 2.

    Agop Bashi, "Compositor-Only Property Optimization," css-animation.com, accessed June 2026. https://www.css-animation.com/performance-budgeting-gpu-architecture/compositor-only-property-optimization/

  3. 3.

    Mozilla Developer Network, "@property," developer.mozilla.org, accessed June 2026. https://developer.mozilla.org/en-US/docs/Web/CSS/@property

  4. 4.

    Florian Rivoal, Tab Atkins Jr., Daniel Libby, and Luke Warlow, "Media Queries Level 5," W3C Working Draft, June 29, 2026. https://drafts.csswg.org/mediaqueries-5/#prefers-reduced-motion

  5. 5.

    W3C, "Understanding Success Criterion 1.4.3: Contrast (Minimum)," w3.org, accessed June 2026. https://www.w3.org/WAI/WCAG22/Understanding/contrast-minimum.html

FAQ

The most common cause is a missing color: transparent declaration. background-clip: text clips the gradient to the text shape, but the text color still paints over it by default. CapyToolkit's gradient builder outputs the background-image value, but you still need to add the transparent text fill declarations in your stylesheet. Add color: transparent (and -webkit-text-fill-color: transparent for Safari compatibility) to reveal the gradient through the letterforms.

Modern browsers support the unprefixed background-clip: text. However, older WebKit builds require -webkit-background-clip: text. Including both declarations covers all practical targets. Autoprefixer adds the prefixed version automatically if you use a PostCSS build step.

Yes, on a span element. The gradient origin anchors to the element box, so the visible gradient colors depend on where the span falls within its gradient area. A span covering the middle portion of a long gradient shows only the middle colors. For predictable results, apply gradient text to block-level headings with known widths rather than short inline spans.

Set background-size: 200% 100% and animate background-position from left to right with a CSS @keyframes rule. For color interpolation in the animation, register a custom property with @property as type <color> and interpolate it in @keyframes. This requires Chromium 85+ or Safari 16.4+.

Possibly. WCAG contrast checks compare text color against background color at a single point. Gradient text varies in color across the word, so it may pass at one end and fail at the other. Run contrast checks at the lightest point of the gradient against the page background. If any position fails, increase the gradient lightness range or add a background color behind the element.

Additional resources

Guides

CSS Gradient Text with background-clip Apply a CSS gradient to text using background-image and background-clip: text. Browser support, fallback strategy, and live examples with the gradient builder. Animating CSS Gradients with @property Animate CSS gradient stops smoothly using @property custom properties. Browser support, fallback patterns, and OKLCH hue-rotation animations. CSS Mesh Gradient Technique Build mesh-style gradients in CSS using multiple layered radial-gradient() values on the same background-image. No SVG or canvas required. Tailwind CSS v4 Gradient Utilities Complete guide to Tailwind v4 gradient utilities. bg-linear-to-r, bg-radial, bg-conic, from-*, via-*, to-*, and in-oklch modifier reference. CSS Gradient Borders Apply CSS gradient borders using border-image or background-clip masking. Both techniques, browser support comparison, and border-radius workaround. OKLCH Interpolation in CSS Gradients Use OKLCH color space interpolation in CSS gradients with the in oklch modifier. How it eliminates grey midpoints and improves perceptual smoothness. CSS Gradients for Dark Mode UI Design CSS gradients for dark mode using reduced chroma, lower lightness stops, and prefers-color-scheme media queries. Practical patterns for UI surfaces. CSS Background Patterns with Gradients Build repeating CSS background patterns using gradient functions and background-size. Stripes, grids, dots, and diagonal tile techniques without images. Glassmorphism with CSS Gradients Implement the glassmorphism effect with CSS gradients, backdrop-filter blur, and translucent stops. Browser support and performance considerations. CSS Gradient Rendering Across Laptop and Phone Displays How CSS gradients render on the Dell XPS 16, iPhone 17 Pro, MacBook Air M4, MacBook Pro M4 and Galaxy S25: P3 color stops, OKLCH interpolation, OLED blacks and the browser engine each device runs.