Cursor Spotlight for React

Cursor spotlight effect. Dimmed background with bright radial gradient following cursor.

Component

Installation

 

Usage

Import

Add the CursorSpotlight import.

import { CursorSpotlight } from "@/components/cursor-spotlight";

Use

Wrap content. Spotlight follows cursor.

<CursorSpotlight>Content</CursorSpotlight>;

Guidelines

  • Wrap content as children. Spotlight follows cursor within the container.
  • spotlightSize and spotlightOpacity control the effect.
  • baseColor sets the dimmed background color.

Props

All props are optional unless marked required. Use these to customize every aspect of the component.

PropTypeDefaultDescription
classNamestring-Additional CSS classes for the container.
spotlightSizenumber100Spotlight radius in pixels.
spotlightOpacitynumber0.25Spotlight opacity (0–1).
baseColorstring"rgb(2 6 23)"Base dimmed background color.
falloffstring"60%"Gradient falloff (e.g. '60%' = transparent at 60% from center).
childrenClassNamestring-Classes for the children wrapper.

Accessibility

  • Decorative visual effect with no interactive controls or focusable elements; the wrapper is marked role img and aria-hidden true so the spotlight layer is skipped by assistive technology.
  • The effect is driven entirely by mouse position with no keyboard handler, so keyboard-only users see only the static dimmed background and never trigger the spotlight.
  • Any meaningful content passed as children is rendered in a normal relative div and stays in the accessibility tree, but authors should ensure that content has sufficient contrast against the dimmed base color.
  • The component does not check prefers-reduced-motion, so it should be guarded for users who prefer reduced motion by disabling the opacity fade and cursor tracking when that media query matches.

Performance

  • The visible reveal animates only opacity via a 150ms transition, which is a cheap GPU-compositable property that does not trigger layout.
  • Every mousemove rebuilds the radial-gradient background string in an inline style, forcing a continuous paint of the full-size layer that is not GPU-compositable and is the main cost of the effect.
  • Cursor tracking updates React state on each mousemove, causing a re-render per event rather than batching through requestAnimationFrame, so rapid movement over a large container can be paint and render heavy.
  • It uses React synthetic onMouseMove and onMouseLeave handlers with no manually attached listeners or timers, so there is nothing to clean up and no leak risk.
  • There is no IntersectionObserver, will-change, or visibility gating, so the spotlight layer keeps repainting whenever the pointer is inside the container regardless of whether it is in view.

Examples

Basic

Basic spotlight container.

import { CursorSpotlight } from "@/components/cursor-spotlight";

<CursorSpotlight className="h-48 rounded-2xl border">
  <div className="flex h-full items-center justify-center">
    <span className="text-sm text-white/50">
      Move cursor for spotlight
    </span>
  </div>
</CursorSpotlight>;

Last updated on Jun 19

Made with ❤️ by Pulkit &

© 2026 Pulkit. All rights reserved

Last updated: