# Grid Pattern

> Fill a background with a grid of lines or dots, with optional cells that glow on and off.

Source: https://www.honestui.com/docs/animated/grid-pattern

```tsx
"use client";

import { GridPattern } from "@/registry/default/animated/grid-pattern";

export function GridPatternDemo() {
  return (
    <div className="grid w-full max-w-2xl gap-4 sm:grid-cols-2">
      <div className="relative flex h-56 items-center justify-center overflow-hidden rounded-xl border border-border bg-card">
        <GridPattern numSquares={18} fade="radial" />
        <span className="relative text-sm font-medium text-foreground">Animated cells</span>
      </div>
      <div className="relative flex h-56 items-center justify-center overflow-hidden rounded-xl border border-border bg-card">
        <GridPattern variant="dots" width={18} height={18} fade="edges" className="text-foreground/25" />
        <span className="relative text-sm font-medium text-foreground">Dot grid</span>
      </div>
    </div>
  );
}

```

## Overview [#overview]

Grid Pattern draws an SVG grid of lines or dots that fills its parent. Set `numSquares` to make that many random cells glow on and fade out in turn, or pass `squares` for cells that stay filled. A `fade` mask softens the grid toward its edges so it sits behind content without a hard frame. The pattern uses `currentColor`, so a text color class such as `text-foreground/15` sets its tint in both themes.

## Installation [#installation]

<CliBlock commands="[&#x22;grid-pattern&#x22;]" />

## Usage [#usage]

```tsx
import { GridPattern } from "@/components/animated/grid-pattern"

<div className="relative overflow-hidden rounded-xl border">
  <GridPattern numSquares={18} fade="radial" />
  <div className="relative p-8">Content</div>
</div>
```

Use `variant="dots"` with a smaller `width` and `height` for a quieter dot field, and `strokeDasharray` for dashed lines.

## Accessibility [#accessibility]

The grid is decorative and hidden from assistive technology. Glowing cells are chosen on the client after mount, so server and client markup match. When reduced motion is requested, cells do not animate and only the static grid and any fixed `squares` are drawn.

## API Reference [#api-reference]


  ### `width`

type: `number` · default: `40`

Cell width in px.

  ### `height`

type: `number` · default: `40`

Cell height in px.

  ### `x`

type: `number` · default: `-1`

Horizontal offset of the pattern in px.

  ### `y`

type: `number` · default: `-1`

Vertical offset of the pattern in px.

  ### `variant`

type: `&#x22;lines&#x22; | &#x22;dots&#x22;` · default: `&#x22;lines&#x22;`

Draws cell outlines or intersection dots.

  ### `strokeDasharray`

type: `string`

Dash pattern for lines, such as "4 2".

  ### `dotRadius`

type: `number` · default: `1`

Dot radius in px.

  ### `squares`



">
    Cells that stay filled, as column and row pairs.

  ### `numSquares`

type: `number` · default: `0`

Number of cells that glow on and off at random.

  ### `maxOpacity`

type: `number` · default: `0.35`

Peak opacity of a lit cell.

  ### `duration`

type: `number` · default: `4`

Seconds for a cell to fade in and out.

  ### `fade`

type: `&#x22;none&#x22; | &#x22;radial&#x22; | &#x22;edges&#x22; | &#x22;top&#x22; | &#x22;bottom&#x22;` · default: `&#x22;none&#x22;`

Masks the grid toward its edges.

  ### `className`

type: `string`

Classes for the SVG, including its text color.
