Text Reveal
One piece of copy and eight ways to reveal it, from a fade to a cloud of dots that settles into the type.
Nothing on this page is in a hurry. Each line waits for the one above it, then arrives on cue.
Three short lines sit in a quiet stage and arrive on cue. Use the chevrons under the copy to step through the eight patterns, or press the name in the middle to play the current one again. The stage plays once on its own the first time at least half of it is on screen.
The patterns, in order of how much machinery each one needs:
- fade: each line fades up, one beat after the line above.
- rise: each line rises out of its own box, tipped back on its foot so it lands rather than slides.
- wipe: a rounded rectangle on every line squeezes away to the left while the line slides in behind it.
- shutter: a bar draws across each word and leaves to the right, with a dark bar on the phrase a line ends on.
- focus: each word racks into focus from a blur, a little larger than it lands.
- decode: each character turns up as noise and settles on its letter.
- weight: a wave of weight runs through the copy on the variable weight axis.
- assemble: a cloud of dots settles into the letters, then the type fades in over them.
How it works
- A pattern is a function of one clock. Every pattern takes
t, in seconds, and writes styles straight to the nodes it is given. Nothing is kept between frames, so a pattern looks the same at any instant however it got there, and nothing renders per frame. - The copy is split once. Lines, words and characters are numbered in reading order, and React never touches the text a pattern rewrites.
resettakes every style off again, so switching patterns cannot leave one pattern's styles on another's frame. - Type is held still while it changes. The copy is set with kerning and ligatures off, so splitting a word into characters moves nothing. Patterns that change a glyph or a weight hold every character at its resting width, measured in ems, so the line does not shiver.
- The dots are sampled from the real type.
assembledraws the copy's own letters onto an offscreen canvas where each character sits in the DOM, reads it back on a grid, and flies the points in from a cloud. The handover to the type is a crossfade between two drawings of the same glyphs. - The noise is not random.
decodehashes the character and the frame, and the dots hash their own index, so a replay shows the same noise. - Reduced motion swaps every pattern for one calm reveal: the lines come up together in place, on opacity alone. Nothing travels, blurs, flickers or changes weight, and the picker steps out of the way, leaving a replay button.
The copy is read out once by assistive technology as plain text; the animated copy is hidden from it, since its letters are being rewritten.
Installation
Usage
import TextReveal from "@/components/ui/text-reveal";
<TextReveal />;The component draws its own stage, an 8:5 card that follows the theme and fills the width of its container. The copy takes its size from the stage, so keep each line short enough to sit on one row.
<TextReveal
defaultPattern="assemble"
lines={[
[{ text: "Make it" }, { text: "feel inevitable.", hl: true }],
[{ text: "Then let it" }, { text: "arrive.", hl: true }],
]}
className="aspect-video"
/>| Prop | Type | Default |
|---|---|---|
lines | { text: string; hl?: boolean }[][] | Three lines about patience |
defaultPattern | "fade" | "rise" | "wipe" | "shutter" | "focus" | "decode" | "weight" | "assemble" | "wipe" |
className | string | none |
A segment with hl is set darker, as the emphasis a line ends on. The weight pattern needs a variable font: it sweeps the weight axis from 100 to 860, so a face with fewer weights shows the nearest ones. The patterns and their timings are in patterns.ts, and the dots are in assemble.ts.