Grid Pattern
magicui/grid-patternFreeComponent
A background grid pattern made with SVGs, fully customizable using Tailwind CSS.
Live preview
live · rendered by the registry
Rendered by magicui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://magicui.design/r/grid-pattern.jsonSource
1import { useId } from "react"23import { cn } from "@/lib/utils"45interface GridPatternProps extends React.SVGProps<SVGSVGElement> {6 width?: number7 height?: number8 x?: number9 y?: number10 squares?: Array<[x: number, y: number]>11 strokeDasharray?: string12 className?: string13 [key: string]: unknown14}1516export function GridPattern({17 width = 40,18 height = 40,19 x = -1,20 y = -1,21 strokeDasharray = "0",22 squares,23 className,24 ...props25}: GridPatternProps) {26 const id = useId()2728 return (29 <svg30 aria-hidden="true"31 className={cn(32 "pointer-events-none absolute inset-0 h-full w-full fill-gray-400/30 stroke-gray-400/30",33 className34 )}35 {...props}36 >37 <defs>38 <pattern39 id={id}40 width={width}41 height={height}42 patternUnits="userSpaceOnUse"43 x={x}44 y={y}45 >46 <path47 d={`M.5 ${height}V.5H${width}`}48 fill="none"49 strokeDasharray={strokeDasharray}50 />51 </pattern>52 </defs>53 <rect width="100%" height="100%" strokeWidth={0} fill={`url(#${id})`} />54 {squares && (55 <svg x={x} y={y} className="overflow-visible">56 {squares.map(([x, y]) => (57 <rect58 strokeWidth="0"59 key={`${x}-${y}`}60 width={width - 1}61 height={height - 1}62 x={x * width + 1}63 y={y * height + 1}64 />65 ))}66 </svg>67 )}68 </svg>69 )70}
Files it writes
More from magicui
All 247 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Androidandroid | magicui | Components | Free | no deps | |
| Animated Beamanimated-beam | magicui | Components | Free | 1 dep | |
| Animated Circular Progress Baranimated-circular-progress-bar | magicui | Components | Free | no deps | |
| Animated Gradient Textanimated-gradient-text | magicui | Components | Free | no deps | |
| Animated Grid Patternanimated-grid-pattern | magicui | Components | Free | 1 dep | |
| Animated Listanimated-list | magicui | Components | Free | 1 dep | |
| Animated Shiny Textanimated-shiny-text | magicui | Components | Free | no deps | |
| Theme Toggleranimated-theme-toggler | magicui | Components | Free | 1 dep |
