# Signal Grid

> A hairline grid with short pulses of light travelling along its lines, like data moving through a network, brightening around the cursor.

Category: Backgrounds · Free · Updated 2026-11-14 · Live demo: https://www.motionkitui.com/components/signal-grid

## When to use it

Developer tools, infrastructure and API products, security and networking companies, and technical documentation heroes.

## How it works

The grid is drawn as hairlines on a canvas. A handful of signals each pick a line and a crossing to start from, then travel a few cells as a short gradient stroke with a bright head; when one finishes, another starts somewhere else. Around the pointer a radial glow brightens the grid, and a vignette fades everything towards the edges.

## Installation

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

Or copy `components/motionkit/signal-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"` | Signal colour as a hex value. |
| `cell` | `number` | `48` | Grid cell size in pixels. |
| `signals` | `number` | `10` | How many signals travel at once, roughly. |
| `speed` | `number` | `1` | Signal speed. 0 holds the grid still. |
| `interactive` | `boolean` | `true` | Light up the grid around the pointer. |
| `children` | `ReactNode` |  | Your content, layered above. |

## Accessibility

- **Keyboard: Not applicable.** Decorative, nothing to focus. Your content inside stays fully interactive.
- **Screen readers: Pass.** The canvas and vignette are hidden from assistive tech; only your content is read.
- **Reduced motion: Pass.** With reduced motion on, it draws one still frame. It also stops drawing while off screen.
- **Colour contrast: Pass.** Grid lines are 5% white and signals are thin and brief, with a vignette darkening the middle, so text over it keeps its contrast.

## Source

