Text✨ Premium

Scramble Text

On hover, each letter scrambles into random glyphs then resolves left-to-right — a cyberpunk decryption effect, zero dependencies.

CSSJSHover

You'll get access to the interactive demo with a free account.

This effect is part of Effect.Labs — 811 vanilla effects, some free, some premium. Text has 56 effects, including 4 free. Explore the category →

3 usage examples

Tech hero — Large brand headline in terminal style — Scramble Text example 1

① Tech hero — Large brand headline in terminal style

WhenOn a dark or cyberpunk-themed landing page, as the visitor arrives and hovers over the main headline.
WhyAt large size (3–5 rem), the scramble is at its most impactful: every frame is readable, glyphs fill the full width of the title. The terminal-decryption aesthetic maps naturally onto tech, AI, or crypto positioning without any other decoration.
SettingsFont-size 4 rem, font-weight 800, letter-spacing 4px, pool narrowed to uppercase letters only for a cleaner read — change the chars constant to 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.
UI component — Scrambling navigation items — Scramble Text example 2

② UI component — Scrambling navigation items

WhenIn a dark sidebar, admin panel, or technical dashboard where each menu item scrambles individually on hover.
WhyAt small size (1–1.5 rem), resolution lasts ~250–450 ms per item — noticeable but not disruptive. The effect replaces hover color and underlines with depth, adding a technical signature without visual noise.
SettingsFont-size 1.1 rem, letter-spacing 1px, faster resolution: setInterval(…, 20) and iterations += 1/2 for a snappier reveal.
Cyberpunk button — Access revealed on hover — Scramble Text example 3

③ Cyberpunk button — Access revealed on hover

WhenOn a gaming interface, dark site, or tech portal, when the main button invites the user to enter, access, or trigger a critical action.
WhyHovering is the expected action on a button — the scramble effect turns a simple hover into an access ritual. On a short label (6–8 characters: 'ACCESS', 'ENTER', 'DECRYPT'), full resolution takes ~480 ms at a 20 ms interval with a 1/2 step, just long enough for the user to feel they are earning something before clicking.
SettingsFont-size 1.1 rem, font-weight 700, letter-spacing 4px, pool narrowed to uppercase + symbols — change chars to 'ABCDEFGHIJKLMNOPQRSTUVWXYZ@#$%'. Interval setInterval(…, 20), step iterations += 1/2 for a snappy reveal.

How it works

On mouseenter, a setInterval fires every 30 ms on the target element. Each tick rebuilds the text character by character: positions whose index is below iterations keep their original letter; the rest are replaced by a random glyph drawn from the pool 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@#$%&*'.

The iterations counter advances by 1/3 per tick: each position passes through roughly 3 scramble frames before being fixed, ~90 ms per revealed letter. On an 8-character word like « SCRAMBLE », full resolution takes ~720 ms — long enough to read, short enough to feel snappy. On mouseleave, the interval is cleared and the original text is restored instantly.

The CSS enforces font-family: monospace and a fixed letter-spacing: 2px on .text-scramble. Both are essential: in a monospace font every glyph occupies the same advance width — the text block doesn't jitter during random substitution and no layout shift occurs between frames.

Accessibility

  • No prefers-reduced-motion handling: the code does not test this media query — on systems configured to reduce motion, the scramble animation runs as-is. Implement it per use-case if needed.
  • Keyboard inaccessible: the effect is triggered by mouseenter only — no focus listener is defined. Keyboard users will not see the animation.
  • No aria-live on the element: rapid text mutations are not announced. A screen reader reads the original text at focus, not the intermediate glyphs.
  • Stable-state text contrast (white #ffffff on dark #0a0a0f): ratio > 18:1, well above WCAG AA and AAA.
  • The <span> element has no explicit role or aria-label — assistive technology treats it as standard inline text.

Browser compatibility

Requires only setInterval, mouseenter/mouseleave, and textContent mutation — universally supported since IE 9.

Chrome 60+✓ Full
Firefox 55+✓ Full
Safari 12+✓ Full
Edge 79+✓ Full
Mobile iOS✓ Touch only
Android Chrome✓ Touch only

Without JS, the original text remains displayed — no critical CSS dependency, content stays readable and functional.

The code

HTML structure to paste into your page (CSS + JS available with a premium account):

index.html — structure
<div class="demo-preview">
  <span class="demo-text text-scramble" id="scrambleTextHover">SCRAMBLE</span>
</div>
🔒 Unlock the full code — from €2.99 the first month

Full HTML + CSS + JS, copy-paste ready — with hundreds of premium effects.

Customize

Options passed to the API or data-* attributes:

Option / propertyDefaultEffect
chars (JS constant) 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@#$%&*' Pool of random glyphs used during scrambling. Narrow to uppercase letters only for a cleaner look; add katakana or Unicode symbols for a matrix effect.
setInterval(…, 30) (JS) 30 ms Refresh rate. Lower to 20 ms for a smoother, faster animation; raise to 60 ms for a slower, more readable scramble.
iterations += 1/3 (JS) 1/3 Reveal speed per tick. 1/2 → each letter fixed in 2 frames (~40 ms/letter at 20 ms). 1/6 → 6 scramble frames per letter (~180 ms/letter). Combine with the interval to fine-tune total duration.
.text-scramble { letter-spacing } (CSS) 2px Spacing between glyphs. Increase to 4–6 px on large headings; 1 px on small text. Do not set to 0: variable-width glyphs will cause jitter.
.demo-text { font-size } (CSS) 2.5rem Text size. The larger the text, the more impactful the effect — recommended ≥ 2 rem for the scramble to be clearly visible.
.demo-text { font-weight } (CSS) 800 Font weight. Heavy weights (700–900) make random glyphs more legible during scrambling and amplify the visual punch.
font-family: monospace (CSS on .text-scramble) monospace Fixed-width font required for visual stability. JetBrains Mono, Fira Code, or Courier New work well. Avoid proportional fonts: line width would shift on every frame.

FAQ

The code targets a single element via getElementById('scrambleTextHover'). To target multiple elements, replace the initialisation with a loop over querySelectorAll('.text-scramble') and attach mouseenter/mouseleave listeners to each node with its own scrambleInterval variable — each instance runs independently.
Proportional fonts (Inter, Arial, Helvetica) assign different advance widths to each glyph: as random characters replace the originals, the total word width changes every frame and the text block jumps. The font-family: monospace rule on .text-scramble enforces a fixed advance width and eliminates the jitter.
Two parameters work in tandem: the setInterval delay (frame rate) and the step iterations += 1/3 (frames before a letter is fixed). For a long but smooth scramble: 20 ms interval + 1/8 step (~160 ms/letter). For near-instant decryption: 30 ms interval + step 1 (30 ms/letter, one scramble frame per position).