Skip to content
WANCRAFT

C.10Typography & Text

Text Scramble

Text that resolves through a flurry of random glyphs — without ever changing width.

ReactTailwindintermediate

Overview

Text Scramble cycles each character through a pool of glyphs before it settles, in a forward, centre-out or random order. Glyphs are written straight into the DOM from requestAnimationFrame, so React never re-renders per frame. Every character sits in a cell sized by its final glyph, which keeps the line perfectly stable in any font. It can run on hover or focus, on mount or when scrolled into view, and changing the text scrambles into the new phrase.

01Installation

Method 01 · Registry

CLI verified

Uses the shadcn CLI in a project initialised with shadcn init. Installs the file to components/ui/text-scramble.tsx and adds its dependencies.

npx shadcn@latest add https://wancraft.my/r/text-scramble.json

Method 02 · Copy and paste

  1. 1. No extra dependencies — React and Tailwind CSS only.
  2. 2. Copy the source from the Code tab into components/ui/text-scramble.tsx.
  3. 3. Import it and adjust props.
Dependencies
None
Peer
react ≥ 18, tailwindcss ≥ 4
Added
1 Oct 2026
Updated
—

02Usage

The default configuration. Change properties above to generate a tailored example in the Usage tab.

example.tsx
import { TextScramble } from "@/components/ui/text-scramble";

export function TextScrambleExample() {
  return (
    <TextScramble className="font-mono text-2xl uppercase" />
  );
}

03Props

PropTypeDefaultDescription
textstring"Signal acquired"Final text. Changing it scrambles from the current text into the new one.
as"span" | "p" | "h1" | "h2" | "h3" | "div""span"Element to render.
charactersstring"ABC…XYZ0123456789#%&*+/<>"Pool of glyphs shown while a character is unresolved.
durationnumber1000Time in ms until the last character settles.
intervalnumber45How often an unresolved glyph changes, in ms.
trigger"hover" | "view" | "mount""hover"What starts the scramble. Hover also responds to keyboard focus within the element.
order"forward" | "random" | "center""forward"Order in which characters settle.
accentstring"#FF7448"Colour of unresolved glyphs.
...propsHTMLAttributes—Native attributes are forwarded to the root element.

04Features

  • 01Zero layout shift: each glyph cell is sized by the final character
  • 02rAF loop writes textContent directly — no React state per frame
  • 03Forward, centre-out and random settle orders
  • 04Hover/focus, in-view and mount triggers; text changes scramble into the new phrase
  • 05Custom glyph pool and swap interval
motion · continuousmotion · staggerinput · hoverinput · focusinput · viewport

05Accessibility

  • The final text is always present as visually hidden text; the scrambling layer is aria-hidden.
  • Screen readers never hear random glyphs, and text changes are read as the final phrase.
  • With prefers-reduced-motion no scrambling happens — text updates instantly.

06Limitations

  • Characters are rendered as inline-block cells, so kerning and ligatures between letters are not applied.