affectUI › Motion › Backgrounds

Grid Background

A fine line grid that drifts slowly behind your content and fades out towards the edges.

Free and open source (MIT). Install: npx shadcn@latest add https://www.affectui.com/r/grid-background.json · Import from @/components/ui/grid-background

When to use

  • Hero sections and feature headers that need a quiet, technical backdrop
  • Empty states or panels that feel too flat on a plain background

When not to use

  • Behind dense text or data tables – the lines compete with the content
  • Several moving backgrounds on one screen – keep it to one per view

Usage

import { GridBackground } from "@/components/ui/grid-background";

export function Hero() {
  return (
    <GridBackground size={48} direction="diagonal">
      <section style={{ display: "grid", placeItems: "center", minHeight: 480 }}>
        <h1>Build on a steady grid</h1>
      </section>
    </GridBackground>
  );
}

Props

NameTypeDefaultDescription
childrenReactNodeContent rendered above the grid
sizenumber48Cell size in px
colorstringrgba(0,0,0,.07)Line color; dark mode defaults to rgba(255,255,255,.07)
speednumber3Seconds per cell; 0 keeps the grid still
direction"up" | "down" | "left" | "right" | "diagonal""diagonal"Drift direction; diagonal runs from top right to bottom left
revealbooleantrueUncover the grid with a circle growing from the center when it first comes into view
fadenumber70Radius of the edge fade, in % of the distance to the corners
classNamestringExtra class on the container – give it a height or let the content size it

Accessibility

  • The grid layer is decorative: aria-hidden and pointer-events: none
  • Content sits in its own layer above the grid and stays fully interactive

Responsive

  • Fills its container at any size; the fade follows the container's shape
  • Dark mode built in: switches when an ancestor (usually <html>) has the class dark or data-theme="dark"

Requirements

  • React 19