# Spotlight Grid

> One soft beam follows the pointer across a grid, lighting the borders and faces of the cards it passes.

Category: Cards · Free · Updated 2026-10-20 · Live demo: https://www.motionkitui.com/components/spotlight-grid

## When to use it

Feature and integration grids where one shared light makes a set of cards feel like a single surface, as on many developer-tool landing pages.

## How it works

The grid listens for pointer moves once and writes the cursor position, relative to each card, into CSS variables on that card. Every card paints a radial gradient at those coordinates behind a 1px gap, so its border lights up, plus a fainter wash across its face. Neighbouring cards glow at their nearest edges because they share one beam. No React state changes as the pointer moves.

## Installation

```bash
npx shadcn@latest add https://www.motionkitui.com/r/spotlight-grid.json
```

Or copy `components/motionkit/spotlight-grid.tsx` below. Requires react and Tailwind CSS v4. Free for personal projects; commercial use needs MotionKit Plus (https://www.motionkitui.com/pricing).

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `color` | `string` | `"#5FAEB4"` | Colour of the beam. |
| `radius` | `number` | `320` | Radius of the beam in pixels. |
| `<SpotlightGridItem>` | `component` |  | Wrap each card in one. Lay them out with your own grid classes. |

## Accessibility

- **Keyboard: Pass.** Focusing a link or button inside a card lights that card, so keyboard users get the same highlight.
- **Screen readers: Pass.** The light layers are hidden from assistive tech.
- **Reduced motion: Pass.** Nothing moves on its own. The light follows the pointer directly, with no animation.
- **Colour contrast: Pass.** The face wash stays at 14% strength, so text on cards keeps its contrast.

## Source

```tsx
"use client";

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

type SpotlightGridProps = {
  children?: ReactNode;
  /** Colour of the beam. */
  color?: string;
  /** Radius of the beam in pixels. */
  radius?: number;
  className?: string;
};

type SpotlightGridItemProps = {
  children?: ReactNode;
  className?: string;
};

/**
 * A grid lit by one beam that follows the pointer. Every <SpotlightGridItem> inside
 * lights up where the beam falls on it, so neighbouring cards glow at their nearest edges.
 */
export function SpotlightGrid({ children, color = "#5FAEB4", radius = 320, className = "" }: SpotlightGridProps) {
  const ref = useRef<HTMLDivElement>(null);

  // positions are written straight to CSS variables, so moving the pointer never re-renders React
  function handleMove(event: PointerEvent<HTMLDivElement>) {
    const grid = ref.current;
    if (!grid) return;
    const items = grid.querySelectorAll<HTMLElement>("[data-spotlight-item]");
    for (const item of items) {
      const rect = item.getBoundingClientRect();
      item.style.setProperty("--spot-x", `${event.clientX - rect.left}px`);
      item.style.setProperty("--spot-y", `${event.clientY - rect.top}px`);
    }
    grid.style.setProperty("--spot-on", "1");
  }

  return (
    <div
      ref={ref}
      onPointerMove={handleMove}
      onPointerLeave={() => ref.current?.style.setProperty("--spot-on", "0")}
      style={{ "--spot-color": color, "--spot-radius": `${radius}px`, "--spot-on": 0 } as CSSProperties}
      className={className}
    >
      {children}
    </div>
  );
}

export function SpotlightGridItem({ children, className = "" }: SpotlightGridItemProps) {
  return (
    <div
      data-spotlight-item
      className={`group relative rounded-2xl bg-white/[0.06] p-px focus-within:[--spot-focus:1] ${className}`}
    >
      {/* the border: the beam shows through the 1px gap around the card's face */}
      <div
        aria-hidden
        className="pointer-events-none absolute inset-0 rounded-[inherit] transition-opacity duration-300"
        style={{
          opacity: "max(var(--spot-on), var(--spot-focus, 0))",
          background:
            "radial-gradient(var(--spot-radius) circle at var(--spot-x, 50%) var(--spot-y, 50%), var(--spot-color), transparent 70%)",
        }}
      />
      <div className="relative h-full rounded-[15px] bg-[#0C1010]">
        {/* a fainter wash of the same beam across the face */}
        <div
          aria-hidden
          className="pointer-events-none absolute inset-0 rounded-[inherit] transition-opacity duration-300"
          style={{
            opacity: "calc(max(var(--spot-on), var(--spot-focus, 0)) * 0.14)",
            background:
              "radial-gradient(calc(var(--spot-radius) * 0.8) circle at var(--spot-x, 50%) var(--spot-y, 50%), var(--spot-color), transparent 70%)",
          }}
        />
        <div className="relative h-full p-6">{children}</div>
      </div>
    </div>
  );
}
```
