Impeccable

Stitch Grid

Faint squares drawn in thin dashed lines, clear at the top and fading out below. Use it behind a calm hero or a whole page with one headline.

BackgroundNo extra packagesLight + darkMobile

Animations that blend right into your project.

Browse components
npx shadcn@latest add https://impeccable-ui.com/r/stitch-grid.json
It is meant to be still. The grid is clear at the top and slowly fades away, so the headline gets the attention.

Run it in a project set up with shadcn. No other packages needed. Or open and copy the file into components/ui/stitch-grid.tsx.

Types

Two types. Fade (the default) is clear at the top and fades away toward the bottom, for a minimal, clean look behind a hero. Full covers the whole box evenly, a single section or the whole screen.

Fade · type="fade"
Full · type="full"
<StitchGrid />              // type="fade": clear at the top, gone by the bottom (the default)
<StitchGrid type="full" />  // even over the whole box

Prompts

Paste one into Claude Code, Cursor or any AI coding tool. Install adds this exact background and asks only which section it goes behind. Blend asks three short questions (where, fade or full with the square size, and the color), then fits it to your brand without changing the look.

# Stitch Grid

A 1-file React component from Impeccable. Add it to this project so it works and looks exactly like the source below, in the one place I choose, and change nothing else.

A still background of faint squares drawn with thin dashed lines, like stitches. By default it is clear at the top and fades away toward the bottom; it can also cover the whole section or screen evenly. It sits behind the content and never catches a click.

## Before you build: one question

Look through this project first: its landing and hero sections, its sign-up and pricing sections, its root layout and which sections have plain, empty backgrounds. Then ask me this in one message and wait for my answer:

- **Where should it go?** Suggest the 1–3 sections it fits best behind (for example the hero, or the sign-up section), or the whole page. For a section, keep its content and wrap it in the grid. For the whole page, it goes once in the root layout, fixed to the screen.
  *Why: the grid is faint and fades out, so it suits a calm section with a short headline and room around it, not a busy one full of cards and images.*

Ask nothing else. If I say *skip*, use the best suggestion.

## Keep it as it is

The faint 72px squares, the thin 3px dashes, the 12% line color and the fade from the top are the design. Keep them exactly as in the source, with the default props (`type="fade"`). If something doesn't fit my project, tell me instead of changing it.

- Add only the component file and the one place I picked. If it wraps an existing section, keep that section's content, spacing and background color. Don't add packages, change other files, or restyle anything.
- Don't add the demo parts from the Impeccable website: the "Animations that blend right into your project." headline, its Browse components pill, the Fade and Full cards, or the smaller squares used on the home screen.

## Fastest path

If this project has a `components.json` (shadcn), run `npx shadcn@latest add https://impeccable-ui.com/r/stitch-grid.json`.
If the command succeeds, only fix import paths to match this project and skip ahead. If it fails or there is no `components.json`, build it by hand as below.

## Build it

- Stack: React 18 or 19 with TypeScript. No other packages: the grid is two CSS backgrounds cut into dashes with a CSS mask, plus a few lines that keep it centred.
- JavaScript project? Name the file `stitch-grid.jsx` and remove the type annotations; nothing else changes.
- Create this file, in this project's usual place for components:
  - `components/ui/stitch-grid.tsx`
- Keep these exports and their names: `StitchGrid`, `StitchGridProps`, `StitchGridType`.
- Keep `"use client"` at the top in Next.js App Router projects. In other setups it is harmless.
- Keep the tuning values at the top exactly as written: `LINE_W`, `LINE_A`, `SIZE`, `DASH`, `FADE` and the `CSS` block. They are the design.
- Nothing moves, so there is no reduced-motion fallback to add. Keep the grid out of the way: `pointer-events: none`, `user-select: none` and `aria-hidden` on its layer. It must never catch a click, a text selection or a screen reader.

## Use it

```tsx
import { StitchGrid } from "@/components/ui/stitch-grid";

// Behind one section: wrap its content and give it a size.
export function Hero() {
  return (
    <StitchGrid className="flex min-h-[560px] flex-col items-center justify-center gap-6 px-6">
      <h1>Animations that blend right in</h1>
      <a href="/components">Browse components</a>
    </StitchGrid>
  );
}

// Behind the whole page: once in the root layout, empty, fixed to the screen.
<StitchGrid className="fixed inset-0 -z-10" />
```

- It is a `<div>` and takes every div prop. `className` and `style` go on the box: give it a size (or let it fill its parent) and, if you want one, a background color. The grid has none.
- Everything inside it sits above the grid and works as normal. Keep the section's own tag and landmarks (`<section>`, `<main>`) inside it, or wrap the grid inside the section.

## How the grid is drawn