```tsx
"use client";

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

type SignalGridProps = {
  children?: ReactNode;
  /** Colour of the travelling signals. */
  color?: string;
  /** Size of a grid cell in pixels. */
  cell?: number;
  /** How many signals travel at once, roughly. */
  signals?: number;
  /** Signal speed. 0 holds the grid still. */
  speed?: number;
  /** Light up the grid around the pointer. */
  interactive?: boolean;
  className?: string;
};

type Signal = { horizontal: boolean; line: number; position: number; direction: 1 | -1; pace: number; length: number; end: number };

function toRgb(hex: string) {
  const value = parseInt(hex.replace("#", "").padEnd(6, "0").slice(0, 6), 16);
  return `${(value >> 16) & 255} ${(value >> 8) & 255} ${value & 255}`;
}

/**
 * A hairline grid with short pulses of light travelling along its lines, each with a soft fading tail, like data
 * moving through a network. The grid brightens around the pointer and fades out towards the edges. Drawn on a
 * canvas, paused off screen, and still for reduced motion.
 */
export function SignalGrid({ children, color = "#5FAEB4", cell = 48, signals = 10, speed = 1, interactive = true, className = "" }: SignalGridProps) {
  const canvasRef = useRef<HTMLCanvasElement>(null);

  useEffect(() => {
    const canvas = canvasRef.current;
    const context = canvas?.getContext("2d");
    const area = canvas?.parentElement;
    if (!canvas || !context || !area) return;
    const rgb = toRgb(color);
    const still = speed === 0 || window.matchMedia("(prefers-reduced-motion: reduce)").matches;
    let width = 0;
    let height = 0;
    let frame = 0;
    let visible = true;
    let last = 0;
    let live: Signal[] = [];
    const pointer = { x: 0, y: 0, active: false, glow: 0 };

    function spawn(): Signal {
      const horizontal = Math.random() < 0.5;
      const lines = Math.floor((horizontal ? height : width) / cell);
      const span = horizontal ? width : height;
      const direction = Math.random() < 0.5 ? 1 : -1;
      // start somewhere along the line, at a grid crossing, and travel a few cells
      const start = Math.floor(Math.random() * (span / cell)) * cell;
      const distance = cell * (3 + Math.floor(Math.random() * 6));
      return {
        horizontal,
        line: (1 + Math.floor(Math.random() * Math.max(1, lines - 1))) * cell,
        position: start,
        direction,
        pace: (60 + Math.random() * 90) * speed,
        length: cell * (0.8 + Math.random() * 1.4),
        end: start + direction * distance,
      };
    }

    function resize() {
      const rect = canvas!.getBoundingClientRect();
      const ratio = Math.min(window.devicePixelRatio || 1, 2);
      width = rect.width;
      height = rect.height;
      canvas!.width = width * ratio;
      canvas!.height = height * ratio;
      context!.setTransform(ratio, 0, 0, ratio, 0, 0);
      live = Array.from({ length: signals }, spawn);
      // spread them out so they don't all start together
      live.forEach((signal) => (signal.position += (signal.end - signal.position) * Math.random() * 0.6));
    }

    function draw() {
      context!.clearRect(0, 0, width, height);
      // the grid: hairlines, brighter near the pointer
      context!.lineWidth = 1;
      for (let x = cell; x < width; x += cell) {
        context!.strokeStyle = "rgb(255 255 255 / 0.05)";
        context!.beginPath();
        context!.moveTo(x + 0.5, 0);
        context!.lineTo(x + 0.5, height);
        context!.stroke();
      }
      for (let y = cell; y < height; y += cell) {
        context!.strokeStyle = "rgb(255 255 255 / 0.05)";
        context!.beginPath();
        context!.moveTo(0, y + 0.5);
        context!.lineTo(width, y + 0.5);
        context!.stroke();
      }
      if (pointer.glow > 0.01) {
        const glow = context!.createRadialGradient(pointer.x, pointer.y, 0, pointer.x, pointer.y, cell * 4);
        glow.addColorStop(0, `rgb(${rgb} / ${0.16 * pointer.glow})`);
        glow.addColorStop(1, `rgb(${rgb} / 0)`);
        context!.fillStyle = glow;
        context!.fillRect(pointer.x - cell * 4, pointer.y - cell * 4, cell * 8, cell * 8);
      }

      // each signal: a bright head and a tail that fades behind it, plus a dot where it passes a crossing
      for (const signal of live) {
        const head = signal.position;
        const tail = head - signal.direction * signal.length;
        const fade = Math.min(1, Math.abs(signal.end - head) / (cell * 0.8));
        const [x1, y1, x2, y2] = signal.horizontal ? [tail, signal.line, head, signal.line] : [signal.line, tail, signal.line, head];
        const gradient = context!.createLinearGradient(x1, y1, x2, y2);
        gradient.addColorStop(0, `rgb(${rgb} / 0)`);
        gradient.addColorStop(1, `rgb(${rgb} / ${0.95 * fade})`);
        context!.strokeStyle = gradient;
        context!.lineWidth = 1.5;
        context!.beginPath();
        context!.moveTo(x1 + 0.5, y1 + 0.5);
        context!.lineTo(x2 + 0.5, y2 + 0.5);
        context!.stroke();
        context!.fillStyle = `rgb(${rgb} / ${fade})`;
        context!.beginPath();
        context!.arc(x2 + 0.5, y2 + 0.5, 1.8, 0, Math.PI * 2);
        context!.fill();
      }
    }

    function loop(time: number) {
      const step = last ? Math.min(0.05, (time - last) / 1000) : 0;
      last = time;
      pointer.glow += ((pointer.active ? 1 : 0) - pointer.glow) * 0.08;
      live = live.map((signal) => {
        const position = signal.position + signal.direction * signal.pace * step;
        const done = signal.direction === 1 ? position >= signal.end : position <= signal.end;
        return done ? spawn() : { ...signal, position };
      });
      draw();
      frame = visible ? requestAnimationFrame(loop) : 0;
      if (!frame) last = 0;
    }

    resize();
    draw();
    if (!still) frame = requestAnimationFrame(loop);
    const resizeObserver = new ResizeObserver(() => {
      resize();
      draw();
    });
    resizeObserver.observe(canvas);
    const visibilityObserver = new IntersectionObserver(([entry]) => {
      visible = entry.isIntersecting;
      if (visible && !frame && !still) frame = requestAnimationFrame(loop);
    });
    visibilityObserver.observe(canvas);

    function move(event: PointerEvent) {
      if (!interactive || event.pointerType === "touch") return;
      const rect = canvas!.getBoundingClientRect();
      pointer.x = event.clientX - rect.left;
      pointer.y = event.clientY - rect.top;
      pointer.active = true;
      if (still) {
        pointer.glow = 1;
        draw();
      }
    }
    function leave() {
      pointer.active = false;
      if (still) {
        pointer.glow = 0;
        draw();
      }
    }
    area.addEventListener("pointermove", move);
    area.addEventListener("pointerleave", leave);

    return () => {
      cancelAnimationFrame(frame);
      resizeObserver.disconnect();
      visibilityObserver.disconnect();
      area.removeEventListener("pointermove", move);
      area.removeEventListener("pointerleave", leave);
    };
  }, [color, cell, signals, speed, interactive]);

  return (
    <div className={`relative isolate overflow-hidden bg-[#0C1010] ${className}`}>
      <canvas ref={canvasRef} aria-hidden className="absolute inset-0 -z-10 size-full" />
      {/* the grid fades out towards the edges, keeping attention in the middle */}
      <div aria-hidden className="pointer-events-none absolute inset-0 -z-10 bg-[radial-gradient(ellipse_at_center,transparent_30%,#0C1010_85%)]" />
      {children}
    </div>
  );
}
```
