Skip to content
Esc
↑↓navigate↵open⌘Jpreview
On this page

Astro Grid Pattern

An SVG grid background that fills its container and can highlight selected squares.

Grid pattern

Installation

bunx --bun shadcn@latest add @gnostic/grid-pattern

Usage

Place the pattern inside a parent that has a relative class. The grid pattern will fill the container via absolute inset-0, and will not intercept clicks or other events.

import { GridPattern } from "@/components/patterns/grid-pattern"
<div class="relative h-72 overflow-hidden">
  <GridPattern />
</div>

Examples

Highlighted squares

squares accepts [column, row] pairs. Each pair fills one cell.

Highlighted squares

Dashed lines

Set strokeDasharray to change the grid stroke. "0" draws a solid line.

Dashed grid

Pointer glow

The lines stay hidden until the pointer moves over them. The mask draws one grid cell. Hover Glow fades that mask in under the pointer. Leave the mask unset to paint a glow over a visible grid instead.

Hidden until hover

API Reference

GridPatternProps

PropType
width?number

Width of one grid square, in user units.

Typenumber
Default60
height?number

Height of one grid square, in user units.

Typenumber
Default60
x?number

Horizontal offset of the pattern.

Typenumber
Default-1
y?number

Vertical offset of the pattern.

Typenumber
Default-1
squares?Array<[x: number, y: number]>

Cells to fill, as `[column, row]` pairs.

TypeArray<[x: number, y: number]>
strokeDasharray?string

SVG stroke dash array for the grid lines. Use `"0"` for a solid line.

Typestring
Default"0"

The default color uses fill-muted-foreground/30 and stroke-muted-foreground/30. Pass a fill-* or stroke-* class, or set the fill or stroke directly on the SVG element.

See the registry source for the component source.