Docs
Glitch Text
Glitch text effect
Loading...
Installation
CLI
pnpm dlx shadcn@latest add https://animata.design/r/text/glitch-text.json
Manual
Add to your CSS
@keyframes glitch {
0% { color: #fff; text-shadow: 2px 2px 0px #00ffff, -2px -2px 0px #ff00ff; }
25% { color: #00ffff; text-shadow: -2px -2px 0px #fff, 2px 2px 0px #ff00ff; }
50% { color: #ff00ff; text-shadow: 2px -2px 0px #00ffff, -2px 2px 0px #fff; }
75% { color: #eee; text-shadow: -2px 2px 0px #ff00ff, 2px -2px 0px #00ffff; }
100% { color: #fff; text-shadow: 2px 2px 0px #00ffff, -2px -2px 0px #ff00ff; }
}
@keyframes twinkle {
0% { opacity: 0; }
50% { opacity: 1; }
100% { opacity: 0; }
}Run the following command
It will create a new file glitch-text.tsx inside the components/animata/text directory.
mkdir -p components/animata/text && touch components/animata/text/glitch-text.tsxPaste the code
Open the newly created file and paste the following code:
import { Tomorrow } from "next/font/google";
import { cn } from "@/lib/utils";
const tomorrow = Tomorrow({
subsets: ["latin"],
weight: ["800", "900"],
variable: "--font-tomorrow",
});
export default function GlitchText({
text = "1000 Stars",
className,
starCount = 50,
}: {
text: string;
className?: string;
starCount?: number;
}) {
return (
<div className="full-content relative flex items-center justify-center overflow-hidden">
<div className="relative flex flex-col items-center justify-center bg-linear-to-b from-[#4B0082] via-[#3B0066] to-[#2B004A]">
{[...Array(starCount)].map((_, i) => (
<div
key={i}
className="star absolute aspect-square animate-[twinkle_5s_infinite] rounded-full bg-[#fafafa] opacity-75"
style={{
width: `${Math.random() * 4}px`,
left: `${Math.random() * 100}%`,
top: `${Math.random() * 100}%`,
animationDelay: `${Math.random() * 5}s`,
}}
/>
))}
<h1
className={cn(
"glitch-text z-10 animate-[glitch_0.5s_infinite] p-6 text-4xl font-black md:p-12 md:text-8xl",
className,
tomorrow.className,
)}
aria-label={text}
>
{text}
</h1>
</div>
</div>
);
}Credits
Built by hari