Docs
Glitch Text
Glitch text effect
Installation
Update tailwind.config.js
Add the following to your tailwind.config.js file.
module.exports = {
theme: {
extend: {
keyframes: {
glitch: {
"0%": {
color: "#fff",
textShadow: "2px 2px 0px #00ffff, -2px -2px 0px #ff00ff",
},
"25%": {
color: "#00ffff",
textShadow: "-2px -2px 0px #fff, 2px 2px 0px #ff00ff",
},
"50%": {
color: "#ff00ff",
textShadow: "2px -2px 0px #00ffff, -2px 2px 0px #fff",
},
"75%": {
color: "#eee",
textShadow: "-2px 2px 0px #ff00ff, 2px -2px 0px #00ffff",
},
"100%": {
color: "#fff",
textShadow: "2px 2px 0px #00ffff, -2px -2px 0px #ff00ff",
},
},
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.tsx
Paste the code
Open the newly created file and paste the following code:
import React from "react";
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="relative flex items-center justify-center overflow-hidden">
<div className="relative flex flex-col items-center justify-center bg-gradient-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