Skip to content

Grid Pattern

A grid of thin lines that fills its parent, with an optional edge fade and a slow drift.

Motionv0.1.0experimentalWCAG 2.2 AAView spec

Optional, and kept apart.

Nothing here is included in a project unless you add it, and the plain component it builds on is unchanged. This effect is decoration: it is hidden from screen readers, stands still for visitors who prefer reduced motion, and can be paused. Use Still on a preview to see that version.

Plain grid

Lines at every 32 pixels

import { GridPattern } from "@rdloom/react";

export default function GridPatternExample() {
  return (
    <div className="flex w-full justify-center">
      <div className="relative flex h-96 w-full items-center justify-center overflow-hidden rounded-xl border border-[var(--rd-color-border-default)] bg-[var(--rd-color-surface-default)]">
        <GridPattern fade={false} />
        <div className="relative text-center">
          <p className="text-4xl font-semibold tracking-tight text-[var(--rd-color-text-default)]">Plain grid</p>
          <p className="text-base text-[var(--rd-color-text-muted)]">Lines at every 32 pixels</p>
        </div>
      </div>
    </div>
  );
}

Installation

npx rdloom add grid-pattern

Copies the source into src/components/rdloom. Edit it freely: rdloom upgrade merges later versions into your changes.

Use another registry client
npx shadcn@latest add https://rdloom.vimalbhatt.com/r/grid-pattern.json

Works, but without upgrade tracking.

Usage

import { GridPattern } from "@rdloom/react";

<div className="flex w-full justify-center">
  <div className="relative flex h-96 w-full items-center justify-center overflow-hidden rounded-xl border border-[var(--rd-color-border-default)] bg-[var(--rd-color-surface-default)]">
    <GridPattern fade={false} />
    <div className="relative text-center">
      <p className="text-4xl font-semibold tracking-tight text-[var(--rd-color-text-default)]">Plain grid</p>
      <p className="text-base text-[var(--rd-color-text-muted)]">Lines at every 32 pixels</p>
    </div>
  </div>
</div>

Faded

Faded edges

The grid dissolves toward the sides

import { GridPattern } from "@rdloom/react";

export default function GridPatternExample() {
  return (
    <div className="flex w-full justify-center">
      <div className="relative flex h-96 w-full items-center justify-center overflow-hidden rounded-xl border border-[var(--rd-color-border-default)] bg-[var(--rd-color-surface-default)]">
        <GridPattern size={24} fade />
        <div className="relative text-center">
          <p className="text-4xl font-semibold tracking-tight text-[var(--rd-color-text-default)]">Faded edges</p>
          <p className="text-base text-[var(--rd-color-text-muted)]">The grid dissolves toward the sides</p>
        </div>
      </div>
    </div>
  );
}

Animated

Slow drift

Stops for reduced motion

import { GridPattern } from "@rdloom/react";

export default function GridPatternExample() {
  return (
    <div className="flex w-full justify-center">
      <div className="relative flex h-96 w-full items-center justify-center overflow-hidden rounded-xl border border-[var(--rd-color-border-default)] bg-[var(--rd-color-surface-default)]">
        <GridPattern animated fade />
        <div className="relative text-center">
          <p className="text-4xl font-semibold tracking-tight text-[var(--rd-color-text-default)]">Slow drift</p>
          <p className="text-base text-[var(--rd-color-text-muted)]">Stops for reduced motion</p>
        </div>
      </div>
    </div>
  );
}

API Reference

Defined by the spec. Components also accept the props of the React Aria component they wrap.

PropTypeDefault
size

Cell size in pixels.

number32
strokeWidth

Line thickness in pixels.

number1
color

Colour of the pattern: any CSS colour or a token such as var(--rd-color-border-default).

string"color-mix(in srgb, var(--rd-color-text-default) 16%, transparent)"
fade

Fades the pattern out toward its edges.

booleantrue
animated

Drifts the pattern slowly, one tile per cycle. Off by default.

booleanfalse
isStill

Stops the drift. Moving content should be stoppable.

booleanfalse
duration

Seconds one drift cycle takes.

number10

Accessibility

Role presentation, WCAG 2.2 AA. Tested with axe and keyboard tests; screen reader checks are in the audit checklist.

Keyboard

Not interactive.

Screen readers announce

  • Ignored: it is not announced

What your code must do

  • Pure decoration: aria-hidden, never focusable, and pointer-events none so content on top stays usable
  • It is drawn with CSS only, so it needs no JavaScript and is safe in server HTML
  • Stands still for visitors who ask for less motion (prefers-reduced-motion), with isStill, and inside an rdm-still container
  • Drift is slow and never flashes (WCAG 2.2.2, 2.3.1)
  • Hidden in forced-colors (high contrast) mode so it never fights system colours
  • Keep text on top at 4.5:1 against the lines: use a low-contrast token for the pattern

Guidelines

Use it when

  • A quiet grid behind a hero, card or empty state
  • Giving a flat surface a little texture

Avoid it when

  • Behind long text where the lines reduce legibility
  • As the only way to show a boundary or meaning

Don't

  • A high-contrast colour that competes with the content
  • Animating several patterns on one screen

Design tokens

The semantic tokens this component uses. Change them once and every component follows; see Design tokens.

  • --rd-color-border-default