Style Library
Text Scramble
AnimationanimationText animation that transforms text by randomly cycling through characters before settling on the final content, creating an engaging cryptographic effect.
Prompt
Paste into any AI assistant before describing what to build — or attach it to a project below.
# Animation pattern — Text Scramble
Text animation that transforms text by randomly cycling through characters before settling on the final content, creating an engaging cryptographic effect.
Build it in React with `motion` (motion/react) and Tailwind CSS. Respect `prefers-reduced-motion` (render the final state without movement), keep it under ~400 ms for UI feedback, and animate only transform and opacity where possible.
Reference implementation (Motion-Primitives, MIT):
```tsx
'use client';
import { type JSX, useEffect, useState } from 'react';
import { motion, MotionProps } from 'motion/react';
export type TextScrambleProps = {
children: string;
duration?: number;
speed?: number;
characterSet?: string;
as?: React.ElementType;
className?: string;
trigger?: boolean;
onScrambleComplete?: () => void;
} & MotionProps;
const defaultChars =
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
export function TextScramble({
children,
duration = 0.8,
speed = 0.04,
characterSet = defaultChars,
className,
as: Component = 'p',
trigger = true,
onScrambleComplete,
...props
}: TextScrambleProps) {
const MotionComponent = motion.create(
Component as keyof JSX.IntrinsicElements
);
const [scrambledText, setScrambledText] = useState<string | null>(null);
const [isAnimating, setIsAnimating] = useState(false);
const text = children;
const displayText = scrambledText ?? children;
const scramble = async () => {
if (isAnimating) return;
setIsAnimating(true);
const steps = duration / speed;
let step = 0;
const interval = setInterval(() => {
let scrambled = '';
const progress = step / steps;
for (let i = 0; i < text.length; i++) {
if (text[i] === ' ') {
scrambled += ' ';
continue;
}
if (progress * text.length > i) {
scrambled += text[i];
} else {
scrambled +=
characterSet[Math.floor(Math.random() * characterSet.length)];
}
}
setScrambledText(scrambled);
step++;
if (step > steps) {
clearInterval(interval);
setScrambledText(null);
setIsAnimating(false);
onScrambleComplete?.();
}
}, speed * 1000);
};
useEffect(() => {
if (!trigger) return;
scramble();
}, [trigger]);
return (
<MotionComponent className={className} {...props}>
{displayText}
</MotionComponent>
);
}
```Use it in an app
Create a free account to attach this style to a project: the hub adds it to the prompt your AI assistant gets, so it builds every page in this look.
From Motion-Primitives (MIT, commit 120f64f).View source