Move your cursor
Customize
Usage
import { DotGlowBackground } from "@/components/motionkit/dot-glow-background";
<DotGlowBackground className="h-80 rounded-2xl">
<p>Move your cursor</p>
</DotGlowBackground>Motion
The exact curves this component runs, plotted with Motion's own maths.
Glow follow
Pointer moves over the area
Works in the App Router as is. Requires Tailwind CSS v4.
npm install motionSave as components/motionkit/dot-glow-background.tsx.
"use client";
import type { ReactNode, PointerEvent } from "react";
import { motion, useMotionTemplate, useMotionValue, useReducedMotion, useSpring } from "motion/react";
type DotGlowBackgroundProps = {
children?: ReactNode;
/** Distance between dots in pixels. */
gap?: number;
/** Radius of the lit area around the pointer. */
radius?: number;
className?: string;
};
export function DotGlowBackground({
children,
gap = 20,
radius = 180,
className = "",
}: DotGlowBackgroundProps) {
const reduceMotion = useReducedMotion();
const x = useMotionValue(-1000);
const y = useMotionValue(-1000);
// the glow eases after the pointer, unless the user prefers reduced motion
const smoothX = useSpring(x, { stiffness: 300, damping: 40 });
const smoothY = useSpring(y, { stiffness: 300, damping: 40 });
const glowX = reduceMotion ? x : smoothX;
const glowY = reduceMotion ? y : smoothY;
const mask = useMotionTemplate`radial-gradient(${radius}px circle at ${glowX}px ${glowY}px, black, transparent)`;
const dots = (color: string) => ({
backgroundImage: `radial-gradient(${color} 1px, transparent 1px)`,
backgroundSize: `${gap}px ${gap}px`,
});
function handleMove(event: PointerEvent<HTMLDivElement>) {
const rect = event.currentTarget.getBoundingClientRect();
x.set(event.clientX - rect.left);
y.set(event.clientY - rect.top);
}
return (
<div
onPointerMove={handleMove}
onPointerLeave={() => {
x.set(-1000);
y.set(-1000);
}}
className={`relative isolate overflow-hidden bg-[#0C1010] ${className}`}
>
<div aria-hidden className="absolute inset-0 -z-10" style={dots("rgb(255 255 255 / 0.09)")} />
<motion.div
aria-hidden
className="absolute inset-0 -z-10"
style={{ ...dots("rgb(95 174 180)"), maskImage: mask, WebkitMaskImage: mask }}
/>
{children}
</div>
);
}
| Prop | Type | Default | Description |
|---|---|---|---|
| gap | number | 20 | Distance between dots in pixels. |
| radius | number | 180 | Radius of the lit area around the pointer. |
You're on
Stage Light
A cone of light from above that sways gently and turns to follow the pointer.
To infinity
Infinite Perspective Grid
A true 3D floor of glowing lines that recedes forever to a lit horizon, with an optional ceiling for a tunnel.
Fast
Secure
Global
Typed
Spotlight Grid
One soft beam follows the pointer across a grid, lighting the borders and faces of the cards it passes.