Grid Pattern

PreviousNext

A flexible SVG-based grid background utility with customizable spacing, dash patterns, and square highlights. Useful for charts, diagrams, or decorative UI sections.

grid-pattern-default

grid-pattern-large

grid-pattern-small

grid-pattern-custom

Installation

pnpm dlx shadcn@latest add https://ui.dalim.in/r/styles/default/grid-pattern.json

Usage

import { GridPattern } from "@/components/ui/grid-pattern"
<div className="relative h-64 w-full rounded-lg border">
  <GridPattern variant="default" />
  <div className="relative z-10 flex h-full items-center justify-center">
    <p className="text-lg font-medium">Content over grid background</p>
  </div>
</div>

With squares highlighted

<GridPattern
  variant="small"
  squares={[
    [2, 3],
    [4, 1],
    [5, 2],
  ]}
/>

API Reference

GridPattern

Renders a customizable SVG grid pattern with optional square highlights.

PropTypeDefaultDescription
widthnumbervariantWidth of each grid tile (overrides variant).
heightnumbervariantHeight of each grid tile (overrides variant).
xnumber-1X-axis offset for the pattern.
ynumber-1Y-axis offset for the pattern.
squaresArrayArray of grid coordinates to fill with highlighted squares.
strokeDasharraystring"0"SVG stroke-dasharray for dashed lines.
variant"default" | "small" | "large""default"Predefined pattern size & style.
classNamestringTailwind/CSS classes applied to the <svg>.
...propsSVGProps<SVGSVGElement>Additional props for the <svg>.

Variants

  • default30x30 grid, light stroke.
  • small10x10 grid, denser lines.
  • large60x60 grid, larger tiles with subtle fill.