A text scramble effect cycles characters through random letters, numbers or symbols before each one settles on the final text, like a code being decoded.
In a text scramble, each character flickers through random glyphs for a moment and then locks onto its real letter, usually from left to right. It suits headlines, numbers that change, and “decoding” or privacy moments, such as a figure scrambling into dots when it is hidden.
Update the text on each animation frame: characters before the reveal point show their real letter, the rest show a random glyph from a small set. A monospaced font or tabular numerals keeps the width from jumping.
Keep the real text readable to assistive technology: put the final text in an aria-label and mark the animated characters aria-hidden, keep the effect short, and show the text directly under reduced motion.
function scramble(el, text, ms = 700) {
const glyphs = 'ABCDEFGHJKLMNPQRSTUVWXYZ0123456789#%&';
el.setAttribute('aria-label', text);
const start = performance.now();
const tick = (now) => {
const shown = Math.floor(((now - start) / ms) * text.length);
el.textContent = [...text].map((c, i) => (i < shown || c === ' ' ? c : glyphs[(Math.random() * glyphs.length) | 0])).join('');
if (shown < text.length) requestAnimationFrame(tick);
};
requestAnimationFrame(tick);
}