MagicCard

Cards with a mouse-tracking spotlight and border glow. Pure CSS overlay, pointer-driven, theme-aware.

Live demo

01

Lightning fast

Pointer events drive a single radial gradient β€” no rerenders, no jank.

Theme aware

Inherits surface and border tokens, so light and dark modes both look right.

Zero deps

Pure Svelte 5 + scoped CSS. Lift the file, drop it in, ship.

Rust accent

gradientColor="#b3502c"

Moss accent

gradientColor="#6e7d4e"

Sky accent

gradientColor="#5b82c4"

Implementation

02
MagicCard.svelte
<script>
  import MagicCard from '$lib/components/MagicCard.svelte';
</script>
​
<MagicCard gradientColor="#146ef5" gradientOpacity={0.15}>
  <article class="card">
    <h3>Lightning fast</h3>
    <p>Pointer events drive a single radial gradient.</p>
  </article>
</MagicCard>

MagicCard tracks the pointer relative to its bounding box and writes the position into a CSS custom property. A radial gradient overlay uses that property as its centre, creating the spotlight. On pointer leave the gradient fades via a CSS transition. Everything is scoped β€” no globals leak.

API

04
PropTypeDefaultDescription
gradientColorstring"#146ef5"Hex colour of the spotlight gradient. Six-digit RGB or eight-digit RGBA.
gradientOpacitynumber0.150 – 1. Strength of the overlay at the spotlight centre.
gradientSizenumber200Radius of the radial gradient in pixels.