Skip to content
GitHub

Grid Pattern

A background grid pattern made with SVGs.

"use client";
import { GridPattern } from "@/components/backgrounds/pxl/grid-pattern";
import { cn } from "@/lib/utils";
export default function GridPatternDemo() {
return (
<GridPattern
squares={[
[4, 4],
[5, 1],
[8, 2],
[5, 3],
[5, 5],
[10, 10],
[12, 15],
[15, 10],
[10, 15],
[15, 10],
[10, 15],
[15, 10],
]}
className={cn(
"mask-[radial-gradient(400px_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/grid-pattern
import { GridPattern } from "@/components/backgrounds/pxl/grid-pattern"
<GridPattern />
"use client";
import { GridPattern } from "@/components/backgrounds/pxl/grid-pattern";
import { cn } from "@/lib/utils";
export default function GridPatternLinearGradient() {
return (
<GridPattern
width={20}
height={20}
x={-1}
y={-1}
className={cn(
"mask-[linear-gradient(to_bottom_right,white,transparent,transparent)]",
)}
/>
);
}
"use client";
import { GridPattern } from "@/components/backgrounds/pxl/grid-pattern";
import { cn } from "@/lib/utils";
export default function GridPatternDashed() {
return (
<GridPattern
width={30}
height={30}
x={-1}
y={-1}
strokeDasharray={"4 2"}
className={cn(
"mask-[radial-gradient(300px_circle_at_center,white,transparent)]",
)}
/>
);
}

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

"use client";
import { GridPattern } from "@/components/backgrounds/pxl/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">
<GridPattern
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">
<GridPattern
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">
<GridPattern
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">
<GridPattern
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">
<GridPattern
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">
<GridPattern
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