Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Text

Pro

Rainbow Text for React

Text filled with every hue of the colour wheel, rolling slowly through its letters. For React with Base UI, when a word should feel playful rather than branded.

Framework

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.

Preview width

Installation

Part of Pro
Pro unlocks the code and one-line install of every Pro button and text effect, plus the MCP for your AI editor.
Have Pro already? Sign in to open it.Opens here as soon as you're Pro.

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.

Preview width

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.

Preview width

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.

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: a paragraph of moving colour is hard to read.

What happens with reduced motion?

The rainbow stops where it is; the colours and the text stay.

API Reference

RainbowText

<span> data-slot="rainbow-text"

PropType
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.

CSS variableType
--rainbow-text-durationstring

One turn of the colour wheel (8s).

--rainbow-text-lightnessstring

The colours' oklch lightness (0.62, 0.8 in dark mode).

All 97 text effects