Scramble Hover
Text that scrambles into random glyphs on hover, then reveals the original word letter-by-letter — a small piece of editorial motion that earns a second look.
craft-bits
Customize
Animation
50ms
10
Behavior
Installation
npx shadcn@latest add https://craftbits.dev/r/scramble-hover.jsonUsage
import { ScrambleHover } from "@craft-bits/core";
<ScrambleHover text="hover me" />Understanding the component
- Two stacked spans. The outer wrapper renders an invisible
sr-onlycopy of the realtextso screen readers always announce the actual word. The visible copy isaria-hiddenso assistive tech skips it during the scramble. - Per-character spans. The visible copy splits
textinto individual<span>elements so each character can have its own class — eitherclassName(revealed) orscrambledClassName(still scrambling). - Reveal modes. Non-sequential (default) cycles every char for
maxIterationsframes then snaps. Sequential reveals one position at a time, starting fromrevealDirection. - Animation loop. A
requestAnimationFrameloop ticks everyscrambleSpeedms. Each tick re-randomizes still-scrambling chars. - Reduced motion. When
prefers-reduced-motion: reduceis set, the effect short-circuits — no hover handler, no animation frame.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
text | string | required | The final reveal text. |
scrambleSpeed | number | 50 | Milliseconds per scramble frame. |
maxIterations | number | 10 | Frames before reveal completes (non-sequential mode). |
sequential | boolean | false | Reveal letter-by-letter instead of all at once. |
revealDirection | 'start' | 'end' | 'center' | 'start' | Order chars reveal in sequential mode. |
useOriginalCharsOnly | boolean | false | Shuffle only the text's own characters. |
characters | string | glyph pool | Character pool to scramble from. |
className | string | — | Class for revealed text. |
scrambledClassName | string | — | Class for currently-scrambling characters. |
Accessibility
- Real
textlives inside.sr-onlyso screen readers announce the unscrambled word. - Scrambled characters use
aria-hidden="true". - Animation is fully disabled when
prefers-reduced-motion: reduceis set.
Credits
- Extracted from:
terminal-dreams(src/components/fancy/text/scramble-hover.tsx). - Inspiration: fancycomponents.dev — Scramble Hover.