Cards
SpotlightCard
A soft light follows the pointer across the card and lights its border on the way.
Download
- React
- Tailwind CSS v4
components/ui/spotlight-card.tsx
"use client";
import { useRef, type CSSProperties, type ReactNode } from "react";
type SpotlightCardProps = {
children: ReactNode;
className?: string;
/** Colour of the light. Any CSS colour. */
color?: string;
/** Size of the light on the border, in pixels. */
size?: number;
/** Card fill. */
background?: string;
/** Border colour where the light is not. */
border?: string;
};
/* SpotlightCard: a soft light follows the pointer across the card and its border. */
export function SpotlightCard({
children,
className = "",
color = "#34f5c5",
size = 240,
background = "#0a1714",
border = "#1a2a27",
}: SpotlightCardProps) {
const ref = useRef<HTMLDivElement>(null);
const onMove = (e: React.PointerEvent<HTMLDivElement>) => {
const el = ref.current;
if (!el) return;
const r = el.getBoundingClientRect();
el.style.setProperty("--x", `${e.clientX - r.left}px`);
el.style.setProperty("--y", `${e.clientY - r.top}px`);
};
return (
<div
ref={ref}
onPointerMove={onMove}
className={`relative rounded-2xl p-px ${className}`}
style={
{
"--x": "50%",
"--y": "0%",
background: `radial-gradient(${size}px circle at var(--x) var(--y), ${color}, transparent 60%), ${border}`,
} as CSSProperties
}
>
<div
className="relative h-full rounded-[15px] p-6"
style={{
background: `radial-gradient(${size * 1.25}px circle at var(--x) var(--y), color-mix(in srgb, ${color} 12%, transparent), transparent 60%), ${background}`,
}}
>
{children}
</div>
</div>
);
}
1. Paste the Code tab into
components/ui/spotlight-card.tsx. The styles are Tailwind CSS v4 classes.2. Use it. This is the preview above:
app/spotlight-card-demo.tsx
import { SpotlightCard } from "@/components/ui/spotlight-card"; export default function SpotlightCardExample() { return ( <div className="grid h-full place-items-center bg-[#06110f] p-6"> <SpotlightCard className="w-full max-w-[300px]"> <p className="font-mono text-[11px] uppercase tracking-[0.2em] text-[#34f5c5]">Uptime</p> <p className="mt-3 text-4xl font-semibold text-[#d7f7ee]">99.98%</p> <p className="mt-2 text-sm text-[#8fb5ab]">Move your pointer across the card.</p> </SpotlightCard> </div> ); }
Props
| Name | Type | Default | What it does |
|---|---|---|---|
| children | ReactNode | — | Card content. |
| color | string | "#34f5c5" | Colour of the light. Any CSS colour. |
| size | number | 240 | Size of the light on the border, in pixels. |
| background | string | "#0a1714" | Card fill. |
| border | string | "#1a2a27" | Border colour where the light is not. |
| className | string | "" | Size and placement of the card. |