Skip to content
WANCRAFT

E.50Backgrounds & Effects

Pixel Trail

A canvas grid whose cells light up under the pointer and fade out, leaving a pixel trail.

NewReactCanvasTailwindintermediate

Overview

Pixel Trail divides its area into a grid of square or round cells drawn on a single canvas. Cells under a mouse, pen or finger light up in your colour and fade out over a set duration; positions between pointer events are interpolated so fast strokes never leave gaps. Only lit cells are tracked and painted, the faint idle grid is cached offscreen, and an optional twinkle sprinkles random cells while idle. Touch is followed with passive listeners, so scrolling is never blocked. The loop sleeps when nothing is lit and stops offscreen and in hidden tabs.

01Installation

Method 01 · Registry

CLI verified

Uses the shadcn CLI in a project initialised with shadcn init. Installs the file to components/ui/pixel-trail.tsx and adds its dependencies.

npx shadcn@latest add https://wancraft.my/r/pixel-trail.json

Method 02 · Copy and paste

  1. 1. No extra dependencies — React and Tailwind CSS only.
  2. 2. Copy the source from the Code tab into components/ui/pixel-trail.tsx.
  3. 3. Import it and adjust props.
Dependencies
None
Peer
react ≥ 18, tailwindcss ≥ 4
Added
13 Oct 2026
Updated
—

02Usage

The default configuration. Change properties above to generate a tailored example in the Usage tab.

example.tsx
import { PixelTrail } from "@/components/ui/pixel-trail";

export function PixelTrailExample() {
  return (
    <div className="relative h-80 w-full overflow-hidden rounded-xl">
      <PixelTrail />
    </div>
  );
}

03Props

PropTypeDefaultDescription
cellSizenumber24Grid cell size in px (min 4).
fadeDurationnumber900Time for a lit cell to fade out, in ms.
colorstring"#FF7448"Colour of lit cells (any CSS colour).
shape"square" | "round""square"Cell shape.
gapnumber2Inset between neighbouring lit cells in px.
twinklebooleantrueOccasionally light random cells at low intensity.
showGridbooleantrueFaint hairline grid (square) or dot grid (round).
childrenReactNode—Optional content layered above the grid.
...propsHTMLAttributes<HTMLDivElement>—Forwarded to the root, which is absolute inset-0 — place it inside a positioned parent.

04Features

  • 01Single canvas — no per-cell DOM nodes, only lit cells are painted
  • 02Interpolated strokes: fast pointer moves light every cell along the path
  • 03Mouse, pen and touch, with passive listeners that never block scrolling
  • 04Idle grid cached offscreen; optional twinkle while idle
  • 05Loop sleeps when nothing is lit; stops offscreen and in hidden tabs
  • 06DPR-aware canvas (capped at 2) with ResizeObserver; ink follows the theme
motion · continuousinput · pointerinput · hoverinput · viewport

05Accessibility

  • The canvas is aria-hidden and ignores pointer events; layered content stays fully interactive.
  • prefers-reduced-motion disables the twinkle and the lingering trail: only the cell under the pointer is lit.
  • Very light colours are deepened automatically on light themes so lit cells keep their contrast.