Text Scramble
Headlines that decode themselves into place.
Settings
What it does
Text Scramble is a text animation ready for your AI assistant, React or plain JavaScript, with no dependencies. Also called decrypt text, glyph reveal or hacker text.
Each letter flickers through random glyphs before settling, the text resolving roughly left to right. Plays when the line scrolls into view or on hover. Readers using reduced motion see the final text straight away.
Documentation
One copy gives an assistant everything it needs: the complete code, every option and every pitfall. Paste it in Claude, Cursor or ChatGPT and say where the effect goes; it adapts the integration to your stack, not the code.
Copy the prompt
Ask for it
For instance: Add this text scramble effect to the hero of my home page.What it sends# Foundry44 · Text Scramble Text resolves character by character from random glyphs. Add this component to my project. Pick the setup below that matches my project and follow only that one. When it uses the code at the end, keep its logic as written (it is self-contained, with no dependencies) and adapt only the integration: JavaScript instead of TypeScript if the project has none, file names, imports, how it starts. ## Markup it expects The element marked `data-f44="text-scramble"`, with this structure inside. Texts, images and the number of items are the demo's: use mine. The `data-f44-*` attributes set options for the ready-made script only; with the code, pass the same options to `textScramble()` or as props. ```html <p data-f44="text-scramble">Journal · Issue 14 · October</p> ``` ## Options | Option | Attribute | Type | Default | Description | |---|---|---|---|---| | `duration` | `data-f44-duration` | `number` | `900` | Time in ms for the whole text to resolve. | | `trigger` | `data-f44-trigger` | `"view" | "hover"` | `view` | What starts the effect: entering the viewport, or pointer hover / keyboard focus. | | `once` | `data-f44-once` | `boolean` | `true` | With `trigger: "view"`, play only the first time the element enters the viewport. | | `characters` | `data-f44-characters` | `string` | `ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789#%&*+=<>/` | Glyphs shown while a character is still scrambling. | ## Setup - **Plain HTML, no build step**: don't paste the code below. Load the ready-made script once, at the end of `<body>`: `<script src="https://foundry44.dev/demos/text-scramble/text-scramble.js" defer></script>` (or download that file and serve it with the page). It starts itself on every `data-f44="text-scramble"` element and reads the `data-f44-*` attributes above. - **React / Next.js with shadcn/ui** (the project has a `components.json`; otherwise, see the next line): `npx shadcn@latest add https://foundry44.dev/r/text-scramble.json` writes `lib/text-scramble-core.ts` and `components/ui/text-scramble.tsx`, then use `<TextScramble />` with the options as props. - **React / Next.js from npm** (no shadcn/ui, or the user prefers a package): `npm install @foundry44/react` (or the project's package manager), then `import { TextScramble } from "@foundry44/react"` with the options as props. With a bundler and no React: `@foundry44/core`, then `import { textScramble } from "@foundry44/core/text-scramble"`. - **React / Next.js by hand**: save the code below as `lib/text-scramble-core.ts` and import it from there (`@/lib/text-scramble-core` where that alias exists). Don't name it `text-scramble.ts` next to a `TextScramble.tsx`: on macOS and Windows the two names collide. In a component marked `"use client"`, call `textScramble(ref.current, options)` in a `useEffect` and return `instance.destroy` as its cleanup; call `instance.update(options)` when options change. - **Any other stack**: create on mount with `textScramble(element, options)`, `update(options)` when they change, `destroy()` on unmount. Only the ready-made script finds `data-f44` elements and starts them by itself. Pasted code does not: call `textScramble(element)` on each element. ## Pitfalls - Respects prefers-reduced-motion: keep that behaviour. - With a proportional font the line width jitters while scrambling: use a monospace font, or keep the effect on short, single-line text. - Inline markup is preserved: only text nodes are rewritten, so links and <em> stay in place. - Do not change the text while it is scrambling: the change is overwritten when the effect ends. Changes made at rest are picked up on the next play. ## Code: `text-scramble-core.ts` ```ts // Copyright (c) 2026 Foundry44 · MIT License (SPDX-License-Identifier: MIT) /** * Foundry44 — text-scramble * Text resolves character by character from random glyphs, roughly left to * right, when it enters the viewport or when it is hovered. * * Self-contained: no imports, so this file can be copied as-is. */ export interface TextScrambleOptions { /** Time in ms for the whole text to resolve. @range 200 4000 50 */ duration?: number; /** What starts the effect: entering the viewport, or pointer hover / keyboard focus. */ trigger?: "view" | "hover"; /** With `trigger: "view"`, play only the first time the element enters the viewport. */ once?: boolean; /** Glyphs shown while a character is still scrambling. */ characters?: string; } export interface TextScrambleInstance { update(options: TextScrambleOptions): void; destroy(): void; } export const textScrambleDefaults: Required<TextScrambleOptions> = { duration: 900, trigger: "view", once: true, characters: "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789#%&*+=<>/", }; // Swapping glyphs every frame reads as flicker; ~20 swaps per second reads as scrambling. const GLYPH_INTERVAL = 50; // Share of the duration over which the reveal sweeps left to right; the rest is random // jitter so characters don't settle in a rigid line. const REVEAL_SWEEP = 0.7; export function textScramble(el: HTMLElement, options: TextScrambleOptions = {}): TextScrambleInstance { let opts = { ...textScrambleDefaults, ...options }; const noop: TextScrambleInstance = { update() {}, destroy() {} }; if (typeof window === "undefined") return noop; // The resting text is the final text, so reduced motion simply never scrambles. const reduced = window.matchMedia?.("(prefers-reduced-motion: reduce)").matches; if (reduced) return noop; // Each text node with its original characters (Array.from keeps emoji whole). let segments: { node: Text; chars: string[] }[] = []; let revealAt: number[] = []; let frame = 0; let startTime = -1; let lastGlyphTime = Number.NEGATIVE_INFINITY; let played = false; let observer: IntersectionObserver | null = null; // Read the text at play time: at rest the DOM is the truth, even if a framework changed it. // Text nodes are scrambled one by one so inline markup (links, <em>) survives. const collectText = () => { segments = []; const walker = document.createTreeWalker(el, NodeFilter.SHOW_TEXT); for (let node = walker.nextNode(); node; node = walker.nextNode()) { segments.push({ node: node as Text, chars: Array.from((node as Text).data) }); } }; const restore = () => { for (const { node, chars } of segments) node.data = chars.join(""); }; const randomGlyph = (original: string) => { const pool = Array.from(opts.characters || textScrambleDefaults.characters); const glyph = pool[Math.floor(Math.random() * pool.length)] ?? original; const isLower = original !== original.toUpperCase(); return isLower ? glyph.toLowerCase() : glyph; }; const render = (progress: number) => { let index = 0; for (const { node, chars } of segments) { let text = ""; for (const char of chars) { text += progress >= (revealAt[index] ?? 0) || /\s/.test(char) ? char : randomGlyph(char); index++; } node.data = text; } }; const tick = (now: number) => { if (startTime < 0) startTime = now; const progress = opts.duration > 0 ? (now - startTime) / opts.duration : 1; if (progress >= 1) { restore(); frame = 0; return; } if (now - lastGlyphTime >= GLYPH_INTERVAL) { lastGlyphTime = now; render(progress); } frame = requestAnimationFrame(tick); }; const play = () => { if (frame) return; played = true; collectText(); const count = segments.reduce((sum, segment) => sum + segment.chars.length, 0); revealAt = Array.from( { length: count }, (_, i) => (count > 1 ? i / (count - 1) : 0) * REVEAL_SWEEP + Math.random() * (1 - REVEAL_SWEEP), ); startTime = -1; lastGlyphTime = Number.NEGATIVE_INFINITY; frame = requestAnimationFrame(tick); }; const bind = () => { if (opts.trigger === "hover") { el.addEventListener("pointerenter", play); el.addEventListener("focusin", play); return; } if (opts.once && played) return; if (typeof IntersectionObserver === "undefined") { play(); return; } observer = new IntersectionObserver( (entries) => { if (!entries.some((entry) => entry.isIntersecting)) return; play(); if (opts.once) unbind(); }, // Wait until the text is a little inside the viewport so the start is actually seen. { rootMargin: "0px 0px -10% 0px" }, ); observer.observe(el); }; const unbind = () => { el.removeEventListener("pointerenter", play); el.removeEventListener("focusin", play); observer?.disconnect(); observer = null; }; bind(); return { update(next) { const previous = opts; opts = { ...opts, ...next }; if (opts.trigger !== previous.trigger || opts.once !== previous.once) { unbind(); bind(); } }, destroy() { unbind(); if (frame) { cancelAnimationFrame(frame); frame = 0; restore(); } }, }; } ```
Two files that become yours: the engine, written without React, and a thin component around it. No package to install. The component is marked use client, so it sits inside a server component as it is.
Add it with the shadcn CLI
In a project set up for shadcn/ui, one command writes both files. Without it, copy them by hand in the two steps below.npx shadcn@latest add https://foundry44.dev/r/text-scramble.json
Or add the engine by hand
Save it aslib/text-scramble-core.ts. It has no dependencies and does nothing on the server.And the component
Save it ascomponents/ui/text-scramble.tsx. It creates the effect on mount, passes every prop change to it live, and cleans up on unmount.// Copyright (c) 2026 Foundry44 · MIT License (SPDX-License-Identifier: MIT) // Generated by scripts/generate.mjs. Do not edit: change the core component instead. "use client"; import { useEffect, useRef, type ComponentPropsWithoutRef } from "react"; import { textScramble, type TextScrambleOptions, type TextScrambleInstance } from "@/lib/text-scramble-core"; export interface TextScrambleProps extends TextScrambleOptions, Omit<ComponentPropsWithoutRef<"div">, keyof TextScrambleOptions> {} export function TextScramble({ duration, trigger, once, characters, style, ...props }: TextScrambleProps) { const ref = useRef<HTMLElementTagNameMap["div"]>(null); const instance = useRef<TextScrambleInstance | null>(null); useEffect(() => { if (!ref.current) return; instance.current = textScramble(ref.current); return () => { instance.current?.destroy(); instance.current = null; }; }, []); // Runs right after creation, then on every option change. useEffect(() => { instance.current?.update(definedOnly({ duration, trigger, once, characters })); }, [duration, trigger, once, characters]); return <div ref={ref} style={style} {...props} />; } function definedOnly<T extends object>(o: T): T { return Object.fromEntries(Object.entries(o).filter(([, v]) => v !== undefined)) as T; }
Or install the package
It is also on npm, in@foundry44/reactwith the other free components. Import it from there instead of@/components/ui.npm install @foundry44/react
import { TextScramble } from "@foundry44/react";
Use it
Every prop is optional: with none, you get the effect as the preview shows it.import { TextScramble } from "@/components/ui/text-scramble"; export function Example() { return ( <TextScramble duration={900} trigger="view" once={true} characters="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789#%&*+=<>/" > {/* your content */} </TextScramble> ); }
PropsProp Default What it is duration 900 Time in ms for the whole text to resolve. trigger view What starts the effect: entering the viewport, or pointer hover / keyboard focus. once true With trigger: "view", play only the first time the element enters the viewport.characters ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789#%&*+=<>/ Glyphs shown while a character is still scrambling. Avoid the pitfalls
- It follows
prefers-reduced-motion: under reduced motion the effect settles at once. - With a proportional font the line width jitters while scrambling: use a monospace font, or keep the effect on short, single-line text.
- Inline markup is preserved: only text nodes are rewritten, so links and <em> stay in place.
- Do not change the text while it is scrambling: the change is overwritten when the effect ends. Changes made at rest are picked up on the next play.
- It follows
One file, readable, no dependencies and no build step. It sets itself up on every element marked data-f44="text-scramble", in plain HTML, WordPress, Framer embeds or any framework.
Load the script
Download it, put it next to your page and load it once, anywhere in the page.<script src="text-scramble.js" defer></script>
The file/*! * Foundry44 · Text Scramble — https://foundry44.dev/components/text-scramble * Text resolves character by character from random glyphs. * Copyright (c) 2026 Foundry44 · MIT License (SPDX-License-Identifier: MIT) * * Usage: load this file, then add data-f44="text-scramble" to any element. * Optional attributes (defaults shown): * data-f44-duration="900" * data-f44-trigger="view" * data-f44-once="true" * data-f44-characters="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789#%&*+=<>/" * Manual: const instance = Foundry44.textScramble(element, { duration: 900, trigger: "view", once: true, characters: "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789#%&*+=<>/" }); * instance.destroy(); * Re-scan the page after adding elements dynamically: Foundry44.init(); * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ (function () { "use strict"; /** * Foundry44 — text-scramble * Text resolves character by character from random glyphs, roughly left to * right, when it enters the viewport or when it is hovered. * * Self-contained: no imports, so this file can be copied as-is. */ const textScrambleDefaults = { duration: 900, trigger: "view", once: true, characters: "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789#%&*+=<>/", }; // Swapping glyphs every frame reads as flicker; ~20 swaps per second reads as scrambling. const GLYPH_INTERVAL = 50; // Share of the duration over which the reveal sweeps left to right; the rest is random // jitter so characters don't settle in a rigid line. const REVEAL_SWEEP = 0.7; function textScramble(el, options = {}) { var _a; let opts = { ...textScrambleDefaults, ...options }; const noop = { update() {}, destroy() {} }; if (typeof window === "undefined") return noop; // The resting text is the final text, so reduced motion simply never scrambles. const reduced = (_a = window.matchMedia) === null || _a === void 0 ? void 0 : _a.call(window, "(prefers-reduced-motion: reduce)").matches; if (reduced) return noop; // Each text node with its original characters (Array.from keeps emoji whole). let segments = []; let revealAt = []; let frame = 0; let startTime = -1; let lastGlyphTime = Number.NEGATIVE_INFINITY; let played = false; let observer = null; // Read the text at play time: at rest the DOM is the truth, even if a framework changed it. // Text nodes are scrambled one by one so inline markup (links, <em>) survives. const collectText = () => { segments = []; const walker = document.createTreeWalker(el, NodeFilter.SHOW_TEXT); for (let node = walker.nextNode(); node; node = walker.nextNode()) { segments.push({ node: node, chars: Array.from(node.data) }); } }; const restore = () => { for (const { node, chars } of segments) node.data = chars.join(""); }; const randomGlyph = (original) => { var _a; const pool = Array.from(opts.characters || textScrambleDefaults.characters); const glyph = (_a = pool[Math.floor(Math.random() * pool.length)]) !== null && _a !== void 0 ? _a : original; const isLower = original !== original.toUpperCase(); return isLower ? glyph.toLowerCase() : glyph; }; const render = (progress) => { var _a; let index = 0; for (const { node, chars } of segments) { let text = ""; for (const char of chars) { text += progress >= ((_a = revealAt[index]) !== null && _a !== void 0 ? _a : 0) || /\s/.test(char) ? char : randomGlyph(char); index++; } node.data = text; } }; const tick = (now) => { if (startTime < 0) startTime = now; const progress = opts.duration > 0 ? (now - startTime) / opts.duration : 1; if (progress >= 1) { restore(); frame = 0; return; } if (now - lastGlyphTime >= GLYPH_INTERVAL) { lastGlyphTime = now; render(progress); } frame = requestAnimationFrame(tick); }; const play = () => { if (frame) return; played = true; collectText(); const count = segments.reduce((sum, segment) => sum + segment.chars.length, 0); revealAt = Array.from( { length: count }, (_, i) => (count > 1 ? i / (count - 1) : 0) * REVEAL_SWEEP + Math.random() * (1 - REVEAL_SWEEP), ); startTime = -1; lastGlyphTime = Number.NEGATIVE_INFINITY; frame = requestAnimationFrame(tick); }; const bind = () => { if (opts.trigger === "hover") { el.addEventListener("pointerenter", play); el.addEventListener("focusin", play); return; } if (opts.once && played) return; if (typeof IntersectionObserver === "undefined") { play(); return; } observer = new IntersectionObserver( (entries) => { if (!entries.some((entry) => entry.isIntersecting)) return; play(); if (opts.once) unbind(); }, // Wait until the text is a little inside the viewport so the start is actually seen. { rootMargin: "0px 0px -10% 0px" }, ); observer.observe(el); }; const unbind = () => { el.removeEventListener("pointerenter", play); el.removeEventListener("focusin", play); observer === null || observer === void 0 ? void 0 : observer.disconnect(); observer = null; }; bind(); return { update(next) { const previous = opts; opts = { ...opts, ...next }; if (opts.trigger !== previous.trigger || opts.once !== previous.once) { unbind(); bind(); } }, destroy() { unbind(); if (frame) { cancelAnimationFrame(frame); frame = 0; restore(); } }, }; } function parse(value) { if (value === "true") return true; if (value === "false") return false; var n = Number(value); return value !== "" && !isNaN(n) ? n : value; } function init() { document.querySelectorAll('[data-f44="text-scramble"]').forEach(function (el) { if (el.__f44) return; var options = {}; [ ["duration", "data-f44-duration"], ["trigger", "data-f44-trigger"], ["once", "data-f44-once"], ["characters", "data-f44-characters"], ].forEach(function (pair) { var value = el.getAttribute(pair[1]); if (value !== null) options[pair[0]] = parse(value); }); el.__f44 = textScramble(el, options); }); } var Foundry44 = (window.Foundry44 = window.Foundry44 || {}); Foundry44.textScramble = textScramble; Foundry44._inits = Foundry44._inits || []; Foundry44._inits.push(init); Foundry44.init = function () { Foundry44._inits.forEach(function (fn) { fn(); }); }; if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", init); else init(); })();
Mark your element
Adddata-f44="text-scramble". Each setting is an attribute on the same element, and an attribute always wins over the default.<div data-f44="text-scramble" data-f44-duration="900"> <!-- your content --> </div>
SettingsAttribute Default What it is data-f44-duration 900 Time in ms for the whole text to resolve. data-f44-trigger view What starts the effect: entering the viewport, or pointer hover / keyboard focus. data-f44-once true With trigger: "view", play only the first time the element enters the viewport.data-f44-characters ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789#%&*+=<>/ Glyphs shown while a character is still scrambling. Drive it from JavaScript
When the element arrives after the page has loaded, or when the settings come from your code.// an element without data-f44, or the script would set it up twice const element = document.querySelector(".my-element"); const instance = Foundry44.textScramble(element, { duration: 900, trigger: "view" }); instance.update({ duration: 900 }); // any option, live instance.destroy(); // listeners and observers gone, inline styles restored // elements added after the page loaded Foundry44.init();
Avoid the pitfalls
- It follows
prefers-reduced-motion: under reduced motion the effect settles at once. - With a proportional font the line width jitters while scrambling: use a monospace font, or keep the effect on short, single-line text.
- Inline markup is preserved: only text nodes are rewritten, so links and <em> stay in place.
- Do not change the text while it is scrambling: the change is overwritten when the effect ends. Changes made at rest are picked up on the next play.
- It follows
For a site builder: Webflow, WordPress, Shopify, Framer, or any site that accepts HTML. One block carries the whole script; paste it, then mark an element.
Paste the embed
Paste it where your builder takes custom HTML: an embed or code block on the page, or the site's footer code to use the effect on every page.Mark the element
Give the element the attributedata-f44with the valuetext-scramble. Most builders have a field for custom attributes; otherwise, add it to the element's HTML.SettingsEvery setting is an attribute too, on the same element. Leave one out and the default applies.Attribute Default What it is data-f44-duration 900 Time in ms for the whole text to resolve. data-f44-trigger view What starts the effect: entering the viewport, or pointer hover / keyboard focus. data-f44-once true With trigger: "view", play only the first time the element enters the viewport.data-f44-characters ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789#%&*+=<>/ Glyphs shown while a character is still scrambling. Avoid the pitfalls
- It follows
prefers-reduced-motion: under reduced motion the effect settles at once. - With a proportional font the line width jitters while scrambling: use a monospace font, or keep the effect on short, single-line text.
- Inline markup is preserved: only text nodes are rewritten, so links and <em> stay in place.
- Do not change the text while it is scrambling: the change is overwritten when the effect ends. Changes made at rest are picked up on the next play.
- It follows