This is a text scramble effect in vanilla JavaScript: a word dissolves into random glyphs and decodes back letter by letter, like a terminal cracking a password. It's an effect for websites, made with HTML, CSS and JavaScript β not a DaVinci Resolve or After Effects preset. No GSAP, no React, no plugins β about 40 lines of plain JS and a few lines of CSS, and every setting is a CSS variable you can change live. Below: how the decrypt animation works, the settings, and the small traps that make most scramble effects jump around.
Why this effect
This one started in my warehouse app: a menu item now and then loses its signal, the letters turn into noise and come back. I still catch myself waiting for it to happen. What I like is that it's readable most of the time and breaks only for a moment β and the glyphs stay crisp while they change, like a real screen, not a blur. The little echo before the noise is my favourite part.
What you'll build
A heading that stays calm, then throws three fading echo copies up and to the left, turns into a line of glyphs β # % & @ $ βΎ * + = ? / < > [ ] { } and a few letters β and decodes from left to right. The last letters take a little longer, so it feels like the "decryption" is struggling at the end. Then the word holds, and the cycle starts again.
How the scramble text works
1. One cell per letter
The script splits the word into <i> cells, one per character. Intl.Segmenter is used instead of split(""), so emoji and accented letters stay in one piece. The real word goes to aria-label, and the cells are hidden from screen readers.
const chars = [...new Intl.Segmenter().segment(word)].map((p) => p.segment);
el.setAttribute("aria-label", word);
el.textContent = "";
const cells = chars.map((char) => {
const cell = document.createElement("i");
cell.textContent = char;
cell.setAttribute("aria-hidden", "true");
el.append(cell);
return cell;
});
2. Keep every glyph one letter wide
This is where most scramble text effects go wrong: @ is wider than I, and a glyph from a fallback font (like βΎ) can be wider still, so the whole word wobbles while it scrambles. Two things fix it: a monospace font, and a fixed width for every cell.
.st-scramble {
font: 700 64px/1.2 "JetBrains Mono", ui-monospace, monospace;
font-variant-ligatures: none;
white-space: pre;
}
.st-scramble i {
display: inline-block;
width: 1ch;
text-align: center;
font-style: normal;
}
font-variant-ligatures: none matters too: JetBrains Mono joins /= into β and <= into β€, and random glyphs hit those pairs all the time.
3. When does each letter lock?
Each letter gets its own moment to stop scrambling. A straight line (i / length) feels mechanical; raising it to the power of 1.4 makes the first letters lock quickly and the last ones drag, which reads as "decrypting".
const lock = ECHO + 0.05 * decode + 0.95 * decode * (i / chars.length) ** 1.4;
const settled = chars[i] === " " || t < ECHO || t > lock;
cell.textContent = settled ? chars[i] : glyphs[Math.random() * glyphs.length | 0];
t is the time inside one cycle: (now / 1000) % cycle, where the cycle is echo + decode + pause.
4. Glyphs change at their own rate
requestAnimationFrame runs 60 times a second (or 120 on fast screens). If the glyphs changed on every frame, the noise would turn into a grey flicker. So they change only --st-rate times a second β 25 by default, close to the menu glitch it came from:
const tick = Math.floor(now / 1000 * num("--st-rate"));
if (tick === lastTick) return;
lastTick = tick;
5. The echo: copies that fly with inertia
Before the noise, three copies of the word slide up and to the left and come back. Each one is dimmer than the last. The distance follows sinΒ², which starts and ends softly β no jerk at either end.
const k = echo * Math.sin(Math.PI * Math.min(t / ECHO, 1)) ** 2;
el.style.textShadow = [1, 2, 3].map((i) =>
`${-i * k}px ${-i * k / 2}px 0 color-mix(in srgb, currentColor ${80 - i * 25}%, transparent)`
).join(", ");
6. Settings live in CSS
The script reads --st-decode, --st-pause, --st-rate and --st-echo with getComputedStyle on every frame. That is why the sliders above change the running effect at once, and why you can give every heading on your page its own timing with plain CSS.
Make it yours
| Variable | What it does |
|---|---|
--st-decode |
Seconds until the last letter locks. 0.8 s is snappy, 3 s feels like real work. |
--st-pause |
Seconds the word stays readable before it scrambles again. |
--st-rate |
Glyph changes per second. 10β15 looks retro and chunky, 40+ is a nervous blur. |
--st-echo |
How far the echo copies fly, in px. 0 turns the echo off. |
--st-size |
Text size. |
--st-color, --st-glow |
Letters and the glow around them. |
The glyphs come from data-glyphs on the element. Try data-glyphs="01" for a binary look, or katakana for the classic film rain.
Spacing: the effect sets margin: 0 β put your own margin on the element (the space around it on your page).
GSAP, Motion or 40 lines?
Most text scramble tutorials reach for a library. Here's how they compare:
- GSAP ScrambleTextPlugin β needs GSAP core plus the plugin. Good when the page already runs on GSAP timelines.
- Motion and React scramble components β need React and a package. Good for React apps that animate everything with Motion.
- This script β about 40 lines, no dependencies. Works on any page: plain HTML, WordPress, React, Vue.
A library pays off when it already runs your other animations. For one decrypting heading, 40 lines you can read are lighter, and the timing stays in CSS where you can change it per element.
Gotchas
- Use a monospace font, or keep the
1chcells: without them the word changes width on every glyph. - Ligatures: switch them off, or
/=and->will turn into single symbols mid-scramble. - Fallback glyphs: symbols your font doesn't have (
βΎ, emoji) are drawn by another font and may look slightly bigger; the fixed cell keeps the layout steady. - Many headings at once: each one runs its own
requestAnimationFrameloop. A few on a page are fine; for dozens, start the effect on hover or when the element scrolls into view. - Background tabs: browsers pause
requestAnimationFramein hidden tabs, so the effect costs nothing there.
Accessibility
The real word is in aria-label, and the scrambling cells are aria-hidden, so screen readers read the word once instead of a stream of symbols. With prefers-reduced-motion: reduce, the script leaves the word as it is β no noise, no echo.
Variations
- The same terminal look with typing instead of decoding: Typewriter.
- A glitch that tears the word apart instead: Glitch Text.
- Scramble on hover only: start the loop on
mouseenterand stop it once every letter has locked. - Scramble only while it's on screen: an
IntersectionObserversets a flag, and the frame skips its work while the heading is out of view:
// after `let lastTick = -1;`
let visible = false;
new IntersectionObserver(([entry]) => {
visible = entry.isIntersecting;
}).observe(el);
// in frame(), next to the reduced-motion check
if (!visible) return;
FAQ
What is a text scramble effect?
Text that turns into random characters and then decodes back into readable words, letter by letter β also called a decrypt or "hacker text" effect. On a website it's a few lines of JavaScript that swap letters for random glyphs until each one locks in place.
How do I make a text scramble effect without GSAP?
Split the text into one element per letter, then on every animation frame replace the letters that haven't "locked" yet with random characters. Lock them one by one, left to right. That's the whole idea β the code above does it in about 40 lines of vanilla JavaScript.
Can a scramble text effect be done in pure CSS?
Only with characters written out in advance: CSS can switch content between fixed strings, but it can't pick random glyphs or work with any text a visitor types. A small script is the honest way to do it, and all the timing can still live in CSS variables.
Why does my scrambled text jump around?
Different glyphs have different widths. Use a monospace font and give every letter a fixed width: 1ch with display: inline-block, and switch off ligatures with font-variant-ligatures: none.
How do I make the decrypt effect slower at the end?
Raise the letter's position to a power when you compute its lock time: (i / length) ** 1.4. The first letters lock fast and the last ones linger, which reads as the code being cracked.
Can I copy and paste the code?
Yes. The buttons at the top of this page copy the HTML, CSS and JS, or download all three as a .zip. Type your own word in "Your text" and set the timing with the sliders first β the copied code comes with your settings.
How do I make a glitch effect on text?
If you want letters torn into shifted slices with red and blue edges instead of random characters, that's a different effect, and it needs no JavaScript: see Glitch Text.