Skip to documentation content

Grid Pattern

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

grid-pattern-demo

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

npx honestui@latest add grid-pattern

Usage

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

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

PropTypeDefaultDescription
widthnumber40Cell width in px.
heightnumber40Cell height in px.
xnumber-1Horizontal offset of the pattern in px.
ynumber-1Vertical offset of the pattern in px.
variantlines|dots"lines"Draws cell outlines or intersection dots.
strokeDasharraystring–Dash pattern for lines, such as "4 2".
dotRadiusnumber1Dot radius in px.
squaresArray<[number, number]>–Cells that stay filled, as column and row pairs.
numSquaresnumber0Number of cells that glow on and off at random.
maxOpacitynumber0.35Peak opacity of a lit cell.
durationnumber4Seconds for a cell to fade in and out.
fadenone|radial|edges|top|bottom"none"Masks the grid toward its edges.
classNamestring–Classes for the SVG, including its text color.