Skip to main content

Text Scramble

The TextScramble component creates a captivating scramble animation effect where random characters rapidly cycle before resolving to the target text. Perfect for attention-grabbing headings, tech-themed interfaces, and dynamic content reveals.

Installation

Import

Usage

Props

string
required
The final text to display after the scramble animation completes.
number
default:"50"
Animation speed in milliseconds between character updates. Lower values = faster scrambling.
number
default:"3"
Total duration of the scramble animation in seconds.
boolean
default:"true"
Whether to trigger the animation. Set to false to show final text without animation.
string
Additional CSS classes. Component uses font-mono by default.
string
Custom set of characters to use during scrambling.
React.ElementType
default:"'span'"
HTML element type to render (span, div, h1, etc.).
() => void
Callback function fired when scramble animation completes.

Animation Details

Algorithm

The component uses a progressive reveal algorithm:
  1. Starts with all characters scrambled
  2. Progressively reveals characters from left to right
  3. Characters to the left of currentIndex are finalized
  4. Characters to the right continue scrambling
  5. Spaces are preserved throughout

Timing

The animation interval runs at the specified speed, incrementing the reveal index:
The animation automatically cleans up intervals on unmount to prevent memory leaks.

Examples

Hero Heading

Matrix-Style Effect

Sequential Reveals

Interactive Button

Loading State

Combine with monospace fonts (font-mono) for the most authentic terminal/hacker aesthetic.

Character Set Examples

Performance Considerations

  • Uses setInterval for character updates
  • Automatically cleans up on unmount
  • Minimal re-renders (only when scrambled text changes)
  • Lightweight algorithm with O(n) complexity
Using very low speed values (< 10ms) may cause performance issues on slower devices.

Use Cases

  • Tech/cyberpunk themed websites
  • Loading states with personality
  • Hero section headings
  • Terminal/CLI interfaces
  • Gaming UIs
  • Data visualization reveals
  • Countdown timers
  • Easter eggs and hidden messages

Accessibility

  • Final text is always readable
  • Screen readers will announce the final text
  • Animation can be disabled with trigger={false}
  • Consider reduced motion preferences for sensitive users