Dot Spotlight
A dot grid background with a subtle cursor spotlight for React: a small light follows the mouse and brightens only the dots beneath it, with no color wash. Built with Motion values and a CSS mask, so it never re-renders, and it rests dimly in the center on touch screens.
- Background
- Dot grid
- Cursor spotlight
- Motion values
- Touch fallback
Find slow requests faster
Traces, logs and metrics for every endpoint, in one view.
import { DotSpotlight } from "@/components/dusk/backgrounds/dot-spotlight";
export default function DotSpotlightDemo() {
return (
<div className="relative flex h-80 w-full items-center justify-center overflow-hidden rounded-xl border border-white/10 bg-background">
<DotSpotlight />
<div className="relative px-6 text-center">
<h3 className="text-3xl font-semibold tracking-tight text-white sm:text-4xl">Find slow requests faster</h3>
<p className="mx-auto mt-2 max-w-sm text-sm leading-relaxed text-white/60">Traces, logs and metrics for every endpoint, in one view.</p>
</div>
</div>
);
}Installation
$ npx shadcn@latest add https://duskui.com/r/dot-spotlight.json1. Install the dependencies.
npm install motion2. Copy the source into
components/dusk/backgrounds/dot-spotlight.tsx.dot-spotlight.tsx "use client"; import * as React from "react"; import { motion, useMotionTemplate, useMotionValue, useReducedMotion, useSpring, } from "motion/react"; import { cn } from "@/lib/utils"; export interface DotSpotlightProps extends React.ComponentProps<"div"> { /** Color of the dots the spotlight lights up. Defaults to a soft white. */ color?: string; /** Color of the resting dots. */ dotColor?: string; /** Distance between dots in px. */ gap?: number; /** Dot radius in px. */ dotSize?: number; /** Radius of the spotlight in px. */ radius?: number; /** Fade the pattern out toward the edges. */ fade?: boolean; } /** Brightness of the spotlight while it rests in the center (touch, reduced motion, cursor away). */ const IDLE = 0.4; const dots = (color: string, r: number) => `radial-gradient(circle at center, ${color} ${r}px, transparent ${r + 0.75}px)`; /** * A dot-grid background where a small, soft spotlight follows the cursor and * brightens only the dots beneath it. No color wash: the light lives in the * dots. Fills its nearest positioned parent. * * The light is a CSS mask driven by spring-smoothed motion values, so moving * the cursor never re-renders React. On touch screens, under reduced motion, * or when the cursor leaves, the light rests dimly in the center. */ export function DotSpotlight({ color = "rgb(255 255 255 / 0.4)", dotColor = "rgb(255 255 255 / 0.1)", gap = 20, dotSize = 1.25, radius = 160, fade = true, className, style, ...props }: DotSpotlightProps) { const reduceMotion = useReducedMotion(); const rootRef = React.useRef<HTMLDivElement>(null); // Position in percent of the container, so the server can render the centered resting state. const mx = useMotionValue(50); const my = useMotionValue(50); const lit = useMotionValue(IDLE); const sx = useSpring(mx, { stiffness: 220, damping: 30 }); const sy = useSpring(my, { stiffness: 220, damping: 30 }); const sLit = useSpring(lit, { stiffness: 160, damping: 26 }); const mask = useMotionTemplate`radial-gradient(${radius}px circle at ${sx}% ${sy}%, #000, transparent)`; React.useEffect(() => { const root = rootRef.current; if (!root || reduceMotion) return; // Only devices with a real hover pointer get a moving light. if (!window.matchMedia("(hover: hover) and (pointer: fine)").matches) return; let inView = true; const rest = () => { mx.set(50); my.set(50); lit.set(IDLE); }; const onMove = (event: PointerEvent) => { if (event.pointerType !== "mouse" || !inView || document.hidden) return; const rect = root.getBoundingClientRect(); const x = event.clientX - rect.left; const y = event.clientY - rect.top; if (x < 0 || y < 0 || x > rect.width || y > rect.height || !rect.width || !rect.height) { rest(); return; } mx.set((x / rect.width) * 100); my.set((y / rect.height) * 100); lit.set(1); }; const observer = new IntersectionObserver(([entry]) => { inView = entry.isIntersecting; if (!inView) rest(); }); observer.observe(root); window.addEventListener("pointermove", onMove, { passive: true }); document.documentElement.addEventListener("pointerleave", rest); return () => { observer.disconnect(); window.removeEventListener("pointermove", onMove); document.documentElement.removeEventListener("pointerleave", rest); rest(); }; }, [reduceMotion, mx, my, lit]); const tile = `${gap}px ${gap}px`; return ( <div ref={rootRef} aria-hidden data-slot="dot-spotlight" className={cn( "pointer-events-none absolute inset-0 overflow-hidden", fade && "[mask-image:radial-gradient(ellipse_at_center,#000_45%,transparent_90%)]", className )} style={style} {...props} > <div className="absolute inset-0" style={{ backgroundImage: dots(dotColor, dotSize), backgroundSize: tile, backgroundPosition: "center" }} /> <motion.div className="absolute inset-0" style={{ backgroundImage: dots(color, dotSize), backgroundSize: tile, backgroundPosition: "center", maskImage: mask, WebkitMaskImage: mask, opacity: sLit, }} /> </div> ); }
The pattern fills its nearest positioned parent, so give the parent relative and overflow-hidden, and put your content after it with relative so it sits on top. The cursor is tracked on the window, so content on top stays fully interactive.
Usage
import { DotSpotlight } from "@/components/dusk/backgrounds/dot-spotlight"
export function Hero() {
return (
<section className="relative overflow-hidden">
<DotSpotlight />
<div className="relative">{/* your content */}</div>
</section>
)
}Examples
Grid & color
gap and dotSize shape the grid, radius sizes the light, and color sets the lit dots. Keep it low-alpha so the light stays subtle.
import { DotSpotlight } from "@/components/dusk/backgrounds/dot-spotlight";
const variants = [
{ label: "gap={14} dotSize={1}", props: { gap: 14, dotSize: 1, radius: 120 } },
{ label: "gap={28} dotSize={1.5}", props: { gap: 28, dotSize: 1.5, color: "rgb(196 181 253 / 0.45)" } },
];
export default function DotSpotlightCustom() {
return (
<div className="grid w-full gap-4 sm:grid-cols-2">
{variants.map((variant) => (
<div
key={variant.label}
className="relative flex h-56 items-end overflow-hidden rounded-xl border border-white/10 bg-background p-4"
>
<DotSpotlight {...variant.props} />
<span className="relative font-mono text-xs text-white/70">{variant.label}</span>
</div>
))}
</div>
);
}Behind a feature grid
Turn off fade to run the pattern edge to edge behind cards; the light still follows the cursor through them.
Fast
p99 under 40 ms.
Secure
Encrypted end to end.
Observable
Traces on every call.
import { Activity, Gauge, ShieldCheck } from "lucide-react";
import { DotSpotlight } from "@/components/dusk/backgrounds/dot-spotlight";
const features = [
{ icon: Gauge, title: "Fast", text: "p99 under 40 ms." },
{ icon: ShieldCheck, title: "Secure", text: "Encrypted end to end." },
{ icon: Activity, title: "Observable", text: "Traces on every call." },
];
export default function DotSpotlightFeatures() {
return (
<div className="relative w-full overflow-hidden rounded-xl border border-white/10 bg-background p-6">
<DotSpotlight fade={false} />
<div className="relative grid gap-3 sm:grid-cols-3">
{features.map(({ icon: Icon, title, text }) => (
<div key={title} className="rounded-xl border border-white/10 bg-card/80 p-4 backdrop-blur-sm">
<Icon className="size-5 text-white/60" aria-hidden />
<p className="mt-3 font-medium text-white">{title}</p>
<p className="text-sm text-white/60">{text}</p>
</div>
))}
</div>
</div>
);
}API Reference
Any other div prop is passed to the root. The spotlight position is spring-smoothed and stored in percent of the container, so the server renders the centered resting state.
| Prop | Type | Default | Description |
|---|---|---|---|
| color | string | "rgb(255 255 255 / 0.4)" | Color of the lit dots. |
| dotColor | string | "rgb(255 255 255 / 0.1)" | Color of the resting dots. |
| gap | number | 20 | Distance between dots in px. |
| dotSize | number | 1.25 | Dot radius in px. |
| radius | number | 160 | Radius of the spotlight in px. |
| fade | boolean | true | Fade the pattern out toward the edges. |
| className | string | — | Merged onto the absolutely positioned root. |
Accessibility
- The pattern is decorative: it is
aria-hiddenandpointer-events-none, so it never reaches screen readers or blocks clicks. - On touch screens and with prefers-reduced-motion the light rests, dim and still, in the center.
- Pointer tracking is skipped while the pattern is off-screen or the tab is hidden.
- The effect is pure decoration; never rely on it to reveal content.