Background Gradient Cursor

NewMotion

Interactive ambient canvas surface featuring cursor-tracking radial mask, procedural dots, dynamic grid lines, and directional linear gradients.

$ pnpm dlx shadcn@latest add @byphongphan/background-gradient-cursor
Requires @byphongphan in components.json
background
Loading preview...

Installation

$ pnpm dlx shadcn@latest add @byphongphan/background-gradient-cursor
Requires @byphongphan in components.json

Anatomy

BackgroundGradientCursor (Relative/Absolute/Fixed canvas wrapper)├── <div (gradient)> (Directional linear background gradient with tilt)├── <div (lines)> (Repeating 45° angled architectural hatching lines)├── <div (grid)> (Procedural coordinate grid layout with customizable size)├── <div (dots)> (Radial dot matrix pattern with variable opacity)├── <div (mask)> (High-performance cursor-following radial spotlight mask)└── {children} (Optional overlaying content, badges, or interactive cards)

Usage

import { BackgroundGradientCursor } from "@/components/background-gradient-cursor"
export function HeroBackground() {  return (    <div className="relative min-h-[400px] w-full overflow-hidden rounded-xl border border-border bg-neutral-950 p-6">      <BackgroundGradientCursor        position="absolute"        gradient={{          display: true,          tilt: 135,          colorStart: "emerald-500",          colorEnd: "transparent",          opacity: 25,        }}        grid={{          display: true,          width: "32px",          height: "32px",          color: "white/10",        }}        dots={{          display: true,          size: 1.5,          color: "white",        }}        mask={{          cursor: true,          radius: 160,          color: "rgba(16, 185, 129, 0.4)",        }}      />      <div className="relative z-10">        <h3>Interactive Canvas Content</h3>      </div>    </div>  )}

Features

  • Hardware-Accelerated Cursor Tracking: Leverages requestAnimationFrame with exponential smoothing (easingFactor: 0.1) to ensure buttery smooth, lag-free cursor tracking without layout thrashing.
  • Layered Visual Stacking: Five independent, composable layers—linear gradient, diagonal lines, coordinate grid, dot matrix, and radial mask—can be toggled and configured individually.
  • Universal Color Token Support: Accepts standard CSS variable names (e.g. primary, emerald-500), direct variables (var(--...)), hex codes (#10b981), and modern color formats (oklch(...)).
  • Zero Heavy Runtime Dependencies: Pure React 19 implementation using native CSS gradients and transforms, requiring no external 3D or animation libraries.
  • Viewport & Element Boundary Awareness: Automatically switches between fixed full-page tracking and scoped container boundary tracking, cleanly hiding the spotlight when the cursor exits the element.

Examples

Cyberpunk Neon Grid

High-frequency cyan grid lines paired with a dual-tone cyan and fuchsia radial gradient mask.

CYBERPUNK NEON

Neural Mesh Interface

Custom multi-stop radial gradient with dual-tone cyan & fuchsia projection tracking the pointer.

Technical Blueprint Matrix

Precision engineering aesthetic with 24px azure coordinate grid lines and high-contrast dot intersections.

TECHNICAL BLUEPRINT

Precision Grid Matrix

Fine-pitched 24px grid layout paired with high-contrast dot intersections illuminated by a focused azure spotlight.

Warm Amber Spotlight

Soft golden radial spotlight with fine amber dot accents tailored for dark card surfaces.

AMBER SPOTLIGHT

Warm Surface Reveal

Soft golden radial glow with fine amber dot accents that smoothly tracks the viewer without visual noise.


API Reference

BackgroundGradientCursor

The primary background container and compositor component.

PropTypeDefaultDescription
positionCSSProperties["position"]"absolute"CSS positioning mode ("absolute", "fixed", or "relative").
gradientGradientProps{}Configuration for the underlying linear gradient wash.
dotsDotsProps{}Configuration for the procedural dot matrix pattern.
gridGridProps{}Configuration for the perpendicular grid lines.
linesLinesProps{}Configuration for the 45-degree repeating diagonal hatching lines.
maskMaskProps{}Configuration for the radial spotlight mask that follows cursor or fixed coords.
classNamestringundefinedAdditional CSS classes for the container element.
styleCSSPropertiesundefinedInline style overrides.
childrenReactNodeundefinedChild elements rendered above background layers (ensure z-index if needed).

MaskProps

PropertyTypeDefaultDescription
cursorbooleanfalseEnables cursor tracking with smooth frame interpolation.
xnumberundefinedStatic X position percentage (used when cursor is false).
ynumberundefinedStatic Y position percentage (used when cursor is false).
radiusnumber | string150px / 50vhRadial radius of the spotlight (pixel value or CSS length unit).
colorstringundefinedCenter color of the radial glow (e.g. primary, #38bdf8, rgba(...)).
gradientstringundefinedCustom CSS radial-gradient(...) string to completely override mask styling.

GradientProps

PropertyTypeDefaultDescription
displaybooleanfalseWhether to render the linear gradient layer.
opacitynumber50Opacity percentage from 0 to 100.
tiltnumber0Angle in degrees for the linear gradient direction.
colorStartstringtransparentColor token, hex code, or CSS variable for the gradient start.
colorEndstringtransparentColor token, hex code, or CSS variable for the gradient end.

GridProps

PropertyTypeDefaultDescription
displaybooleanfalseWhether to render the perpendicular grid lines.
opacitynumber100Opacity percentage from 0 to 100.
colorstring"border"Color token, hex code, or CSS variable for the grid lines.
widthstring"32px"Horizontal cell width of the grid pattern.
heightstring"32px"Vertical cell height of the grid pattern.

DotsProps

PropertyTypeDefaultDescription
displaybooleanfalseWhether to render the dot matrix pattern.
opacitynumber30Opacity percentage from 0 to 100.
colorstring"foreground"Color token, hex code, or CSS variable for the dots.
sizenumber1Radius in pixels of each rendered dot.

LinesProps

PropertyTypeDefaultDescription
displaybooleanfalseWhether to render the 45-degree diagonal lines.
opacitynumber100Opacity percentage from 0 to 100.
sizenumber16Spacing interval in pixels between repeating lines.
colorstring"border"Color token, hex code, or CSS variable for the hatching lines.

Command Palette

Quick search and commands navigation