Hover and cursor effects that work for everyone
By Pulse Labs · Published · Updated · 2 min read
A pointer effect responds to where the mouse is: a pool of light that follows the cursor, a card that leans toward it, a button that glows. Build it so it only runs for a real mouse, gives keyboard focus the same cue, and stays still for people who ask for less motion. Done that way it is decoration that costs nothing for anyone who cannot use it.
The demo is a spotlight that follows the pointer across a card. Under it is a table of what each kind of visitor should get, which is the part most tutorials leave out.
<a class="card" href="#plans" id="card">
<h2>Repair, 30 minutes</h2>
<p>Hover with a mouse, or press Tab to focus the card.</p>
</a>.card { display: block; position: relative; margin: 20px auto; max-width: 340px; padding: 26px; border-radius: 16px; border: 1px solid #3a3160; background: #1b1530; color: inherit; text-decoration: none; overflow: hidden; }
.card::before { content: ""; position: absolute; inset: 0; opacity: 0; transition: opacity .25s; pointer-events: none; background: radial-gradient(240px circle at var(--x, 50%) var(--y, 50%), #8a73f544, transparent 70%); }
.card h2 { position: relative; margin: 0 0 4px; font-size: 20px; }
.card p { position: relative; margin: 0; color: #cfc8ee; }
.card:focus-visible { outline: 2px solid #c8f250; outline-offset: 3px; }
.card:focus-visible::before { opacity: 1; }
@media (hover: hover) and (pointer: fine) { .card:hover::before { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .card::before { transition: none; } }const card = document.getElementById("card");
const ok = matchMedia("(hover: hover) and (pointer: fine) and (prefers-reduced-motion: no-preference)");
card.addEventListener("pointermove", (e) => {
if (!ok.matches) return;
const r = card.getBoundingClientRect();
card.style.setProperty("--x", e.clientX - r.left + "px");
card.style.setProperty("--y", e.clientY - r.top + "px");
});What each visitor gets
| Visitor | What they should see | How the code does it |
|---|---|---|
| Mouse | The light follows the pointer | pointermove sets --x and --y; the gradient reads them |
| Keyboard | A still glow and a visible outline on focus | :focus-visible shows the layer and the outline, with no pointer needed |
| Touch screen | No effect. There is no hover | The hover rule sits inside (hover: hover) and (pointer: fine) |
| Reduced motion | A still glow on hover or focus, no following | The script stops updating when the query is reduce, and the fade is removed |
| Script off | A card that works as a link | The effect is an extra layer; the content never depends on it |
Make it cheap to run
- Set custom properties, not
leftandtop. The gradient repaints, but the card never changes layout. - Keep the lit area small: one card, not the whole page.
- Leave form fields alone. A field that tilts under the pointer is hard to type into.
On a page you already have
Writing this for every card on a site is a lot of small code. MotionLift's pointer effects are light on cards, cards that lean to the pointer on desktop, buttons that glow and lean toward the mouse with a ring that spreads when pressed, and moving light across the page without a backdrop. Form fields never tilt under the pointer. The Studio lets you switch each one off. The local shop example shows light on cards and prices that move, on a made-up bike repair page.
See reduced motion for testing, and 3D website for the leaning card, which is the same idea taken one step further.