Skip to documentation content

Dot Grid

A transparent grid of dots for section backgrounds, with an optional slow wave, twinkle, edge fade, and pointer highlight.

dot-grid-demo

Overview

Dot Grid draws an evenly spaced lattice of dots on a transparent canvas, so it sits on any surface. It is the quiet background behind a hero, an empty state, or a feature section. The dots default to currentColor at low opacity, so they follow your text color and switch with the theme.

Optional layers add life without noise:

  • Wave swells and shrinks the dots in a slow diagonal pattern.
  • Twinkle fades individual dots in and out.
  • Pointer highlight grows and recolors the dots near the cursor.
  • Fade dissolves the grid toward the edges, the top, or the bottom so it never ends in a hard line.

The grid is centered, so the outer dots sit the same distance from each edge, and it stays crisp at any device pixel ratio.

Installation

npm install honestui

Usage

import { DotGrid } from "honestui/shaders"

<section className="relative overflow-hidden rounded-xl border">
  <DotGrid className="absolute inset-0" fade="radial" wave={0.3} />
  <div className="relative p-12">
    <h2>Ship it calmly.</h2>
  </div>
</section>

Pass content as children or layer it above the grid as in the example. Any CSS color works for color and highlightColor, including custom properties such as var(--primary).

A static grid with no wave, twinkle, or pointer highlight renders once and only redraws on resize, so it costs almost nothing.

Accessibility

The canvas is hidden from assistive technology and the grid is decoration only. Keep dot opacity low behind text and check contrast where the highlight passes under content. The wave and twinkle stop when the user prefers reduced motion, while the element is offscreen, and while the page is hidden. The pointer highlight follows the cursor only and carries no information.

API Reference

PropTypeDefaultDescription
gapnumber20Distance between dot centers in CSS pixels.
dotSizenumber2Dot diameter in CSS pixels.
shapecircle|square|diamond|cross"circle"Dot shape.
colorstring"currentColor"Dot color. Any CSS color.
opacitynumber0.35Dot opacity from 0 to 1.
wavenumber0Strength of the slow wave from 0 to 1.
twinklenumber0Strength of the per-dot twinkle from 0 to 1.
speednumber1Animation speed.
interactivebooleantrueGrows and brightens dots near the pointer.
highlightColorstring–Color of dots near the pointer. Defaults to color.
highlightRadiusnumber140Radius of the pointer highlight in CSS pixels.
highlightScalenumber2.2Dot scale at the center of the highlight.
fadenone|radial|edges|top|bottom"none"Fades the grid out toward the edges.
pausedbooleanfalseRenders one still frame.
classNamestring–Class for sizing and positioning the container.
childrenReactNode–Content layered above the grid.