shadcn.io is not affiliated with official shadcn/ui
Drift Text lets each letter float on its own: it bobs a little up and down and sways from side to side, slowly, at a pace of its own, so nothing lines up and the motion hardly ever repeats. The line stays readable throughout; it just never quite sits still.
Use it for calm, ambient copy: a hero line on a quiet page, a wellness app, a background caption. For letters that move together on a wave, use Wave Text; for the whole line breathing as one, Breathing Text. Each letter runs two CSS keyframe animations the install adds to your stylesheet, a bob and a sway, whose lengths and starting points come from a small formula of the letter's place, so the server and the browser draw the same thing. There's no animation library and nothing random. Pointed at, the letters hold still; with reduced motion they sit on the line.
Installation
Usage
import { DriftText } from "@/components/ui/drift-text";<h1>
<DriftText text="Let your mind wander" />
</h1>Demos
Intensity
intensity is how far each letter wanders and turns: subtle is barely there, medium, the default, a gentle float, strong a line adrift in the wind.
Duration
duration is how long a letter takes, on average, to bob and sway once, 5000 ms by default; each letter's own time is a little longer or shorter. A short one is restless, a long one sleepy.
Accessibility
Screen readers read the text once, as plain text, from a visually hidden copy; the drifting letters are hidden from them. Words wrap whole, and the line keeps its direction on a right-to-left page. The letters move by a few hundredths of their size, so the text stays readable at every moment. The motion never ends, so it holds still while the pointer is over it, or while a link around it has keyboard focus, and with reduced motion it doesn't move at all.
FAQ
How is it different from Wave Text?
Wave Text moves every letter on one shared wave, so the line looks coordinated, like a flag. Drift Text moves each letter on its own, at its own pace, so nothing lines up: it looks organic rather than wavy.
Does it ever visibly repeat?
Hardly. Each letter's bob and sway last different lengths of time, and differ from every other letter's, so the line as a whole takes a very long time to come back to where it started.
Is the motion random?
It looks random but isn't: each letter's pace and starting point come from a small formula of its place in the text, so the server and the browser agree and the page never mismatches.
Why does it stop when I point at it?
Motion that never ends can make text hard to read for some people, so the letters hold still while the pointer is over them, or while a link around the text has keyboard focus, and drift on again afterwards.
API Reference
DriftText
<span> data-slot="drift-text"
textstring
The text. Its line breaks (\n) are kept.
duration?number
How long a letter takes, on average, to bob and sway once, in milliseconds; each letter's own time is a little longer or shorter.
- Default
5000
intensity?"subtle" | "medium" | "strong"
How far each letter wanders and turns. @default "medium".
- Type
"subtle" | "medium" | "strong"
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
Forwarded to the part.
--drift-text-durationstring
A letter's average bob and sway (5s).
--drift-text-reachstring
How far a letter bobs up and down (0.045em).
--drift-text-turnstring
How far a letter sways either way (2deg).
Related
- Pro
Wave Text
MotionLetters that move together on a wave
- Pro
Breathe in, breathe out
Breathing Text
MotionThe whole line breathing as one
- Pro
Liquid Text
InteractiveLetters that sway and melt together
- Pro
Wobble Text
MotionLetters that rock like jelly
- Pro
Pendulum Text
InteractiveLetters that swing on strings
- Pro
Writing Text
EntranceA calm line, word by word