Skip to content
GitHub

Animated Grid Pattern

An animated background grid pattern made with SVGs.

import { AnimatedGridPattern } from "@/components/backgrounds/pxl/animated-grid-pattern";
import { cn } from "@/lib/utils";
export default function AnimatedGridPatternDemo() {
return (
<AnimatedGridPattern
numSquares={30}
maxOpacity={0.1}
duration={3}
repeatDelay={1}
className={cn(
"mask-[radial-gradient(500px_circle_at_center,white,transparent)]",
"inset-x-0 inset-y-[-30%] h-[200%] skew-y-12",
)}
/>
);
}
pnpm dlx shadcn@latest add pxl-ui/registry/backgrounds/animated-grid-pattern
import { AnimatedGridPattern } from "@/components/backgrounds/pxl/animated-grid-pattern"
<AnimatedGridPattern />

Use the variant prop to change the colors of the grid.

"use client";
import { AnimatedGridPattern } from "@/components/backgrounds/pxl/animated-grid-pattern";
import { cn } from "@/lib/utils";
export default function FlickeringGridVariants() {
return (
<div className="flex flex-wrap size-full items-center justify-center gap-2">
<div className="relative w-max h-32 aspect-video pixel-rounded pixel-size-lg">
<AnimatedGridPattern
variant="muted"
numSquares={30}
maxOpacity={0.1}
duration={3}
repeatDelay={1}
className={cn(
"mask-[radial-gradient(500px_circle_at_center,white,transparent)]",
"inset-x-0 inset-y-[-30%] h-[200%] skew-y-12",
)}
/>
</div>
<div className="relative w-max h-32 aspect-video pixel-rounded pixel-size-lg">
<AnimatedGridPattern
variant="primary"
numSquares={30}
maxOpacity={0.1}
duration={3}
repeatDelay={1}
className={cn(
"mask-[radial-gradient(500px_circle_at_center,white,transparent)]",
"inset-x-0 inset-y-[-30%] h-[200%] skew-y-12",
)}
/>
</div>
<div className="relative w-max h-32 aspect-video pixel-rounded pixel-size-lg">
<AnimatedGridPattern
variant="info"
numSquares={30}
maxOpacity={0.1}
duration={3}
repeatDelay={1}
className={cn(
"mask-[radial-gradient(500px_circle_at_center,white,transparent)]",
"inset-x-0 inset-y-[-30%] h-[200%] skew-y-12",
)}
/>
</div>
<div className="relative w-max h-32 aspect-video pixel-rounded pixel-size-lg">
<AnimatedGridPattern
variant="success"
numSquares={30}
maxOpacity={0.1}
duration={3}
repeatDelay={1}
className={cn(
"mask-[radial-gradient(500px_circle_at_center,white,transparent)]",
"inset-x-0 inset-y-[-30%] h-[200%] skew-y-12",
)}
/>
</div>
<div className="relative w-max h-32 aspect-video pixel-rounded pixel-size-lg">
<AnimatedGridPattern
variant="warning"
numSquares={30}
maxOpacity={0.1}
duration={3}
repeatDelay={1}
className={cn(
"mask-[radial-gradient(500px_circle_at_center,white,transparent)]",
"inset-x-0 inset-y-[-30%] h-[200%] skew-y-12",
)}
/>
</div>
<div className="relative w-max h-32 aspect-video pixel-rounded pixel-size-lg">
<AnimatedGridPattern
variant="danger"
numSquares={30}
maxOpacity={0.1}
duration={3}
repeatDelay={1}
className={cn(
"mask-[radial-gradient(500px_circle_at_center,white,transparent)]",
"inset-x-0 inset-y-[-30%] h-[200%] skew-y-12",
)}
/>
</div>
</div>
);
}
Prop Type Default Description
className string - Additional classes to be added to the pattern
variant "default" | "primary" | "secondary" | "muted" | "success" | "warning" | "danger" "default" Colors of the grids
width number 40 Width of the pattern
height number 40 Height of the pattern
x number -1 X offset of the pattern
y number -1 Y offset of the pattern
strokeDasharray number 0 Stroke dash array of the pattern
numSquares number 200 Number of squares in the pattern
maxOpacity number 0.5 Maximum opacity of the pattern
duration number 1 Duration of the animation
repeatDelay number 0.5 Repeat delay of the animation