shadcn.io is not affiliated with official shadcn/ui
Rainbow Text fills a word with the whole colour wheel: one continuous ribbon of hues that rolls slowly through the letters, in the reading direction, and loops without a seam. Every hue has the same lightness, so none jumps out, and the colours lighten on a dark page so the word reads in either theme.
Use it for a playful word: a celebration, a launch, a "new" label, a pride banner. For your own brand's colours, use Gradient Text; for letters that each take a colour and swap it now and then, Colourful Text; for a rainbow that turns under the pointer, Foil Text. It's CSS only: the rainbow 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 rainbow holds still.
Installation
Usage
import { RainbowText } from "@/components/ui/rainbow-text";<h2>
Made for <RainbowText text="everyone" />
</h2>Demos
Intensity
intensity is how saturated the colours are: subtle for a pastel rainbow, medium by default, strong for a vivid one. Their lightness stays the same, so the text is as readable at every intensity.
Duration
duration is one full turn of the colour wheel through the text, 8000 ms by default: slow enough to read the word while it moves. animate={false} holds the rainbow still.
Accessibility
The text stays real text, read by screen readers and selectable. Each hue has the same lightness, darker on a light page and lighter on a dark one, so the contrast holds across the whole word; in forced-colors mode, where backgrounds are removed, the text falls back to the system's text colour. With reduced motion the colours stay where they are.
FAQ
How is it different from Gradient Text?
Gradient Text runs through the colours you give it and back. Rainbow Text always runs through the whole colour wheel, at one lightness, so every hue is as readable as the next; you choose how vivid it is, not which colours.
Why is there no jump when the rainbow loops?
The rainbow ends on the hue it starts with and is twice the text's width: the animation slides it exactly one width, so the last frame matches the first.
Does it work in light and dark mode?
Yes. The colours are darker on a light page and lighter in dark mode, set by --rainbow-text-lightness; set it yourself for a page with its own background.
Which way does it roll?
In the reading direction: left to right, or right to left on a right-to-left page.
API Reference
RainbowText
<span> data-slot="rainbow-text"
textstring
The text.
animate?boolean
Whether the rainbow keeps rolling; false holds it still. @default true.
- Default
true
duration?number
One full turn of the colour wheel through the text, in milliseconds.
- Default
8000
intensity?"subtle" | "medium" | "strong"
How saturated the colours are: subtle for a pastel rainbow, medium,
or strong for a vivid one.
- Type
"subtle" | "medium" | "strong"- Default
"medium"
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.
--rainbow-text-durationstring
One turn of the colour wheel (8s).
--rainbow-text-lightnessstring
The colours' oklch lightness (0.62, 0.8 in dark mode).
Related
Gradient Text
DecorativeYour own brand's colours instead
- Pro
Colourful Text
DecorativeEach letter takes a colour and swaps
- Pro
Foil Text
DecorativeA rainbow that turns under the pointer
Shimmering Text
DecorativeA band of light instead of hues
- Pro
Chromatic Text
DecorativeColour split at the edges
- Pro
Wave Text
MotionLetters that ride a playful wave