Cursor Spotlight
鼠标聚光
A soft pool of light follows the pointer inside a surface and fades on exit.
Where to use it
Highlight a feature card or a dark hero surface while keeping its content readable. Keep the glow muted behind text and clip it to the card so adjacent controls stay visually stable.
Practical example
In a photo editing app's feature grid, a cool glow follows the pointer across the noise reduction card. It draws attention to the active card while its title and icon stay fixed.
Also called
- Pointer Spotlight
AI prompt
Add Cursor Spotlight inside [target surface]. Set the center of a low-opacity radial gradient from pointer coordinates within the element, clip the glow at its edges, and fade it on pointer leave. Keep the overlay behind the content and let pointer events reach the controls. Use a stationary highlight for touch or reduced motion.
Example code
Save the standalone HTML as a file and open it in your browser. It uses the same code as the preview.
View HTML
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Cursor Spotlight</title>
<style>
:root {
color-scheme: dark;
--demo-bg: #171629;
--demo-ink: #f8f5ff;
--demo-accent: #b9a6ff;
--demo-muted: #bfbbd3;
font-family: system-ui, sans-serif;
color: var(--demo-ink);
background: var(--demo-bg);
}
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; min-width: 0; }
button, input { font: inherit; }
.demo {
display: grid;
place-items: center;
align-content: center;
min-height: 100vh;
padding: 14px;
overflow: hidden;
background: radial-gradient(ellipse at 50% 24%, #28233f, var(--demo-bg) 78%);
}
.demo-button {
border: 1px solid #ffffff3d;
border-radius: 7px;
background: #ffffff12;
color: var(--demo-ink);
padding: 6px 11px;
font-size: 12px;
cursor: pointer;
}
:focus-visible {
outline: 2px solid var(--demo-accent);
outline-offset: 3px;
}
.spotlight {
position: relative;
isolation: isolate;
display: grid;
align-content: center;
justify-items: center;
gap: 6px;
width: min(100%, 242px);
min-height: 108px;
padding: 12px;
overflow: hidden;
color: #eee6ff;
background:
linear-gradient(90deg, #c4afff1c 1px, transparent 1px),
linear-gradient(#c4afff1c 1px, transparent 1px),
#241c3a;
background-size: 18px 18px;
border: 1px solid #645484;
border-radius: 13px;
font: inherit;
cursor: pointer;
}
.spotlight::before {
position: absolute;
z-index: -1;
inset: 0;
opacity: 0.48;
background: radial-gradient(100px circle at var(--light-x, 50%) var(--light-y, 50%), #c79dffb5, transparent 95%);
content: "";
transition: opacity 180ms ease;
}
.spotlight:is(:focus-visible, [aria-pressed="true"])::before { opacity: 1; }
@media (hover: hover) { .spotlight:hover::before { opacity: 1; } }
.spotlight-mark { color: #fff3d0; font-size: 26px; line-height: 1; }
.spotlight strong { font-size: 12px; }
@media (prefers-reduced-motion: reduce) {
.spotlight::before { transition: none; }
}
</style>
</head>
<body>
<main class="demo">
<button class="spotlight" type="button" aria-pressed="false">
<span class="spotlight-mark" aria-hidden="true">✦</span>
<strong>Spotlight</strong>
</button>
</main>
<script>
const card = document.querySelector(".spotlight");
const reduceMotion = window.matchMedia("(prefers-reduced-motion: reduce)");
card.addEventListener("pointermove", (event) => {
if (event.pointerType === "touch" || reduceMotion.matches) return;
const { left, top } = card.getBoundingClientRect();
card.style.setProperty("--light-x", (event.clientX - left) + "px");
card.style.setProperty("--light-y", (event.clientY - top) + "px");
});
function resetSpotlight() {
card.style.removeProperty("--light-x");
card.style.removeProperty("--light-y");
}
card.addEventListener("pointerleave", resetSpotlight);
card.addEventListener("pointercancel", resetSpotlight);
reduceMotion.addEventListener("change", resetSpotlight);
card.addEventListener("click", () => {
const lit = card.getAttribute("aria-pressed") === "true";
card.setAttribute("aria-pressed", String(!lit));
});
</script>
</body>
</html>Original example by UI Skills