GLITCH LAB v1.0 ezolab.dev / lab instrument SYS: READY ✦ Holiday cards

Effects/ Scramble Text [FX_06]/ Calibrated

Scramble Text

Copies a link to this page with your text and settings β€” whoever opens it sees the same effect. Send it to a friend, a colleague or save it for later.
CSS + JS Light Β· zero deps #animation#terminal#text

Text scramble effect in vanilla JS: the word turns into random glyphs and decodes back letter by letter, with a fading echo. No GSAP, any text.

Live viewport Optical bench
LIVE FEED 60.0 FPS | FRAME: 16.7ms RES: β€” [ + calibrated ]
Type any word: the preview changes at once, and so do the HTML you copy, the .zip and CodePen. Leave it empty to get the default word back.

How it works // breakdown

Spec-FX_06

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;
}
Every cell is 1ch wide β€” wide and narrow glyphs take the same space

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 1ch cells: 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 requestAnimationFrame loop. 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 requestAnimationFrame in 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 mouseenter and stop it once every letter has locked.
  • Scramble only while it's on screen: an IntersectionObserver sets 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.

Get the code β€” copy or download
Copy HTML: the markup with your text β€” paste it where the effect should be. Copy CSS: the styles with your slider settings β€” paste into your stylesheet. Any text element works: give it the class and a data-text equal to its text.
or
↓ Download .zip Both files in one archive β€” index.html and style.css β€” with your text and settings. Unzip and open index.html in a browser.
/* Scramble Text β€” a word dissolves into random glyphs and decodes back,
   letter by letter, left to right. A short script swaps the glyphs;
   all timing lives in the variables below, the script reads them live.
   Works on any text element: class="st-scramble" + data-text.
   Font: JetBrains Mono (Google Fonts), falls back to monospace. */
.st-scramble {
  --st-decode: 1.8;  /* seconds until the last letter locks */
  --st-pause: 2.6;    /* seconds the word stays readable before it scrambles again */
  --st-rate: 25;     /* how many times a second the glyphs change */
  --st-echo: 30px;   /* how far the echo copies fly before the noise; 0 = no echo */
  --st-size: 64px;
  --st-color: #9be89a;
  --st-glow: #39ff14;

  margin: 0;         /* margin: space around the text on your page */
  font: 700 var(--st-size)/1.2 "JetBrains Mono", ui-monospace, monospace;
  font-variant-ligatures: none;   /* "/=" must stay two glyphs, not "β‰ " */
  white-space: pre;
  color: var(--st-color);
  filter: drop-shadow(0 0 6px var(--st-glow));
}

/* Every cell is exactly one letter wide: glyphs from other fonts
   (like β‚Ύ) can't make the word jump */
.st-scramble i {
  display: inline-block;
  width: 1ch;
  text-align: center;
  font-style: normal;
}