shadcn.io is not affiliated with official shadcn/ui
Rolling Text turns each character over in place: its face rolls up and away while the same character rolls in from below, in perspective, one character after the next, so a wave of rolls runs along the line. It plays once when the page shows it, once when it scrolls into view, or every time the pointer comes over it.
Use it for a short label with a mechanical feel: a departures board, a status, a navigation link that rolls on hover. For words that take turns, use Flip Words; for numbers that roll to a new value, Sliding Number. Each character is the front face of a small cube turning on an axis behind the text, moved by two CSS keyframe animations the install adds to your stylesheet, delayed by the character's place in the line, with no animation library. With reduced motion the text stands still.
Installation
Usage
import { RollingText } from "@/components/ui/rolling-text";<h2>
<RollingText text="Now boarding" />
</h2>Demos
Hover
trigger="hover" rolls the text every time the pointer comes over it, and when the link or button around it gets keyboard focus, so a navigation link answers both. On a touch screen it simply shows the text.
Direction
direction is which way the characters turn: up, the default, rolls each face up and away with the next one coming from below; down rolls them the other way.
Timing
duration is how long one character takes to roll over, 600 ms by default, and stagger the time between one character and the next, 50 ms. A short pair suits a small label; a long one makes a slow wave across a title. trigger="view" waits until the text scrolls into view.
Accessibility
Screen readers read the text once, as plain text, from a visually hidden copy: the rolling characters are hidden from them. Words wrap whole, and the line keeps its direction on a right-to-left page. With reduced motion nothing rolls, on any trigger.
FAQ
How does the roll work?
Each character has two faces: the one you see, and a copy turned a quarter turn below it. Both turn together about an axis half a line behind the text, like a cube, so the face you see rolls up and away as the copy rolls in. The parent's perspective gives it depth.
How do I make a link roll on hover?
Put it inside the link with trigger="hover": <a href="/pricing"><RollingText text="Pricing" trigger="hover" /></a>. It rolls when the pointer is over the text, and when the link is focused from the keyboard.
Can it play again?
With trigger="hover", on every hover. With the other triggers it plays once; give it a new key and React renders it fresh, so it plays again from the start.
Can it roll to a different word?
No: each character rolls back to itself, for the motion. To change the words, use Flip Words or Rotating Text.
API Reference
RollingText
<span> data-slot="rolling-text"
textstring
The text.
direction?"up" | "down"
Which way each character rolls: its face turns up and away, or down. @default "up".
- Type
"up" | "down"- Default
"up"
duration?number
How long one character takes to roll over, in milliseconds. @default 600.
stagger?number
The time between one character rolling and the next, in milliseconds. @default 50.
trigger?"mount" | "view" | "hover"
What rolls it: the page showing it, the text scrolling into view, or the pointer over it (again on every hover, and on keyboard focus of the link or button around it).
- Type
"mount" | "view" | "hover"- Default
"mount"
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-view?string
"in" when visible is true, otherwise "out".
--rolling-text-durationstring
One character's roll (600ms).
--rolling-text-staggerstring
The time between one character rolling and the next (50ms).
--rolling-text-turnstringRelated
Flip Words
CyclingWhole words that take turns
Sliding Number
NumbersDigits that roll to a new value
Rotating Text
CyclingWords that roll through like a reel
- Pro
Paper Fold Text
EntranceLetters that unfold like a flap board
- Pro
Caps Toggle Text
CyclingA change of case on hover
- Pro
Shuffle
DecodeLetters that slide sideways into place