Background Gradient Cursor
NewMotionInteractive 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@byphongphan in components.jsonInstallation
$ pnpm dlx shadcn@latest add @byphongphan/background-gradient-cursor@byphongphan in components.jsonAnatomy
Usage
Features
- Hardware-Accelerated Cursor Tracking: Leverages
requestAnimationFramewith 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.
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.
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.
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.
| Prop | Type | Default | Description |
|---|---|---|---|
position | CSSProperties["position"] | "absolute" | CSS positioning mode ("absolute", "fixed", or "relative"). |
gradient | GradientProps | {} | Configuration for the underlying linear gradient wash. |
dots | DotsProps | {} | Configuration for the procedural dot matrix pattern. |
grid | GridProps | {} | Configuration for the perpendicular grid lines. |
lines | LinesProps | {} | Configuration for the 45-degree repeating diagonal hatching lines. |
mask | MaskProps | {} | Configuration for the radial spotlight mask that follows cursor or fixed coords. |
className | string | undefined | Additional CSS classes for the container element. |
style | CSSProperties | undefined | Inline style overrides. |
children | ReactNode | undefined | Child elements rendered above background layers (ensure z-index if needed). |
MaskProps
| Property | Type | Default | Description |
|---|---|---|---|
cursor | boolean | false | Enables cursor tracking with smooth frame interpolation. |
x | number | undefined | Static X position percentage (used when cursor is false). |
y | number | undefined | Static Y position percentage (used when cursor is false). |
radius | number | string | 150px / 50vh | Radial radius of the spotlight (pixel value or CSS length unit). |
color | string | undefined | Center color of the radial glow (e.g. primary, #38bdf8, rgba(...)). |
gradient | string | undefined | Custom CSS radial-gradient(...) string to completely override mask styling. |
GradientProps
| Property | Type | Default | Description |
|---|---|---|---|
display | boolean | false | Whether to render the linear gradient layer. |
opacity | number | 50 | Opacity percentage from 0 to 100. |
tilt | number | 0 | Angle in degrees for the linear gradient direction. |
colorStart | string | transparent | Color token, hex code, or CSS variable for the gradient start. |
colorEnd | string | transparent | Color token, hex code, or CSS variable for the gradient end. |
GridProps
| Property | Type | Default | Description |
|---|---|---|---|
display | boolean | false | Whether to render the perpendicular grid lines. |
opacity | number | 100 | Opacity percentage from 0 to 100. |
color | string | "border" | Color token, hex code, or CSS variable for the grid lines. |
width | string | "32px" | Horizontal cell width of the grid pattern. |
height | string | "32px" | Vertical cell height of the grid pattern. |
DotsProps
| Property | Type | Default | Description |
|---|---|---|---|
display | boolean | false | Whether to render the dot matrix pattern. |
opacity | number | 30 | Opacity percentage from 0 to 100. |
color | string | "foreground" | Color token, hex code, or CSS variable for the dots. |
size | number | 1 | Radius in pixels of each rendered dot. |
LinesProps
| Property | Type | Default | Description |
|---|---|---|---|
display | boolean | false | Whether to render the 45-degree diagonal lines. |
opacity | number | 100 | Opacity percentage from 0 to 100. |
size | number | 16 | Spacing interval in pixels between repeating lines. |
color | string | "border" | Color token, hex code, or CSS variable for the hatching lines. |