Spotlight cards
A row of cards lit by a soft spotlight that follows the cursor across all of them, borders included.
"use client";
import { useRef, type PointerEvent, type ReactNode } from "react";
import "./spotlight-cards.css";
export type SpotlightItem = { title: string; text: string; icon?: ReactNode };
type SpotlightCardsProps = {
items: SpotlightItem[];
theme?: "light" | "dark";
};
/**
* SpotlightCards
* One pointer listener on the grid writes the pointer position into each card
* as CSS variables (--x, --y). CSS then paints a radial light at that spot,
* on the card face AND on its border, so light "spills" between cards.
*/
export function SpotlightCards({
items,
theme = "light",
}: SpotlightCardsProps) {
const grid = useRef<HTMLDivElement>(null);
const onMove = (e: PointerEvent<HTMLDivElement>) => {
const cards = grid.current?.querySelectorAll<HTMLElement>(".gu-spot__card");
cards?.forEach((card) => {
const r = card.getBoundingClientRect();
card.style.setProperty("--x", `${e.clientX - r.left}px`);
card.style.setProperty("--y", `${e.clientY - r.top}px`);
});
grid.current?.setAttribute("data-active", "");
};
// Move the light off-screen when the pointer leaves.
const onLeave = () => {
grid.current
?.querySelectorAll<HTMLElement>(".gu-spot__card")
.forEach((card) => {
card.style.removeProperty("--x");
card.style.removeProperty("--y");
});
grid.current?.removeAttribute("data-active");
};
return (
<div
ref={grid}
className="gu-spot"
data-theme={theme}
onPointerMove={onMove}
onPointerLeave={onLeave}
>
{items.map((item) => (
<article key={item.title} className="gu-spot__card">
<div className="gu-spot__inner">
{item.icon && <div className="gu-spot__icon">{item.icon}</div>}
<h3 className="gu-spot__title">{item.title}</h3>
<p className="gu-spot__text">{item.text}</p>
</div>
</article>
))}
</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 cards
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
A responsive grid of feature cards lit by one shared spotlight. As the mouse moves anywhere over the grid, a soft radial light appears under the pointer on every card's face and its 1px border, so the light spills across neighboring cards.
## Layout and look
- Grid: auto-fit columns, each at least 220px, gap 14px, max width 860px.
- Card: 22px radius, 1px border (rgba(14,14,16,0.12) light / rgba(243,238,227,0.1) dark), face #ffffff light / #16171d dark, padding 28px 24px 30px.
- Each card: 44px icon tile (12px radius, background #ff5a1f, icon color #0e0e10, 22px icon), 40px gap, then a 19px bold title (letter-spacing -0.02em) and a 15px muted paragraph (#555a66 light / #a3a8b4 dark, line-height 1.5).
## Behavior and motion
- A single pointermove listener on the grid writes the pointer position relative to EACH card into CSS variables --x and --y.
- The border is made by giving the card 1px padding and a background of: radial-gradient(260px circle at --x --y, rgba(255,90,31,0.9), transparent 70%) over the border color.
- The inner face has background: radial-gradient(420px circle at --x --y, rgba(255,90,31,0.14), transparent 65%) over the face color.
- When the pointer leaves the grid, move the light off-screen (-500px).
## Touch
On devices without hover, run a 6s infinite ease-in-out sweep that animates --x from -20% to 120% and --y from 10% to 90% and back (register --x and --y with @property so they animate). Touch moves still drive the light while the finger is down.
## Accessibility
- Cards are <article> elements with <h3> titles; icons are aria-hidden.
- prefers-reduced-motion: no sweep; the light rests at the top-left corner.
## 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.
### SpotlightCards.tsx
```tsx
"use client";
import { useRef, type PointerEvent, type ReactNode } from "react";
import "./spotlight-cards.css";
export type SpotlightItem = { title: string; text: string; icon?: ReactNode };
type SpotlightCardsProps = {
items: SpotlightItem[];
theme?: "light" | "dark";
};
/**
* SpotlightCards
* One pointer listener on the grid writes the pointer position into each card
* as CSS variables (--x, --y). CSS then paints a radial light at that spot,
* on the card face AND on its border, so light "spills" between cards.
*/
export function SpotlightCards({
items,
theme = "light",
}: SpotlightCardsProps) {
const grid = useRef<HTMLDivElement>(null);
const onMove = (e: PointerEvent<HTMLDivElement>) => {
const cards = grid.current?.querySelectorAll<HTMLElement>(".gu-spot__card");
cards?.forEach((card) => {
const r = card.getBoundingClientRect();
card.style.setProperty("--x", `${e.clientX - r.left}px`);
card.style.setProperty("--y", `${e.clientY - r.top}px`);
});
grid.current?.setAttribute("data-active", "");
};
// Move the light off-screen when the pointer leaves.
const onLeave = () => {
grid.current
?.querySelectorAll<HTMLElement>(".gu-spot__card")
.forEach((card) => {
card.style.removeProperty("--x");
card.style.removeProperty("--y");
});
grid.current?.removeAttribute("data-active");
};
return (
<div
ref={grid}
className="gu-spot"
data-theme={theme}
onPointerMove={onMove}
onPointerLeave={onLeave}
>
{items.map((item) => (
<article key={item.title} className="gu-spot__card">
<div className="gu-spot__inner">
{item.icon && <div className="gu-spot__icon">{item.icon}</div>}
<h3 className="gu-spot__title">{item.title}</h3>
<p className="gu-spot__text">{item.text}</p>
</div>
</article>
))}
</div>
);
}
```
### spotlight-cards.css
```css
/* SpotlightCards: edit these variables to restyle. */
.gu-spot {
--card: #ffffff;
--text: #0e0e10;
--muted: #555a66;
--border: rgb(14 14 16 / 0.12);
--light: rgb(255 90 31 / 0.9); /* border highlight */
--glow: rgb(255 90 31 / 0.14); /* face glow */
--radius: 22px;
display: grid;
grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
gap: 14px;
width: min(100%, 860px);
font-family: system-ui, sans-serif;
}
.gu-spot[data-theme="dark"] {
--card: #16171d;
--text: #f3eee3;
--muted: #a3a8b4;
--border: rgb(243 238 227 / 0.1);
--glow: rgb(255 90 31 / 0.16);
}
/* Border trick: the card itself is the 1px "border", painted with the light. */
.gu-spot__card {
--x: -500px;
--y: -500px;
position: relative;
padding: 1px;
border-radius: var(--radius);
background:
radial-gradient(
260px circle at var(--x) var(--y),
var(--light),
transparent 70%
),
var(--border);
}
.gu-spot__inner {
position: relative;
height: 100%;
padding: 28px 24px 30px;
border-radius: calc(var(--radius) - 1px);
background:
radial-gradient(
420px circle at var(--x) var(--y),
var(--glow),
transparent 65%
),
var(--card);
}
.gu-spot__icon {
display: grid;
place-items: center;
width: 44px;
height: 44px;
margin-bottom: 40px;
border-radius: 12px;
background: #ff5a1f;
color: #0e0e10;
}
.gu-spot__icon svg {
width: 22px;
height: 22px;
}
.gu-spot__title {
margin: 0 0 8px;
color: var(--text);
font-size: 1.2rem;
font-weight: 700;
letter-spacing: -0.02em;
}
.gu-spot__text {
margin: 0;
color: var(--muted);
font-size: 0.95rem;
line-height: 1.5;
}
/* Touch screens: a slow light sweep keeps the cards alive. */
@media (hover: none) {
.gu-spot:not([data-active]) .gu-spot__card {
animation: gu-spot-sweep 6s ease-in-out infinite;
}
}
@keyframes gu-spot-sweep {
0%,
100% {
--x: -20%;
--y: 10%;
}
50% {
--x: 120%;
--y: 90%;
}
}
/* Lets the sweep animate the custom properties smoothly. */
@property --x {
syntax: "<length-percentage>";
inherits: true;
initial-value: -500px;
}
@property --y {
syntax: "<length-percentage>";
inherits: true;
initial-value: -500px;
}
@media (prefers-reduced-motion: reduce) {
.gu-spot .gu-spot__card {
animation: none !important;
--x: 0px !important;
--y: 0px !important;
}
}
```
You might also want
Next piece: Spotlight reveal3D tilt card
Components, intermediate
Depth cards hero
Components, intermediate
Expanding image accordion
Components, beginner