Cómo funciona
Each character is an inline box sized by its final glyph. While it churns, the final glyph turns transparent and a random one is centred over it in a lighter accent colour, so the line never reflows and the eye reads it as working. Settle times follow the reading order with a seeded jitter, so the text resolves as a soft wave and the same way every time; settling is a hard cut, crisp like a split-flap board. Glyphs change every 45ms rather than every frame, which reads as deliberate instead of noisy.
Úsalo para
- Short headings or labels in technical, security or launch contexts.
- Links and menu items that should react to hover with character.
Busca otra opción cuando
- Body text or anything longer than a line or two.
- Long passages in Chinese or Japanese: wide characters churn through narrow glyphs, so keep it to short headings there.
Uso
import { useState } from 'react'
import { ScrambleText } from './ScrambleText.jsx'
export function ReleaseHeading() {
return <h2><ScrambleText text="Faster builds, fewer surprises" trigger="view" /></h2>
}
// Drive it from a parent, such as a whole link row
export function LinkRow({ label }) {
const [play, setPlay] = useState(0)
return (
<a href="/changelog" onPointerEnter={() => setPlay((p) => p + 1)} onFocus={() => setPlay((p) => p + 1)}>
<ScrambleText text={label} trigger="none" play={play} />
</a>
)
}Propiedades
| Propiedad | Tipo | Por defecto | Qué hace |
|---|---|---|---|
text | string | — | Final text. |
trigger | 'view' | 'hover' | 'mount' | 'none' | 'view' | When it scrambles: entering the view (once), pointer enter or focus inside, on mount, or only through play. |
play | any | — | Any change replays it, such as a counter. |
duration | number | 900 | Time until the last character settles, in ms. |
charset | 'letters' | 'symbols' | 'digits' | 'binary' | string | 'letters' | Glyphs to churn through, or your own string. |
tick | number | 45 | Milliseconds between glyph changes. |
as | ElementType | 'span' | Element to render. |
Accesibilidad
- The final text sits in a visually hidden span, so screen readers read it once and never hear the random glyphs; the animated characters are aria-hidden.
- Hover triggers also fire on focus inside, so keyboard users get the same effect.
- The animation is short (under a second by default) and does not repeat on its own.
- Reduced motion skips the scramble entirely; the final text is always shown.
Movimiento
Glyphs change every 45ms; characters settle over the duration (900ms by default), 70% by position and 30% by a seeded jitter.
Añádelo a tu proyecto
Los miembros Pro copian un prompt y su agente de programación instala el código, igual que con los gratuitos.
ScrambleText.jsxscramble-text.csstokens.cssREADME.md
Los dos archivos se instalan juntos. La hoja de estilos lee las variables de tokens.css y lleva valores de reserva, así que también funciona sola.



