shadcn.io is not affiliated with official shadcn/ui
Gradient Text fills a word with colour that keeps moving: a gradient flows through the letters and loops without a seam, since it mirrors its colours back to where it started. A soft glow of the same colours can sit behind it.
Use it for one word in a headline or a short label, not a paragraph: the eye goes to it first. For light that sweeps across the letters instead, use Shimmering Text; for metal, Chrome Text. It's CSS only: the gradient is clipped to the letters and moved by a keyframe animation the install adds to your stylesheet, with no animation library. With reduced motion the gradient holds still.
Installation
Usage
import { GradientText } from "@/components/ui/gradient-text";<h2>
Ship it <GradientText text="beautifully" />
</h2>Demos
Colors
colors takes any CSS colours, start to end, including your theme's variables such as var(--primary). The gradient runs through them and back, so the loop has no seam whatever you pass.
Glow
glow adds a blurred copy of the gradient behind the letters, moving with it, for a word on a dark hero.
Duration
duration is one pass of the gradient through the text, 3000 ms by default; animate={false} holds it still, for a gradient that never moves.
Accessibility
The text stays real text, read by screen readers and selectable; the glow is a decorative copy they skip. In forced-colors mode, where backgrounds are removed, the text falls back to the system's text colour so it never disappears. Check the contrast of your lightest colour against the page.
FAQ
Why is there no jump when the gradient loops?
The gradient runs through your colours and back, so its end is its start, and it's twice the text's width: the animation slides it exactly one width and starts over where it began.
Can it follow my theme?
Yes. Pass theme variables in colors, such as ["var(--primary)", "var(--foreground)"], and the text follows the theme, light and dark.
Does a constant animation cost much?
Little. It moves the background inside the letters, with no JavaScript and no layout; keep it to a word or a short line rather than a paragraph.
Which way does it flow?
The way the text reads: left to right in English, right to left in Arabic or Hebrew, whatever the page's direction.
API Reference
GradientText
<span> data-slot="gradient-text"
textstring
The text.
animate?boolean
Whether the gradient keeps flowing; false holds it still. @default true.
- Default
true
colors?string[]
The colours the text runs through, any CSS colours, start to end; the gradient mirrors them so the loop has no seam. By default blue, purple and pink.
- Default
DEFAULT_COLORS
duration?number
One pass of the gradient through the text, in milliseconds.
- Default
3000
glow?boolean
A soft glow of the same colours behind the text. @default false.
- Default
false
render?ReactElement | ((props: object, state: object) => ReactElement)
Replace the host element or compose it with another component.
- Type
ReactElement | ((props: object, state: object) => ReactElement)
className?string
Merged with the part's classes.
--gradient-text-durationstring
One pass of the gradient (3s).
Related
Shimmering Text
DecorativeLight that sweeps across instead
- Pro
Chrome Text
DecorativeMetal with a reflection and a band
- Pro
Rainbow Text
DecorativeThe whole colour wheel, rolling
- Pro
Colourful Text
DecorativeEach letter in a colour of its own
- Pro
Neon Text
DecorativeA glowing tube on a dark surface
- Pro
Outline Text
DecorativeHollow letters that flood with colour