Colour · gradient recipeCSS gradient text — how to make it

The gradient is set as a background and clipped to the shape of the letters. Below are a live example, code with a fallback for older browsers and why the text sometimes disappears.

TextButtonBorderAnimation← Back to the builder
01Example02Code03Steps04Mistakes05Questions06Recipes07Related
01

Live example

change the colours — the code below follows
Colour shift
Recipe settings
Colours
#6C8CFF0%
#B18CFF100%
Open in the builder →
02

Ready code

with @supports — without support the text stays coloured
.gradient-text {
  display: inline-block;
  color: #6c8cff; /* fallback */
}

@supports (background-clip: text) or (-webkit-background-clip: text) {
  .gradient-text {
    background: linear-gradient(90deg, #6c8cff 0%, #b18cff 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
  }
}
03

Step by step

  1. 01
    background: linear-gradient(…)
    Set the gradient as the element’s background, as for any block.
  2. 02
    background-clip: text
    Clip the background to the outline of the letters. Safari needs the -webkit- prefix.
  3. 03
    -webkit-text-fill-color: transparent
    Make the letter fill transparent so the background shows through.
  4. 04
    @supports (…)
    Wrap the rule in a support check so older browsers keep a plain colour.
04

Common mistakes

The text vanished

The transparent fill is set but background-clip did not apply. Without @supports the text becomes invisible — always keep a fallback color.

Gradient spans the whole line

A block element’s background stretches across the full width, and the letters only get a slice of the transition. Use display: inline-block.

Selection is invisible

With a transparent fill the selection highlight can disappear. Set ::selection with an opaque colour.
05

Frequently asked

Safari long understood only the prefixed property, so the rule needs both lines: -webkit-background-clip: text and background-clip: text. The transparent letter fill also comes from the prefixed -webkit-text-fill-color: transparent, which every modern browser supports. Forget the prefix and Safari shows a gradient rectangle instead of letters, or transparent text with no background. The recipe code already has both forms, and the @supports check covers either.
06

Other recipes

Updated

«» added to favorites