The short version
- Tailwind gradient text needs a gradient background,
bg-clip-textto clip it to the letters, andtext-transparentso the background shows through. - In Tailwind v4 the gradient utility is
bg-linear-to-r, while v3 usesbg-gradient-to-r; the from, via and to colour classes work the same in both. - Tailwind v4 lets you choose the interpolation space with a modifier such as
bg-linear-to-r/oklch, which keeps the midpoint of a gradient bright. - Add
box-decoration-clonewhen a gradient heading wraps onto several lines, and a little bottom padding when descenders get cut off. - Check the contrast of the lightest colour in the gradient against the page, because that is where gradient text becomes hard to read.
On this page
To make Tailwind gradient text, put a gradient on the element and clip it to the letters: bg-linear-to-r from-violet-600 to-pink-500 bg-clip-text text-transparent. The first part paints a gradient background, bg-clip-text trims that background to the shape of the glyphs, and text-transparent removes the solid text colour so the gradient shows through. In Tailwind v3, write bg-gradient-to-r instead of bg-linear-to-r; the rest is identical.
<h1 class="bg-linear-to-r from-violet-600 to-pink-500 bg-clip-text text-5xl font-bold text-transparent">
Ship the quiet version
</h1>How the classes work together
It helps to know what each utility compiles to, because every bug with gradient text comes from one of the four parts going missing. Under the hood this is the same technique as plain CSS gradient text: background-clip: text with a transparent fill.
bg-linear-to-rWhat it sets
If you forget it
from-* via-* to-*What it sets
If you forget it
bg-clip-textWhat it sets
background-clip: textIf you forget it
text-transparentWhat it sets
color: transparentIf you forget it
Directions follow the usual suffixes: -to-r, -to-br, -to-b and so on. Version 4 also accepts an angle, such as bg-linear-45 or bg-linear-135, and adds bg-radial and bg-conic, which work for text too. If you have not used the gradient utilities much, Tailwind gradients covers backgrounds in depth.
Tailwind v4 and v3 class names
The biggest change in v4 is the name of the linear utility. bg-gradient-to-r became bg-linear-to-r, to sit alongside the new radial and conic utilities. The old name still compiles in v4 for compatibility, but new code should use the new one.
Tailwind v4
bg-linear-to-rTailwind v3
bg-gradient-to-rbg-linear-to-br or bg-linear-45Tailwind v3
bg-gradient-to-brbg-radialTailwind v3
bg-conicTailwind v3
Tailwind v4
bg-linear-to-r/oklchTailwind v3
Tailwind v4
bg-clip-textTailwind v3
bg-clip-textGradient text examples you can copy
Three or four colours that sit near each other on the wheel make the cleanest gradient text. Opposites look loud and can turn grey in the middle. These combinations use colours from the default palette, described in Tailwind colours.
from-*, a middle one in via-*, the last in to-*. The 600 shades keep enough contrast on a white page; on a dark page, swap to 300 or 400. The hex values are the v3 palette; v4's OKLCH versions look very close.Stop positions move where each colour sits. from-20% via-50% to-80% keeps solid colour at both ends of a long headline, which looks calmer than a blend that starts on the first letter.
<!-- Stop positions -->
<h2 class="bg-linear-to-r from-cyan-600 from-20% via-blue-600 via-50% to-violet-600 to-80% bg-clip-text text-transparent">
Plans for every team
</h2>
<!-- OKLCH interpolation keeps the middle bright -->
<h2 class="bg-linear-to-r/oklch from-blue-600 to-yellow-400 bg-clip-text text-transparent">
Brighter in the middle
</h2>
<!-- Arbitrary gradient, underscores stand in for spaces -->
<h2 class="bg-[linear-gradient(100deg,#1e1b4b_0%,#7c3aed_60%,#f472b6_100%)] bg-clip-text text-transparent">
Exactly your colours
</h2>Blue to yellow is a good test of interpolation. Blended in sRGB it passes through a greyish green; blended in OKLCH it stays vivid. CSS gradients in OKLCH explains why.
Fixing common gradient text problems
Multi-line headings
By default the gradient spans the whole element box, so a heading that wraps gets one stretched gradient with the second line in a different colour from the first. Add box-decoration-clone to give each line its own full gradient, or inline-block to shrink the box to the text.
Clipped descenders
Tight leading such as leading-none can slice the bottom off a g or y, because the background ends at the line box. Add pb-1 or loosen the leading slightly.
Dark mode
A gradient tuned for white paper looks muddy on a dark page. Give it its own shades with variants: from-violet-600 to-pink-600 dark:from-violet-300 dark:to-pink-300. The same thinking applies to backgrounds, covered in dark mode gradients.
Avoid
- Gradient text on long paragraphs
- A pale stop that vanishes on white
- Complementary colours with a grey middle
- Gradient text on top of a gradient background
- Leaving out a solid colour for selected text
Do
- Keep it for a headline or a single word
- Check the lightest stop against the page
- Neighbouring hues, or OKLCH interpolation
- Solid ground behind gradient words
- Set
selection:text-white selection:bg-violet-600
Animating Tailwind gradient text
A slow shimmer comes from a background twice as wide as the text that slides sideways. In v4, define the animation inside @theme and it becomes an animate-* utility.
@import "tailwindcss";
@theme {
--animate-shine: shine 6s linear infinite;
@keyframes shine {
to { background-position: 200% center; }
}
}bg-size-[200%_auto] animate-shine motion-reduce:animate-none to the heading, and repeat the first colour as the last stop so the loop has no jump.Use it once on a page at most. Motion pulls the eye, which is the point for a launch headline and a nuisance everywhere else. The pattern is the same one used in animated CSS gradients.
Keep gradient text readable
- 1
Find the weakest stop
The lightest colour on a light page, or the darkest on a dark page, sets the contrast you actually get.
- 2
Test it like body copy
Large bold headings need at least 3:1 against the page under WCAG. Colour contrast and accessibility has the full rules.
- 3
Use weight
Gradients read better in bold and heavy weights, where there is more fill to show the colour.
- 4
Stop at a few words
One headline or one emphasised word. Anything longer starts to look like a rendering error.
Gradient text is a web technique. When the job is a social post or a banner and you want the gradient behind the words instead, Gradiently Marks move their calmest area behind the text and pick light or dark ink per line, so the words read without you testing every stop.
Questions people ask
How do I make gradient text in Tailwind?
Add a gradient with bg-linear-to-r (or bg-gradient-to-r in v3), colour stops with from-* and to-*, then bg-clip-text and text-transparent.
Why is my Tailwind gradient text not showing?
Usually text-transparent is missing, so solid text covers the gradient, or bg-clip-text is missing, so the gradient fills a box behind the words. Check that all four parts are on the same element.
What replaced bg-gradient-to-r in Tailwind v4?
The linear utility is now bg-linear-to-r. The old name still works for compatibility, and v4 adds bg-radial, bg-conic and angle utilities such as bg-linear-45.
How do I stop gradient text cutting off letters like g and y?
Add a little bottom padding such as pb-1, or loosen the line height, because the clipped background ends at the line box.
Is gradient text accessible?
It can be, if every part of the gradient meets contrast requirements against the page. Test the lightest stop and keep gradient text to headings.
Written by Gradiently
The team behind Gradiently, a design tool built around Marks: living gradients that make everything you design look like yours.
See our profile