# Dot Canvas

A decorative dotted canvas overlay for design surfaces and page backgrounds.

## Installation

```bash
npx shadcn@latest add https://reactdocs.canceydejean.dev/r/dot-canvas.json
```

[Registry JSON](https://reactdocs.canceydejean.dev/r/dot-canvas.json)

## Preview

```tsx
import { DotCanvas } from "@/lib/dot-canvas";

export function Preview() {
  return (
    <div className="relative h-40 w-full max-w-md overflow-hidden rounded-xl border">
      <DotCanvas />
      <p className="relative z-10 p-6 text-sm text-muted-foreground">
        Content sits above the dots.
      </p>
    </div>
  );
}
```


## Source

### lib/dot-canvas.tsx

```tsx
import { cn } from "cn";

/** Grid pitch of the dotted canvas, in pixels. 24 is the page-scale default. */
const PITCH = {
  12: "bg-size-[12px_12px]",
  20: "bg-size-[20px_20px]",
  24: "bg-size-[24px_24px]",
} as const;

export type DotCanvasSize = keyof typeof PITCH;

export const DOT_CANVAS_SIZES = [12, 20, 24] as const satisfies readonly DotCanvasSize[];

/**
 * Dotted design-canvas texture. Decorative overlay — pointer events pass
 * through. Pass `className` for masks, opacity, and placement overrides.
 */
export function DotCanvas({ size = 24, className }: { size?: DotCanvasSize; className?: string }) {
  return (
    <div
      aria-hidden
      className={cn(
        "pointer-events-none absolute inset-0 bg-[radial-gradient(circle_at_1px_1px,var(--color-border)_1px,transparent_0)]",
        PITCH[size],
        className,
      )}
    />
  );
}
```



## Usage

Place `DotCanvas` inside a `relative` container. It fills the parent with a dotted grid and ignores
pointer events, so content above stays interactive.

```tsx
import { DotCanvas } from "@/lib/dot-canvas";

export function Example() {
  return (
    <div className="relative h-48 overflow-hidden rounded-xl border">
      <DotCanvas />
      <p className="relative z-10 p-6 text-sm">Content sits above the dots.</p>
    </div>
  );
}
```

Pass `size` as `12`, `20`, or `24` (default) to change grid pitch. Use `className` for opacity,
masks, or placement overrides.

