Text Scramble

Changed characters cycle through random glyphs before they settle.

Preview

"use client";

import { useState } from "react";
import { TextScramble } from "@/components/motion/text-scramble";

const PHRASES = [
  "Inspecting the repository",
  "Running the checks",
  "Preparing the update",
];

export function TextScramblePreview() {
  const [index, setIndex] = useState(0);

  return (
    <div className="flex w-full flex-col items-center gap-8 text-center">
      <TextScramble
        text={PHRASES[index]}
        className="font-mono text-xl font-medium text-foreground"
      />

      <button
        type="button"
        onClick={() => setIndex((current) => (current + 1) % PHRASES.length)}
        className="inline-flex h-9 items-center rounded-full border border-border bg-card px-4 text-xs font-medium text-foreground press hover:border-(--color-border-strong)"
      >
        Next phrase
      </button>
    </div>
  );
}

Install

Add it with the shadcn CLI, or copy the source manually.

$ bunx --bun shadcn add @beui/text-scramble

API Reference

text
string

Final text revealed by the scramble animation.

Default—
duration?
number

Maximum animation duration in milliseconds.

Default—
glyphs?
string

Characters sampled while unresolved positions are scrambling.

DefaultABCDEFGHJKLMNPQRSTUVWXYZ0123456789#%&@$?/
className?
string

Classes merged onto the root element.

Default—
style?
CSSProperties

Inline styles for the root element.

Default—
Also on React Native. Reveals, sweeps, shimmers, cascades and scrambles.

More in Text Animation

Updated