Text that scrambles into random characters, then decodes letter by letter. Runs on hover, when it scrolls into view, or on mount.
<div class="rounded-xl border border-line bg-surface p-6">
<p class="text-sm text-muted">Project codename</p>
<h2 class="mt-1 text-3xl font-semibold tracking-tight text-ink">
<x-markas.text-scramble text="Operation Nusantara" trigger="view" />
</h2>
<a href="#" class="mt-4 inline-flex h-9 items-center rounded-lg border border-line px-3 font-mono text-sm text-ink hover:bg-subtle focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary"><x-markas.text-scramble text="Open the brief" charset="symbols" /></a>
</div>Examples
Stats in sequence
Revenue
Rp 12,4 M
Uptime
99.98%
Active teams
1,284
Revenue
Rp 12,4 M
Uptime
99.98%
Active teams
1,284
Revenue
Rp 12,4 M
Uptime
99.98%
Active teams
1,284
Revenue
Rp 12,4 M
Uptime
99.98%
Active teams
1,284
Revenue
Uptime
Active teams
Terminal
$ markas auth --token
Handshake 0110 1011 0010
Access granted
$ markas auth --token
Handshake 0110 1011 0010
Access granted
$ markas auth --token
Handshake 0110 1011 0010
Access granted
$ markas auth --token
Handshake 0110 1011 0010
Access granted
$ markas auth --token
Handshake
<div class="rounded-xl border border-line bg-surface p-5 font-mono text-sm">
<p class="text-muted">$ markas auth --token</p>
<p class="mt-2 text-ink">Handshake <x-markas.text-scramble text="0110 1011 0010" trigger="mount" charset="binary" :duration="1200" /></p>
<p class="mt-1 flex items-center gap-2 font-semibold text-ink"><span aria-hidden="true" class="size-2 rounded-full bg-success"></span><x-markas.text-scramble text="Access granted" trigger="mount" charset="symbols" :duration="900" :delay="600" /></p>
</div>Studio navbar
<nav aria-label="Main" class="flex items-center justify-between gap-3 rounded-xl border border-line bg-surface px-4 py-3 font-mono text-sm text-ink sm:px-5">
<span class="flex items-center gap-2 font-sans font-semibold"><svg class="size-6 shrink-0" viewBox="0 0 1464 1430" aria-hidden="true"><polygon points="354,578 1256,138 1171,430 268,868" class="fill-ink/15" /><polygon points="553,443 1455,3 1370,295 467,733" class="fill-ink/55" /><polygon points="421,762 1325,318 1240,611 336,1050" class="fill-success/35" /><polygon points="265,1073 1169,629 1084,922 180,1362" class="fill-ink/25" /><polygon points="93,965 997,521 912,814 8,1253" class="fill-ink/75" /><polygon points="347,1135 1251,691 1166,984 262,1424" class="fill-success" /></svg>MarkasUI</span>
<div class="flex gap-3 sm:gap-5">
<a href="#" class="rounded-sm focus-visible:outline-2 focus-visible:outline-offset-4 focus-visible:outline-primary"><x-markas.text-scramble text="Docs" charset="symbols" :duration="500" /></a>
<a href="#" class="rounded-sm focus-visible:outline-2 focus-visible:outline-offset-4 focus-visible:outline-primary"><x-markas.text-scramble text="Templates" charset="symbols" :duration="500" /></a>
<a href="#" class="rounded-sm focus-visible:outline-2 focus-visible:outline-offset-4 focus-visible:outline-primary"><x-markas.text-scramble text="Blog" charset="symbols" :duration="500" /></a>
</div>
</nav>Installation
npx markasui@latest add text-scramblepnpm dlx markasui@latest add text-scrambleyarn dlx markasui@latest add text-scramblebunx --bun markasui@latest add text-scramble- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Install the dependency:
npm install alpinejs - Copy the component source below to
resources/views/components/markas/text-scramble.blade.php.
- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Copy the component source below to
src/components/markas/TextScramble.tsx.
- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Copy the component source below to
src/components/markas/TextScramble.vue.
- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Copy the component source below to
src/lib/components/markas/TextScramble.svelte.
- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Copy the component source below to
src/components/markas/TextScramble.astro.
- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Copy the component source below to
src/app/markas/text-scramble.component.ts.
Usage
<h2 class="text-3xl font-semibold">
<x-markas.text-scramble text="Operation Nusantara" trigger="view" />
</h2>
<x-markas.text-scramble text="Rp 12,4 M" trigger="view" charset="digits" />
<x-markas.text-scramble text="99.98%" trigger="view" charset="digits" :delay="150" />
<a href="/brief"><x-markas.text-scramble text="Open the brief" charset="symbols" /></a>import { TextScramble } from "@/components/markas/TextScramble";
<h2 className="text-3xl font-semibold">
<TextScramble text="Operation Nusantara" trigger="view" />
</h2>
<TextScramble text="Rp 12,4 M" trigger="view" charset="digits" />
<TextScramble text="99.98%" trigger="view" charset="digits" delay={150} />
<a href="/brief"><TextScramble text="Open the brief" charset="symbols" /></a><template>
<h2 class="text-3xl font-semibold">
<TextScramble text="Operation Nusantara" trigger="view" />
</h2>
<TextScramble text="Rp 12,4 M" trigger="view" charset="digits" />
<TextScramble text="99.98%" trigger="view" charset="digits" :delay="150" />
<a href="/brief"><TextScramble text="Open the brief" charset="symbols" /></a>
</template><script lang="ts">
import TextScramble from "$lib/components/markas/TextScramble.svelte";
</script>
<h2 class="text-3xl font-semibold">
<TextScramble text="Operation Nusantara" trigger="view" />
</h2>
<TextScramble text="99.98%" trigger="view" charset="digits" delay={150} />
<a href="/brief"><TextScramble text="Open the brief" charset="symbols" /></a>---
import TextScramble from "@/components/markas/TextScramble.astro";
---
<h2 class="text-3xl font-semibold">
<TextScramble text="Operation Nusantara" trigger="view" />
</h2>
<TextScramble text="99.98%" trigger="view" charset="digits" delay={150} />
<a href="/brief"><TextScramble text="Open the brief" charset="symbols" /></a>import { Component } from "@angular/core";
import { TextScramble } from "./markas/text-scramble.component";
@Component({
selector: "app-stats",
imports: [TextScramble],
template: `
<h2 class="text-3xl font-semibold">
<span
markas-text-scramble
text="Operation Nusantara"
trigger="view"
></span>
</h2>
<span
markas-text-scramble
text="99.98%"
trigger="view"
charset="digits"
delay="150"
></span>
<a href="/brief">
<span markas-text-scramble text="Open the brief" charset="symbols"></span>
</a>
`,
})
export class Stats {}Angular uses an attribute selector on a span: <span markas-text-scramble>. In Astro the text is rendered on the server and a small script scrambles it.
hoverruns on hover and focus of the closest link or button.viewandmountstart scrambled and decode once;viewwaits until the text scrolls into view.- An invisible copy of the final text holds the width, so the layout never shifts while scrambling.
- The random characters come from a seeded generator, so every run looks the same in every framework.
- Screen readers hear only the final text. With reduced motion, the final text is shown and never scrambles. The Blade version needs Alpine.js.
Props
| Name | Type | Default | Description |
|---|---|---|---|
text | string | - | The final text. It is rendered on the server and is what screen readers hear. |
trigger | "hover" | "view" | "mount" | "hover" | hover runs on hover and focus of the closest link or button, view runs once when the text scrolls into view, mount runs right away. |
charset | "letters" | "digits" | "symbols" | "binary" | "letters" | Characters used while scrambling. |
duration | number | 800 | Milliseconds from fully scrambled to fully decoded. |
delay | number | 0 | Milliseconds to stay scrambled before decoding starts, for view and mount. Use rising delays to decode a row of stats in sequence. |
Accessibility
- Screen readers hear the final text once from a visually hidden copy; the scrambled layer is aria-hidden.
- An invisible copy of the final text keeps the width fixed, so nothing around it shifts.
- With reduced motion, the final text is shown and never scrambles.
Related components
More animations components with the same classes in every framework.
- Avatar GroupOverlapping stack of avatars that spreads out on hover, shows each name in a tooltip, and collapses extra people into a +N chip.
- Letter SwapText whose letters slide out and back in with a stagger when its link or button is hovered or focused. Forward, ping-pong, or shuffled order.
- MarqueeEndless horizontal or vertical scroll of any content, with faded edges, reverse direction, and a pause on hover or focus.
- Number TickerNumber that counts up to its value when it scrolls into view, with thousands separators, decimals, and a prefix or suffix.
- Scroll ProgressThin bar at the top of the page or a scrolling container that fills as the reader scrolls.
- Spotlight CardCard with a soft radial light that follows the pointer and a border that glows near it. Lights up on keyboard focus too.