Scramble Text
Letters near the pointer flicker into coloured symbols of similar width, then glide back into place.
Preview
Interfaces should feel like somebody made them.
Move your pointer across the letters.
Setup
Install with the shadcn CLI
One command adds every file, the npm packages and any Kinetik components it builds on. Needs a components.json; the CLI offers to create one if your project has none.
Or install manually
- 1
Run in your terminal:
$npm install clsx tailwind-merge - 2
Copy
lib/utils.tsfrom the Code tab. Skip if you already havecn(). - 3
Create a
components/ui/scramble-text/folder and copy every file from the Code tab into it. Each file does one job, so you can read or change a piece without the rest. - 4
Import and render:
Exampleimport { ScrambleText } from "@/components/ui/scramble-text" <ScrambleText as="h1" boot> Build beautiful interfaces. </ScrambleText>
No dependencies: it is plain React, DOM and a canvas for measuring.
Usage
Pass a string as children. Hovering scrambles the letters around the pointer.
import { ScrambleText } from "@/components/ui/scramble-text"
export function Hero() {
return (
<ScrambleText as="h1" boot className="text-6xl font-semibold">
Build beautiful interfaces.
</ScrambleText>
)
}Variants
variant picks what letters turn into:
symbols: coloured symbols picked by width; neighbours glide out of the wayemoji: emoji shrunk to fit each letter's box, so nothing around them movesdither: the real letter breaks up into a pixel dither pattern (a CSS mask) and fills back in to solid. The letter never changes, so nothing reflows
<ScrambleText variant="emoji">Hover me</ScrambleText>
<ScrambleText variant="dither" boot>Loading the future</ScrambleText>Boot reveal
Set boot to reveal the text on mount. Every letter shows up in reading order as a flickering
symbol, then settles on its real letter. The reveal starts fast and slows down, and it always
takes duration no matter how long the text is.
<ScrambleText as="h1" boot duration={1000}>Hello there.</ScrambleText>Line breaks
Each word is locked to the width of its real letters, so a scrambled symbol never pushes a word
onto another line and text-balance keeps the same layout. To fix the lines yourself, put a
newline in the text. It renders as a <br>.
<ScrambleText as="h1" className="whitespace-nowrap">
{"Most interfaces feel like\nnobody made them."}
</ScrambleText>How it works
- Each letter is its own box, rendered by React, so the server and client markup match
- Separate boxes lose the font's kerning, so each pair is measured on a canvas and the difference is put back as
margin-rightin em - A letter picks from the 5 symbols closest to its own width, and picks any symbol 1 time in 5
- When a box changes width, the boxes after it are pushed back to where they were, then glide home (FLIP)
- Each change waits a random 0–70 ms (0–150 ms when settling), so letters never change on the same frame
- Only the markup and measuring load with the page. The animation engine is a separate chunk, loaded on mount for
bootand otherwise when the browser is idle. With reduced motion it is never loaded
Files
index.tsx: the component; renders the letter boxes and lazy-loads the engineengine.ts: scramble, release, boot reveal and pointer zonesglide.ts: the FLIP glide loopmeasure.ts: kerning and width locks, measured on a canvasvariants.ts: the symbol, emoji and dither setsdither.ts: the Bayer dither maskstypes.ts: shared types
Props
| Prop | Type | Default | Notes |
|---|---|---|---|
children | string | — | The text. A newline is a fixed line break. |
as | ElementType | "span" | Element to render, e.g. h1 or p. |
variant | "symbols" | "emoji" | "dither" | "symbols" | What letters turn into. |
boot | boolean | false | Reveal the text with a scramble on mount. |
duration | number | 1000 | Length of the boot reveal in ms. |
colors | string[] | Palette / text colour | Symbol colours. Symbols default to a palette, dither to the text colour. Emoji ignore it. |
className | string | — | Applied to the root element. |
Accessibility
- Screen readers get one clean copy of the text; the letter boxes are hidden from them
- Copying the text selects it once, not letter by letter
- With reduced motion turned on, the text shows straight away and never scrambles
- Touch input does not scramble, so tapping a link stays readable