Getting Started
Blocks
Components
Device Mocks
Special Effects
Animations
Text Animations
Buttons
"use client";
import { cn } from "@/lib/utils";
import { GridPattern } from "@/registry/magicui/grid-pattern";
export function GridPatternDemo() {
return (
<div className="relative flex h-[500px] w-full flex-col items-center justify-center overflow-hidden rounded-lg border bg-background">
<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-image:radial-gradient(400px_circle_at_center,white,transparent)]",
"inset-x-0 inset-y-[-30%] h-[200%] skew-y-12",
)}
/>
</div>
);
}
Installation
pnpm dlx shadcn@latest add @magicui/grid-pattern
Examples
Linear Gradient
"use client";
import { cn } from "@/lib/utils";
import { GridPattern } from "@/registry/magicui/grid-pattern";
export function GridPatternLinearGradient() {
return (
<div className="relative flex size-full items-center justify-center overflow-hidden rounded-lg border bg-background p-20">
<GridPattern
width={20}
height={20}
x={-1}
y={-1}
className={cn(
"[mask-image:linear-gradient(to_bottom_right,white,transparent,transparent)] ",
)}
/>
</div>
);
}
Dashed Stroke
"use client";
import { cn } from "@/lib/utils";
import { GridPattern } from "@/registry/magicui/grid-pattern";
export function GridPatternDashed() {
return (
<div className="relative flex size-full items-center justify-center overflow-hidden rounded-lg border bg-background p-20">
<GridPattern
width={30}
height={30}
x={-1}
y={-1}
strokeDasharray={"4 2"}
className={cn(
"[mask-image:radial-gradient(300px_circle_at_center,white,transparent)]",
)}
/>
</div>
);
}
Usage
import { GridPattern } from "@/components/magicui/grid-pattern";
<div className="relative h-[500px] w-full overflow-hidden">
<GridPattern />
</div>
Props
GridPattern
Prop | Type | Default | Description |
---|---|---|---|
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 |
squares | number | [] | X Y coordinates of filled squares as 2D array |
strokeDasharray | string | 0 | Stroke dash array for the pattern |
Limited Time Offer
Ship Faster with Magic UI ProMagic UI Pro
Stop building from scratch.
Get 8 production-ready templates and 50+ premium components that your users will love.
✓
Next.js 15 + TypeScript ready✓
Copy, paste, customize in minutes✓
Save 100+ hours of development