shadcn.io is not affiliated with official shadcn/ui
Rotating Text rolls one word of a sentence through its options like the reel of a slot machine: each letter of the outgoing word rolls up out of sight while the same letter of the next one rolls in behind it, one letter after the other, so a ripple runs along the word. The window fades out at its top and bottom edges, so the letters turn over a drum rather than drop off a cliff. It holds the width of its widest word, and it pauses while the pointer is over it.
Use it for the word of a headline that cycles: who a product is for, where it runs, what it does. For words that lift away and blur instead, use Flip Words; to grow a box around each word, Container Text Flip; to type them out, Typing Text. A small timer counts the turns and CSS keyframe animations the install adds to your stylesheet roll the letters, with no animation library; with reduced motion the words swap in place.
Installation
Usage
import { RotatingText } from "@/components/ui/rotating-text";<h2>
Made for <RotatingText texts={["designers", "developers", "everyone"]} />
</h2>Demos
Direction
direction="down" rolls the reel the other way: the next word drops in from above and the last one falls out below, like a departures board.
Stagger
stagger is the time between one letter rolling and the next, 30 ms by default. 0 rolls the whole word at once; a longer one sends a slow ripple along it, so give it a longer duration too (how long each word stays, 2500 ms by default).
Accessibility
Screen readers read every word once, as a list (designers, developers, everyone), from a visually hidden copy; the rolling letters are hidden from them, so they never hear a word change mid-sentence. The words stop while the pointer is over them, for anyone reading slowly, and with reduced motion they swap without moving.
FAQ
How is it different from Flip Words?
Both swap one word for the next, letter by letter. Rotating Text moves them like a reel, straight up through a window, the old and new letters turning over together; Flip Words lifts the old word away, growing and blurring, and raises the new one out of a blur.
Why is there space after a short word?
Rotating Text holds the width of its widest word so the sentence never jumps as the words change. In centred text the space is shared on both sides; keep the words close in length for the tightest fit.
Does it work with tight line heights?
Yes. The window reaches a little above and below the line, with margins that give the room back, so tall letters and descenders show whole even in a heading set with leading-none, and the lines around it don't move.
How do I colour the rolling word?
Give it a className, such as text-primary font-semibold: the class applies to every word, and the rest of the sentence keeps its own style.
Does it pause?
Yes, while the pointer is over it, and it waits a full duration again once the pointer leaves. With a single word it never rolls.
API Reference
RotatingText
<span> data-slot="rotating-text"
textsstring[]
The texts, shown in turn from the first; a text may be a few words.
direction?"up" | "down"
Which way the texts roll: up, the next rising from below, or down. @default "up".
- Type
"up" | "down"- Default
"up"
duration?number
How long each text stays, in milliseconds. @default 2500.
- Default
2500
stagger?number
The time between one letter rolling and the next, in milliseconds; 0
rolls the whole text at once.
- Default
30
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.
data-turn?string--rotating-text-staggerstring
The time between one letter rolling and the next (30ms).
Related
Flip Words
CyclingWords that lift away and blur
- Pro
Container Text Flip
CyclingGrow a box around each word
- Pro
Typing Text
EntranceType the words out instead
- Pro
Rolling Text
CyclingLetters that roll over in place
- Pro
Morph Text
CyclingWords that melt into each other
- Pro
Shuffle
DecodeLetters that spin through a reel once