Read this before you touch anything, so you know what the code does and why it must stay as it is.

1. **The layer.** The box is `position: relative` with `isolation: isolate`. The grid sits in one layer at `z-index: -1` inside it, so everything passed as children always paints above the grid, and the box's own background color paints below it. The layer has `pointer-events: none`, so clicks and selection go straight to the content.
2. **The lines.** Two CSS backgrounds on the layer's `::before` and `::after`: one draws a 1px vertical line every `size` px (72), the other a 1px horizontal line. Each is cut into dashes by a mask that repeats `dash` px on, `dash` px off (3 and 3). The lines are the text color (or `color`) mixed down to 12%, so they follow light and dark mode on their own.
3. **Whole dashes.** `size` is rounded to a whole number of dash-and-space pairs, and the masks sit exactly on the lines, so every square looks the same and a dash starts at every corner.
4. **Centred and sharp.** A small `ResizeObserver` measures the box and moves the grid so it is centred on whole pixels. Both sides match, and no line lands between two pixels and turns blurry.
5. **Fade.** With `type="fade"` (the default) the whole layer gets one more mask: fully clear at the top, about half at 35%, faint at 65% and gone by 90% of the height. With `type="full"` there is no fade.

## Check

- It type-checks and the page renders with no console errors.
- Faint squares about 72px wide, drawn with short dashes, sit behind the content, centred so both sides match. They are clearest at the top and gone near the bottom. Text on top can still be selected and every button and link on top still works.
- It looks right in light and dark mode (check both): dark dashes on a light page, light ones on a dark page, always quieter than the text.
- On a phone the grid shows the same way, the lines stay sharp, the page scrolls normally, and there is no sideways scroll.
- Nothing moves, so `prefers-reduced-motion: reduce` looks the same.
- Nothing else on the site looks or behaves differently.
- Finish with a short report: the files you added or changed, where it's placed, and every place where you had to do something differently from the source, and why.

## Source

The reference implementation. Copy it as-is, then apply only the changes listed above.

### `components/ui/stitch-grid.tsx`

