# Dot Grid

> A quiet dotted background that wakes up around the cursor.

- Category: Backgrounds
- Tier: Free (MIT)
- Page: https://bowls.dev/components/dot-grid
- Requires: React 18+, Tailwind CSS 4

## Install

Copy the source below into `components/bowls/dot-grid.tsx`.

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `gap` | `number` | `18` | Space between dots, in px. |
| `color` | `string` | `"currentColor"` | Dot colour (inherits text colour). |
| `spotlight` | `number` | `140` | Radius of the cursor spotlight. |

## Usage

```tsx
"use client";

import { DotGrid } from "@/components/bowls/dot-grid";

export default function Demo() {
  return (
    <DotGrid className="h-full w-full text-[#0a0a0a] dark:text-[#f5f5f5]">
      <div className="flex h-full items-center justify-center">
        <span className="rounded-xl bg-[#f7f7f7] dark:bg-[#080808] px-4 py-2 text-[15px] font-semibold shadow-[0_0_0_10px_#f7f7f7] dark:shadow-[0_0_0_10px_#080808]">Move your cursor</span>
      </div>
    </DotGrid>
  );
}
```

## Source

`components/bowls/dot-grid.tsx`

```tsx
"use client";

import { useRef, type ReactNode } from "react";

export type DotGridProps = {
  children?: ReactNode;
  /** Gap between dots, in px. */
  gap?: number;
  /** Dot colour. Defaults to the text colour, so it follows light / dark mode. */
  color?: string;
  /** Radius of the cursor spotlight, in px. */
  spotlight?: number;
  className?: string;
};

/** A quiet dot background whose dots darken near the cursor. */
export function DotGrid({ children, gap = 18, color = "currentColor", spotlight = 140, className }: DotGridProps) {
  const ref = useRef<HTMLDivElement>(null);

  const move = (e: React.PointerEvent) => {
    const box = ref.current?.getBoundingClientRect();
    if (!box || !ref.current) return;
    ref.current.style.setProperty("--x", `${e.clientX - box.left}px`);
    ref.current.style.setProperty("--y", `${e.clientY - box.top}px`);
  };

  const dots = `radial-gradient(${color} 1.3px, transparent 1.6px)`;

  return (
    <div
      ref={ref}
      onPointerMove={move}
      onPointerLeave={() => ref.current?.style.setProperty("--x", "-999px")}
      className={`relative overflow-hidden ${className ?? ""}`}
      style={{ ["--x" as string]: "-999px", ["--y" as string]: "-999px" }}
    >
      <div aria-hidden="true" className="absolute inset-0 opacity-25" style={{ backgroundImage: dots, backgroundSize: `${gap}px ${gap}px` }} />
      <div
        aria-hidden="true"
        className="absolute inset-0"
        style={{
          backgroundImage: dots,
          backgroundSize: `${gap}px ${gap}px`,
          maskImage: `radial-gradient(${spotlight}px circle at var(--x) var(--y), #000, transparent)`,
          WebkitMaskImage: `radial-gradient(${spotlight}px circle at var(--x) var(--y), #000, transparent)`,
        }}
      />
      <div className="relative h-full">{children}</div>
    </div>
  );
}
```
