All effectsVisual styles

Gradient Text

渐变文字

Color changes across the letters while the area surrounding them stays transparent.

Look at the color across the letters

Where to use it

Accent a short headline, product name, or large metric. Keep both ends of the gradient readable at the chosen type size, and limit it to one part of the heading hierarchy.

Practical example

A solar-panel calculator colors its large annual generation estimate from deep teal to blue. The unit and assumptions sit in solid text beneath it, so visitors can read the number first and then check what it represents.

Also called

  • Text Gradient

AI prompt

Add Gradient Text to [target text] by clipping a restrained two-color gradient to the glyphs. Keep it as real text and set a readable solid color fallback. Check each end of the gradient on the actual background and preserve legibility in forced-colors mode.

Example code

Save the standalone HTML as a file and open it in your browser. It uses the same code as the preview.

View HTML
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Gradient Text</title>
  <style>
    :root {
      color-scheme: dark;
      --demo-bg: #171629;
      --demo-ink: #f8f5ff;
      --demo-accent: #b9a6ff;
      --demo-muted: #bfbbd3;
      font-family: system-ui, sans-serif;
      color: var(--demo-ink);
      background: var(--demo-bg);
    }

    *, *::before, *::after { box-sizing: border-box; }
    body { margin: 0; min-width: 0; }
    button, input { font: inherit; }

    .demo {
      display: grid;
      place-items: center;
      align-content: center;
      min-height: 100vh;
      padding: 14px;
      overflow: hidden;
      background: radial-gradient(ellipse at 50% 24%, #28233f, var(--demo-bg) 78%);
    }

    .demo-button {
      border: 1px solid #ffffff3d;
      border-radius: 7px;
      background: #ffffff12;
      color: var(--demo-ink);
      padding: 6px 11px;
      font-size: 12px;
      cursor: pointer;
    }

    :focus-visible {
      outline: 2px solid var(--demo-accent);
      outline-offset: 3px;
    }

    .gradient-sample {
      display: grid;
      place-items: center;
      width: min(100%, 280px);
      min-height: 108px;
      padding-inline: 12px;
      border: 1px solid #4f4368;
      border-radius: 16px;
      background: #251f36;
    }
    .gradient-letters {
      color: #c8b2ff;
      font-size: clamp(28px, 12vw, 44px);
      font-weight: 790;
      line-height: 1.2;
      letter-spacing: -0.035em;
    }
    @supports (background-clip: text) {
      .gradient-letters {
        background: linear-gradient(104deg, #a0f4db, #c9b2ff 55%, #ffb2c2);
        background-clip: text;
        color: transparent;
      }
    }
    @media (forced-colors: active) {
      .gradient-letters { color: CanvasText; }
    }
  </style>
</head>
<body>
  <main class="demo">
    <div class="gradient-sample">
      <span class="gradient-letters">Spectrum</span>
    </div>
  </main>
</body>
</html>

Original example by UI Skills