```tsx
"use client";

/**
 * Stitch Grid, from Impeccable.
 *
 * A still background of faint squares drawn with thin dashed lines, like
 * stitches on paper. Two types:
 * - "fade" (the default): the grid is clear at the top and fades away toward
 *   the bottom, for a calm, clean hero.
 * - "full": the grid covers the whole box evenly, a section or the whole screen.
 *
 * It sits behind whatever you put inside it. It is never selectable, never
 * catches a click, and is hidden from screen readers.
 *
 * No packages and no animation: two CSS backgrounds, cut into dashes with a
 * CSS mask. The only script measures the box so the grid sits centred on
 * whole pixels, which keeps every line sharp.
 */

import { useLayoutEffect, useRef, type CSSProperties, type HTMLAttributes, type ReactNode } from "react";

export type StitchGridType = "fade" | "full";

export type StitchGridProps = Omit<HTMLAttributes<HTMLDivElement>, "color"> & {
  /** "fade" (default): clear at the top, gone by the bottom. "full": even over the whole box. */
  type?: StitchGridType;
  /** Size of one square, in px. Rounded to fit whole dashes, so every square looks the same. */
  size?: number;
  /** Length of one dash, in px. The space between dashes is the same. */
  dash?: number;
  /** Color of the lines, drawn at 12% of it. Any CSS color, including var(--…). Default: the text color. */
  color?: string;
  /** Your content. It sits above the grid and works as normal. */
  children?: ReactNode;
};

/* ---------- tuning (the design: keep as written) ---------- */

const LINE_W = 1; // px: thickness of a line
const LINE_A = 12; // %: how strong a line is (share of its color)
const SIZE = 72; // px: default square
const DASH = 3; // px: default dash, and the space after it
const FADE = "linear-gradient(to bottom, #000 0%, rgb(0 0 0 / 0.55) 35%, rgb(0 0 0 / 0.18) 65%, transparent 90%)"; // the "fade" type: clear at the top, gone near the bottom

const CSS = `
:where(.isg) { position: relative; isolation: isolate; }
.isg-layer { position: absolute; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.isg-layer[data-type="fade"] { -webkit-mask-image: ${FADE}; mask-image: ${FADE}; }
.isg-layer::before, .isg-layer::after { content: ""; position: absolute; inset: 0; background-position: var(--isg-x) var(--isg-y); -webkit-mask-position: var(--isg-x) var(--isg-y); mask-position: var(--isg-x) var(--isg-y); }
.isg-layer::before {
  background-image: linear-gradient(to right, var(--isg-c) ${LINE_W}px, transparent ${LINE_W}px);
  background-size: var(--isg-s) var(--isg-s);
  -webkit-mask-image: repeating-linear-gradient(to bottom, #000 0 var(--isg-d), transparent var(--isg-d) calc(var(--isg-d) * 2));
  mask-image: repeating-linear-gradient(to bottom, #000 0 var(--isg-d), transparent var(--isg-d) calc(var(--isg-d) * 2));
  -webkit-mask-size: var(--isg-s) var(--isg-s); mask-size: var(--isg-s) var(--isg-s);
}
.isg-layer::after {
  background-image: linear-gradient(to bottom, var(--isg-c) ${LINE_W}px, transparent ${LINE_W}px);
  background-size: var(--isg-s) var(--isg-s);
  -webkit-mask-image: repeating-linear-gradient(to right, #000 0 var(--isg-d), transparent var(--isg-d) calc(var(--isg-d) * 2));
  mask-image: repeating-linear-gradient(to right, #000 0 var(--isg-d), transparent var(--isg-d) calc(var(--isg-d) * 2));
  -webkit-mask-size: var(--isg-s) var(--isg-s); mask-size: var(--isg-s) var(--isg-s);
}`;

const num = (v: unknown, fallback: number, min: number, max: number) =>
  typeof v === "number" && Number.isFinite(v) ? Math.min(max, Math.max(min, v)) : fallback;

/* ---------- the background ---------- */

export function StitchGrid({ type = "fade", size = SIZE, dash = DASH, color, className, style, children, ...rest }: StitchGridProps) {
  const layerRef = useRef<HTMLDivElement>(null);

  const d = Math.round(num(dash, DASH, 1, 40));
  // A square is always a whole number of dash + space pairs, so a dash starts at every corner.
  const s = Math.max(d * 2, Math.round(num(size, SIZE, 8, 400) / (d * 2)) * d * 2);

  // Centre the grid on whole pixels, so the lines stay sharp and both sides match.
  useLayoutEffect(() => {
    const layer = layerRef.current;
    if (!layer) return;
    const place = () => {
      const { width, height } = layer.getBoundingClientRect();
      layer.style.setProperty("--isg-x", `${Math.floor(((width % s) + s) / 2) % s}px`);
      layer.style.setProperty("--isg-y", `${Math.floor(((height % s) + s) / 2) % s}px`);
    };
    place();
    const ro = new ResizeObserver(place);
    ro.observe(layer);
    return () => ro.disconnect();
  }, [s]);

  const vars = {
    "--isg-s": `${s}px`,
    "--isg-d": `${d}px`,
    "--isg-c": `color-mix(in srgb, ${color ?? "currentColor"} ${LINE_A}%, transparent)`,
    "--isg-x": "0px",
    "--isg-y": "0px",
  } as CSSProperties;

  return (
    <div className={className ? `isg ${className}` : "isg"} style={style} {...rest}>
      <style>{CSS}</style>
      <div ref={layerRef} className="isg-layer" data-type={type === "full" ? "full" : "fade"} style={vars} aria-hidden="true" />
      {children}
    </div>
  );
}
```

Usage

Wrap a section's content in it and give it a size. Everything inside sits above the grid.

import { StitchGrid } from "@/components/ui/stitch-grid";

export function Hero() {
  return (
    <StitchGrid className="flex min-h-[560px] flex-col items-center justify-center gap-6 bg-background px-6">
      <h1 className="text-5xl font-semibold tracking-tight">Animations that blend right in</h1>
      <a href="/components" className="rounded-full border px-5 py-2.5">
        Browse components
      </a>
    </StitchGrid>
  );
}

For a whole page, leave it empty and fix it to the screen, so it stays one screen big however long the page is.

// Behind a whole page: fixed to the screen, under everything.
<StitchGrid type="full" className="fixed inset-0 -z-10" />

How it looks

Squares of size px, drawn with 1px lines cut into short dashes, like stitches. The lines take the text color at 12%, so they are dark on a light page and light on a dark one, and always quieter than your text.

The grid is centred in the box on whole pixels, so both sides match and every line stays sharp, and a dash always starts at a corner. Nothing moves, so there is nothing to slow a phone down and nothing for reduced motion to turn off. It never catches a click or a text selection, and screen readers skip it.

Props

PropDefaultWhat it does
type"fade""fade" is clear at the top and fades out toward the bottom. "full" covers the whole box evenly.
size72Size of one square, in px (8 to 400). Rounded to fit whole dashes, so a dash always starts at a corner.
dash3Length of one dash, in px (1 to 40). The space between dashes is the same length.
colorthe text colorColor of the lines. They are drawn at 12% of it, so pass a full color.
children—Your content. It sits above the grid and works as normal: text can be selected and buttons clicked.
className / style—On the box. Give it a size (or fill its parent), and a background color if you want one: the grid has none.