Skip to documentation content

Text Scramble

Scramble text through random characters and resolve it left to right, on mount, on view, on hover, or on demand.

text-scramble-demo

Overview

Text Scramble cycles each character through random glyphs and settles them in reading order, the "decoding" effect used for status changes, build labels, and terminal-style navigation. Use it for short labels whose change is worth noticing. Avoid it on body text, where a reader would have to wait to read.

Every scrambling glyph is drawn over an invisible copy of its final character, so a random wide glyph such as W never pushes the line wider. The only change during a scramble is a pixel or two of lost kerning between characters, and settled text keeps its normal kerning. For a perfectly fixed width, use a monospaced font, which has no kerning. Spaces stay in place by default, so words keep their shape and long text still wraps between them.

Installation

npx honestui@latest add text-scramble

Usage

import { TextScramble } from "@/components/animated/text-scramble"

<TextScramble>Deployment complete</TextScramble>

Play it on hover or keyboard focus, for navigation links:

<a href="/settings">
  <TextScramble trigger="hover" characters="01#/<>_=">
    Settings
  </TextScramble>
</a>

Change children or replayKey to play it again, for example after a status update or a button press.

Accessibility

Assistive technology reads the final text from a visually hidden copy, and the scrambling characters are hidden from it. Screen readers never hear the random characters. The server and the first client render both show the final text, so the content is readable before JavaScript runs.

With reduced motion enabled, the text changes to its final value at once without scrambling.

API Reference

PropTypeDefaultDescription
children*string–Final text. Changing it scrambles into the new value.
asElementType"span"Element to render.
triggermount|view|hover"mount"When the scramble plays. hover also plays on keyboard focus.
replayKeyunknown–Plays the scramble again whenever this value changes.
durationnumber0.8Seconds until the last character resolves.
speednumber40Milliseconds between random-character swaps.
charactersstringA–Z, a–z, 0–9Characters drawn while scrambling.
scrambleSpacesbooleanfalseScrambles spaces too, hiding word gaps during the effect.
onComplete() => void–Called once the text has resolved.
classNamestring–Class for the root element.
scrambleClassNamestring–Class for characters that are still scrambling, such as a muted color.