Spotlight reveal
A soft circle of light follows the pointer and shows a second layer underneath: here, the hidden type specs behind a headline.
"use client";
import { useEffect, useRef, type ReactNode } from "react";
import "./spotlight-reveal.css";
type SpotlightRevealProps = {
/** What everyone sees. */
children: ReactNode;
/** The second layer, shown only inside the spotlight. Same size as children. */
reveal: ReactNode;
/** Spotlight radius in pixels. It grows by half while pressed. */
radius?: number;
/** Describes the area for keyboard and screen reader users. */
label?: string;
};
/**
* SpotlightReveal
* Two layers stacked exactly on top of each other. The top one is only
* visible through a soft circle that follows the pointer, a finger, or the
* arrow keys. Both layers stay in the page, so screen readers read both.
*/
export function SpotlightReveal({
children,
reveal,
radius = 110,
label = "Spotlight area. Use the arrow keys to move the light.",
}: SpotlightRevealProps) {
const area = useRef<HTMLDivElement>(null);
useEffect(() => {
const el = area.current;
if (!el) return;
const reduce = window.matchMedia(
"(prefers-reduced-motion: reduce)",
).matches;
const r = el.getBoundingClientRect();
// Start in the middle so visitors notice something is there.
const pos = { x: r.width / 2, y: r.height / 2, size: radius * 0.6 };
const goal = { ...pos };
let frame = 0;
const draw = () => {
frame = 0;
const k = reduce ? 1 : 0.18;
pos.x += (goal.x - pos.x) * k;
pos.y += (goal.y - pos.y) * k;
pos.size += (goal.size - pos.size) * k;
el.style.setProperty("--x", `${pos.x}px`);
el.style.setProperty("--y", `${pos.y}px`);
el.style.setProperty("--r", `${pos.size}px`);
const left =
Math.abs(goal.x - pos.x) +
Math.abs(goal.y - pos.y) +
Math.abs(goal.size - pos.size);
if (left > 0.3) frame = requestAnimationFrame(draw);
};
const kick = () => {
if (!frame) frame = requestAnimationFrame(draw);
};
draw();
const point = (e: PointerEvent) => {
const b = el.getBoundingClientRect();
goal.x = e.clientX - b.left;
goal.y = e.clientY - b.top;
if (goal.size < radius) goal.size = radius;
kick();
};
const press = (e: PointerEvent) => {
goal.size = radius * 1.5;
point(e);
};
const release = () => {
goal.size = radius;
kick();
};
const leave = () => {
goal.size = radius * 0.6;
kick();
};
const keys = (e: KeyboardEvent) => {
const step = e.shiftKey ? 80 : 28;
const b = el.getBoundingClientRect();
const moves: Record<string, [number, number]> = {
ArrowLeft: [-step, 0],
ArrowRight: [step, 0],
ArrowUp: [0, -step],
ArrowDown: [0, step],
};
const m = moves[e.key];
if (!m) return;
e.preventDefault();
goal.x = Math.min(b.width, Math.max(0, goal.x + m[0]));
goal.y = Math.min(b.height, Math.max(0, goal.y + m[1]));
goal.size = radius;
kick();
};
el.addEventListener("pointermove", point);
el.addEventListener("pointerdown", press);
el.addEventListener("pointerup", release);
el.addEventListener("pointerleave", leave);
el.addEventListener("keydown", keys);
return () => {
el.removeEventListener("pointermove", point);
el.removeEventListener("pointerdown", press);
el.removeEventListener("pointerup", release);
el.removeEventListener("pointerleave", leave);
el.removeEventListener("keydown", keys);
cancelAnimationFrame(frame);
};
}, [radius]);
return (
<div
ref={area}
className="gu-spot"
tabIndex={0}
role="group"
aria-label={label}
>
<div className="gu-spot__base">{children}</div>
<div className="gu-spot__reveal">{reveal}</div>
</div>
);
}
Paste this into ChatGPT, Claude, Cursor, v0, Lovable or Bolt. It describes the layout, motion, colors and accessibility and includes the code, so the AI can rebuild it in any framework.
# Build this UI piece: Spotlight reveal
You are a senior front-end engineer. Recreate the piece below in my project. If I don't say which framework I use, ask once, then build it in that framework (React, Vue, Svelte, Angular, Astro, plain HTML/CSS/JS or anything else). Keep the behavior, motion, colors, spacing and accessibility exactly as described. Keep the code clean and commented for beginners.
## What it is
Two layers stacked exactly on top of each other. The top layer is only visible through a soft circle of light that follows the pointer, a finger or the arrow keys. The demo uses it to show the hidden type specs behind a headline: point at the dark headline and a blueprint version shows through, with its weight, line height and tracking written above it.
## Behavior
- Both layers share one grid cell, so they are always the same size.
- The reveal layer is masked by radial-gradient(circle var(--r) at var(--x) var(--y), #000 92%, transparent 100%): solid inside the circle with a short soft edge.
- A requestAnimationFrame loop eases x, y and the radius toward their goals by 18% per frame, and stops when they arrive.
- It starts in the centre at 60% of the radius so people notice it. Pointer move: radius 100%. Pressing: 150%. Leaving: back to 60%.
- Arrow keys move the light 28px (80px with Shift), clamped to the area.
## Look
- Demo base layer: ink #0e0e10, cream headline at up to 4.6rem, weight 900, line-height 0.92, tracking −0.05em, max 11ch, and a muted hint line.
- Demo reveal layer: ultramarine #2b35ff with a 24px cream grid at 16%, a monospace spec line, and the same headline as a 1.5px cream outline (transparent fill).
- The mouse pointer is hidden inside the area (the light is the cursor); on touch screens nothing is hidden.
## Accessibility
- The area is focusable (tabIndex 0), role="group" with a label that explains the arrow keys. Focus ring: 2px lime #d7ff3a.
- Both layers stay in the page, so screen readers read both.
- touch-action: pan-y, so a vertical swipe still scrolls the page while a tap or a sideways drag moves the light.
- prefers-reduced-motion: the light follows directly, with no easing.
## Props
children (base layer), reveal (top layer), radius (px, default 110), label.
## Reference implementation
The original is written in React with one plain CSS file. Dependencies: none (plain React and CSS). Translate it faithfully; do not add new libraries unless my framework needs them.
### SpotlightReveal.tsx
```tsx
"use client";
import { useEffect, useRef, type ReactNode } from "react";
import "./spotlight-reveal.css";
type SpotlightRevealProps = {
/** What everyone sees. */
children: ReactNode;
/** The second layer, shown only inside the spotlight. Same size as children. */
reveal: ReactNode;
/** Spotlight radius in pixels. It grows by half while pressed. */
radius?: number;
/** Describes the area for keyboard and screen reader users. */
label?: string;
};
/**
* SpotlightReveal
* Two layers stacked exactly on top of each other. The top one is only
* visible through a soft circle that follows the pointer, a finger, or the
* arrow keys. Both layers stay in the page, so screen readers read both.
*/
export function SpotlightReveal({
children,
reveal,
radius = 110,
label = "Spotlight area. Use the arrow keys to move the light.",
}: SpotlightRevealProps) {
const area = useRef<HTMLDivElement>(null);
useEffect(() => {
const el = area.current;
if (!el) return;
const reduce = window.matchMedia(
"(prefers-reduced-motion: reduce)",
).matches;
const r = el.getBoundingClientRect();
// Start in the middle so visitors notice something is there.
const pos = { x: r.width / 2, y: r.height / 2, size: radius * 0.6 };
const goal = { ...pos };
let frame = 0;
const draw = () => {
frame = 0;
const k = reduce ? 1 : 0.18;
pos.x += (goal.x - pos.x) * k;
pos.y += (goal.y - pos.y) * k;
pos.size += (goal.size - pos.size) * k;
el.style.setProperty("--x", `${pos.x}px`);
el.style.setProperty("--y", `${pos.y}px`);
el.style.setProperty("--r", `${pos.size}px`);
const left =
Math.abs(goal.x - pos.x) +
Math.abs(goal.y - pos.y) +
Math.abs(goal.size - pos.size);
if (left > 0.3) frame = requestAnimationFrame(draw);
};
const kick = () => {
if (!frame) frame = requestAnimationFrame(draw);
};
draw();
const point = (e: PointerEvent) => {
const b = el.getBoundingClientRect();
goal.x = e.clientX - b.left;
goal.y = e.clientY - b.top;
if (goal.size < radius) goal.size = radius;
kick();
};
const press = (e: PointerEvent) => {
goal.size = radius * 1.5;
point(e);
};
const release = () => {
goal.size = radius;
kick();
};
const leave = () => {
goal.size = radius * 0.6;
kick();
};
const keys = (e: KeyboardEvent) => {
const step = e.shiftKey ? 80 : 28;
const b = el.getBoundingClientRect();
const moves: Record<string, [number, number]> = {
ArrowLeft: [-step, 0],
ArrowRight: [step, 0],
ArrowUp: [0, -step],
ArrowDown: [0, step],
};
const m = moves[e.key];
if (!m) return;
e.preventDefault();
goal.x = Math.min(b.width, Math.max(0, goal.x + m[0]));
goal.y = Math.min(b.height, Math.max(0, goal.y + m[1]));
goal.size = radius;
kick();
};
el.addEventListener("pointermove", point);
el.addEventListener("pointerdown", press);
el.addEventListener("pointerup", release);
el.addEventListener("pointerleave", leave);
el.addEventListener("keydown", keys);
return () => {
el.removeEventListener("pointermove", point);
el.removeEventListener("pointerdown", press);
el.removeEventListener("pointerup", release);
el.removeEventListener("pointerleave", leave);
el.removeEventListener("keydown", keys);
cancelAnimationFrame(frame);
};
}, [radius]);
return (
<div
ref={area}
className="gu-spot"
tabIndex={0}
role="group"
aria-label={label}
>
<div className="gu-spot__base">{children}</div>
<div className="gu-spot__reveal">{reveal}</div>
</div>
);
}
```
### spotlight-reveal.css
```css
.gu-spot {
position: relative;
display: grid;
overflow: hidden;
/* Vertical swipes still scroll the page; taps and sideways drags move the light. */
touch-action: pan-y;
cursor: none;
border-radius: inherit;
}
.gu-spot:focus-visible {
outline: 2px solid #d7ff3a;
outline-offset: 3px;
}
/* Both layers share one grid cell, so they are always the same size. */
.gu-spot__base,
.gu-spot__reveal {
grid-area: 1 / 1;
}
/* A soft-edged hole: solid to 92% of the radius, then a short fade. */
.gu-spot__reveal {
-webkit-mask-image: radial-gradient(
circle var(--r, 0px) at var(--x, 50%) var(--y, 50%),
#000 92%,
transparent 100%
);
mask-image: radial-gradient(
circle var(--r, 0px) at var(--x, 50%) var(--y, 50%),
#000 92%,
transparent 100%
);
}
/* On touch screens there is no pointer to hide. */
@media (hover: none) {
.gu-spot {
cursor: auto;
}
}
```
You might also want
Next piece: Stacked toastsCursor trail
Animations, intermediate
Dot ripple field
Animations, intermediate
Letter scatter headline
Animations, beginner