[Lab 04]AWAIS MALIK
Spotlight card
A soft light follows the pointer across a card and lights up its border, driven by two CSS variables.
- CSS Variables
- Vanilla JS
- No dependencies
Jump to the code ↓04 / 04
Live — hover me
Featured // 01
Radial spotlight
Move your pointer around the card to light up its border and surface.
Explore component →index.html9 lines
<div class="spotlight-card" data-spotlight>
<div class="spotlight-border" aria-hidden="true"></div>
<div class="spotlight-content">
<span class="spotlight-badge">FEATURED // 01</span>
<h3 class="spotlight-title">Radial Spotlight</h3>
<p class="spotlight-text">Move your cursor around the card to illuminate the border and surface with a reactive CSS radial gradient.</p>
<span class="spotlight-link">Explore component →</span>
</div>
</div>spotlight.css72 lines
.spotlight-card {
position: relative;
width: 100%;
max-width: 400px;
padding: 1px;
background: rgba(241, 240, 232, 0.12);
border-radius: 8px;
overflow: hidden;
--x: 50%;
--y: 50%;
}
.spotlight-border {
position: absolute;
inset: 0;
pointer-events: none;
background: radial-gradient(
220px circle at var(--x) var(--y),
rgba(214, 255, 59, 0.8),
transparent 70%
);
opacity: 0;
transition: opacity 0.3s ease;
}
.spotlight-card:hover .spotlight-border {
opacity: 1;
}
.spotlight-content {
position: relative;
padding: 2.25rem 2rem;
background: #0d0d0c;
border-radius: 7px;
z-index: 1;
display: flex;
flex-direction: column;
gap: 0.75rem;
background-image: radial-gradient(
350px circle at var(--x) var(--y),
rgba(214, 255, 59, 0.06),
transparent 80%
);
}
.spotlight-badge {
font-family: ui-monospace, monospace;
font-size: 0.75rem;
letter-spacing: 0.12em;
color: #d6ff3b;
}
.spotlight-title {
font-size: 1.5rem;
font-weight: 600;
color: #f1f0e8;
margin: 0;
}
.spotlight-text {
font-size: 0.9rem;
line-height: 1.5;
color: rgba(241, 240, 232, 0.65);
margin: 0;
}
.spotlight-link {
font-family: ui-monospace, monospace;
font-size: 0.8rem;
color: #d6ff3b;
margin-top: 0.5rem;
}spotlight.js10 lines
// Tracks pointer coordinates and updates CSS custom properties on the card
document.querySelectorAll("[data-spotlight]").forEach((card) => {
card.addEventListener("pointermove", (e) => {
const rect = card.getBoundingClientRect();
const x = e.clientX - rect.left;
const y = e.clientY - rect.top;
card.style.setProperty("--x", `${x}px`);
card.style.setProperty("--y", `${y}px`);
});
});Next experiment
Scramble text →