---
title: Astro Grid Pattern
description: An SVG grid background that fills its container and can highlight selected squares.
seo:
    title: "Grid Pattern Background for Astro"
sidebar:
    label: "Grid Pattern"
related:
    - /patterns/dot-pattern
    - /patterns/dot-pattern-with-glow
    - /patterns/hexagon-pattern
    - /patterns/hover-glow
---

```astro
---
import { GridPattern } from "@/components/patterns/grid-pattern"
---

<div class="bg-background relative flex h-72 w-full items-center justify-center overflow-hidden rounded-lg border">
  <GridPattern />
  <p class="relative z-10 text-sm font-medium">Grid pattern</p>
</div>
```

## Installation

```bash
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.

```ts
import { GridPattern } from "@/components/patterns/grid-pattern"
```

```astro
<div class="relative h-72 overflow-hidden">
  <GridPattern />
</div>
```

## Examples

### Highlighted squares

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

```astro
---
import { GridPattern } from "@/components/patterns/grid-pattern"

const squares: Array<[number, number]> = [
  [1, 1],
  [2, 3],
  [4, 2],
  [6, 1],
  [7, 3],
]
---

<div class="bg-background relative flex h-72 w-full items-center justify-center overflow-hidden rounded-lg border">
  <GridPattern squares={squares} />
  <p class="relative z-10 text-sm font-medium">Highlighted squares</p>
</div>
```

### Dashed lines

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

```astro
---
import { GridPattern } from "@/components/patterns/grid-pattern"
---

<div class="bg-background relative flex h-72 w-full items-center justify-center overflow-hidden rounded-lg border">
  <GridPattern strokeDasharray="4 2" />
  <p class="relative z-10 text-sm font-medium">Dashed grid</p>
</div>
```

### Pointer glow

The lines stay hidden until the pointer moves over them. The mask draws one
grid cell. [Hover Glow](/ui/patterns/hover-glow) fades that mask in under the
pointer. Leave the mask unset to paint a glow over a visible grid instead.

```astro
---
import { HoverGlow } from "@/components/patterns/hover-glow"
---

<HoverGlow
  class="bg-background flex h-72 w-full items-center justify-center overflow-hidden rounded-lg border"
  glowColor="color-mix(in oklch, var(--color-primary) 75%, transparent)"
  glowSize={140}
  maskImage="linear-gradient(black 1px, transparent 1px), linear-gradient(90deg, black 1px, transparent 1px)"
  maskSize="60px 60px"
>
  <p class="relative z-10 text-sm font-medium">Hidden until hover</p>
</HoverGlow>
```

### Masked squares

Add radial mask utilities on the pattern. The grid fades out from the center.

```astro
---
import { GridPattern } from "@/components/patterns/grid-pattern"
---

<div class="bg-background relative flex h-72 w-full items-center justify-center overflow-hidden rounded-lg border">
  <GridPattern class="mask-radial-from-0 mask-radial-to-72" />
  <p class="relative z-10 text-sm font-medium">Masked squares</p>
</div>
```

## API Reference

### GridPatternProps

<AutoTypeTable
    path="../../packages/ui/src/components/patterns/grid-pattern/types.ts"
    name="GridPatternProps"
/>

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](/ui/r/grid-pattern.json) for the component source.
