Back to Blog
CSS Techniques
7 min read

CSS Gradient Text Effects: A Complete Guide

Gradient text has become a staple of modern web design. Learn how to create vibrant, eye-catching text effects using pure CSS -- from basic background-clip techniques to animated and interactive gradient text.

How Gradient Text Works

CSS does not have a native "gradient text color" property. Instead, gradient text is achieved through a clever combination of three properties: you apply a gradient as the element's background, clip that background to the text shape using background-clip: text, and then make the actual text color transparent so the gradient shows through. This technique is well-supported in all modern browsers and has become the standard approach for gradient typography on the web.

The result is text that appears to be filled with a gradient, and since it is still real text in the DOM, it remains selectable, accessible to screen readers, and responsive. Let's start with the fundamental pattern and then build on it.

Basic Gradient Text with background-clip

The core technique requires exactly three CSS declarations. The background property defines the gradient, background-clip: text clips it to the text shape, and color: transparent reveals the gradient beneath. Here is the simplest possible example:

.gradient-text {
  background: linear-gradient(90deg, #ff6b6b, #4ecdc4);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}

The -webkit-background-clip and -webkit-text-fill-color prefixes are still needed for Safari and some older Chromium versions. Always include both the prefixed and unprefixed versions for maximum compatibility.

You can use any gradient type here -- linear, radial, or conic. The gradient direction and color stops control how the colors flow across your text. For horizontal text, a 90deg or to right angle tends to look best, but diagonal gradients at 135deg can add a dynamic feel to headings.

Radial Gradient Text

Radial gradients can produce a spotlight or glowing effect on text, where the center of the text appears brighter and the edges fade to a different color:

.radial-gradient-text {
  background: radial-gradient(circle at 50% 50%, #ffd700, #ff6348);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}

The gold-to-red radial gradient creates a warm, glowing effect that works well on dark backgrounds. Adjust the center position with the at keyword to shift the focal point.

Animated Gradient Text

Static gradient text is already eye-catching, but animated gradients take it further. The trick is to create a background larger than the text area and then animate its position using background-position. Since you cannot directly animate gradient color stops with CSS transitions, moving the background position is the most performant approach.

.animated-gradient-text {
  background: linear-gradient(
    270deg,
    #ff6b6b,
    #feca57,
    #48dbfb,
    #ff9ff3,
    #ff6b6b
  );
  background-size: 300% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
  animation: gradient-shift 4s ease infinite;
}

@keyframes gradient-shift {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

The gradient is set to 300% width so it extends well beyond the visible area. The animation then slides it back and forth, creating a smooth, continuous color shift. Repeating the first color at the end ensures a seamless loop.

Keep the animation subtle for production use. A slow, gentle shift (4-8 seconds) looks polished, while fast animations can feel distracting and reduce readability. Also consider adding prefers-reduced-motion support to pause animations for users who have motion sensitivity:

@media (prefers-reduced-motion: reduce) {
  .animated-gradient-text {
    animation: none;
    background-size: 100% 100%;
  }
}

Multi-Line Gradient Text

Gradient text on multi-line blocks introduces a subtlety that catches many developers off guard. By default, the gradient is applied relative to the element's bounding box, not to each individual line. This means a top-to-bottom gradient will spread across the entire height of the paragraph, potentially causing the first line and last line to appear as completely different solid colors instead of each line showing the full gradient range.

There are two common approaches to handling this:

Approach 1: Use a Horizontal Gradient

The simplest fix is to use a left-to-right gradient (90deg). Since horizontal gradients apply across the width of each line independently, every line of text shows the full color range regardless of how many lines there are:

.multiline-gradient {
  background: linear-gradient(90deg, #667eea, #764ba2);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}

Approach 2: Set display: inline

If you need a vertical gradient on multi-line text, wrapping the text in an inline-level element (or setting the element to display: inline) causes the background to be painted per line fragment rather than across the full block. This creates a more consistent gradient appearance per line, though the exact rendering can vary between browsers. A box-decoration-break: clone declaration helps normalize behavior:

.multiline-vertical-gradient {
  display: inline;
  background: linear-gradient(180deg, #f093fb, #f5576c);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}

Gradient Text with Hover Effects

Interactive gradient text adds polish to navigation links, call-to-action headings, and feature highlights. The key challenge is that you cannot transition background-image directly in CSS. Instead, you can animate the background position, size, or swap between a solid color and a gradient using a clever technique.

Position-Shift Hover

This approach uses an oversized gradient and shifts its position on hover, creating a color-change effect:

.gradient-text-hover {
  background: linear-gradient(
    90deg,
    #00d2ff 0%,
    #3a7bd5 50%,
    #00d2ff 100%
  );
  background-size: 200% auto;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
  transition: background-position 0.4s ease;
}

.gradient-text-hover:hover {
  background-position: right center;
}

The gradient is twice the element's width. On hover, the background position shifts to reveal the other half, creating a smooth color-shifting effect without needing keyframe animations.

Solid-to-Gradient Reveal

For text that starts as a solid color and reveals a gradient on hover, use the gradient as the background from the start but transition the background size from zero to full:

.reveal-gradient {
  position: relative;
  color: #ffffff;
  transition: color 0.3s ease;
}

.reveal-gradient:hover {
  background: linear-gradient(90deg, #f7971e, #ffd200);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}

Note that this approach doesn't animate smoothly because background-clip is not an animatable property. For a smoother transition, consider layering two elements (one solid, one gradient) and transitioning their opacity.

Advanced: Gradient Text with Text Stroke

Combining gradient text with -webkit-text-stroke creates outlined text filled with a gradient. This bold typographic style works well for hero sections and decorative headings:

.gradient-stroke-text {
  font-size: 4rem;
  font-weight: 900;
  background: linear-gradient(135deg, #667eea, #764ba2);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  -webkit-text-stroke: 2px rgba(255, 255, 255, 0.3);
  color: transparent;
}

The semi-transparent white stroke adds a subtle outline that provides definition to the gradient text. Use this sparingly and with large font sizes -- thin strokes on small text can reduce readability.

Browser Compatibility

The background-clip: text property has excellent browser support. Chrome, Edge, Firefox, Safari, and Opera all support it in their current versions. However, there are a few things to be aware of:

  • Safari requires -webkit- prefix -- Always include both -webkit-background-clip: text and the unprefixed background-clip: text. Safari still relies on the prefixed version as of 2025.
  • Use -webkit-text-fill-color -- While color: transparent works in most browsers, -webkit-text-fill-color: transparent provides more reliable results in WebKit-based browsers and should be included alongside.
  • box-decoration-break has limited support -- The box-decoration-break: clone technique for multi-line text is not supported in all browsers. Always test multi-line gradient text across your target browsers.
  • Provide a fallback color -- Always set a solid fallback color before the gradient declarations. If background-clip: text is not supported, the text will at least remain readable.
.gradient-text-safe {
  /* Fallback for unsupported browsers */
  color: #667eea;

  /* Gradient text for modern browsers */
  @supports (-webkit-background-clip: text) or (background-clip: text) {
    background: linear-gradient(90deg, #667eea, #764ba2);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: transparent;
  }
}

Performance and Accessibility Tips

  • Use gradient text on headings, not body copy -- Gradient text reduces readability at small sizes. Reserve it for large headings, hero text, and decorative elements where the visual impact justifies any legibility trade-off.
  • Ensure sufficient contrast -- Both ends of your gradient must meet WCAG contrast requirements against the background. A gradient from light yellow to light cyan on a white background would fail accessibility checks even if part of it passes.
  • Avoid heavy animations on mobile -- Animated gradients with large background sizes can cause jank on low-powered devices. Use prefers-reduced-motion to disable animation for users who request it.
  • Test text selection -- Gradient text remains selectable, but selected text can look odd in some browsers. Verify that the selection highlight is usable in your design.
  • Screen readers work normally -- Since gradient text is still real text in the DOM, screen readers read it without issues. No extra ARIA attributes are needed.

Design Your Gradient Visually

Choosing the right gradient colors for text requires experimentation. Try our Gradient Studio to design your gradient visually -- adjust colors, angles, and stops in real time, then copy the CSS directly into your project. The tool supports linear, radial, and conic gradients with full color stop control and transparency.

When designing gradients for text, stick to two or three colors for the best readability. High-contrast color pairs like blue-to-purple, pink-to-orange, or cyan-to-green tend to produce the most visually striking results. Test your chosen gradient at the actual font size and weight you plan to use, since thin fonts may not showcase the gradient as effectively as bold weights.