A Svelte 5 card component with a physics-based liquid light effect. The spotlight follows your cursor with real spring momentum ā it doesn't just snap to position, it flows.
As you move your cursor over the card, a glowing radial gradient tracks your position ā but instead of following instantly, it has mass and momentum via Svelte's Spring primitive. The result feels genuinely liquid, not mechanical.
Two layers work together:
Both fade in on hover and fade out on leave, also spring-animated.
git clone https://github.com/your-username/liquid-card.git
cd liquid-card
npm install
npm run dev
Drop LiquidCard.svelte into your Svelte 5 project and wrap any content with it:
<script>
import LiquidCard from '$lib/LiquidCard.svelte';
</script>
<LiquidCard>
<h3>Hello</h3>
<p>Any content goes here.</p>
</LiquidCard>
You can also pass a className prop for custom styling:
<LiquidCard className="my-card">
<p>Custom styled card</p>
</LiquidCard>
| Prop | Type | Default | Description |
|---|---|---|---|
children |
snippet | ā | Card content (required) |
className |
string |
"" |
Extra CSS class on the root element |
The component uses CSS custom properties you can override:
.liquid-card {
--spotlight-size: 500px; /* radius of the light cone */
--border-color: oklch(0.8 0.1 240); /* glow color ā change the hue freely */
}
Want a warm amber glow instead of the default cool blue? Just change the hue value in oklch:
--border-color: oklch(0.8 0.15 60); /* amber */
<!-- Spring tracks cursor position with mass/damping -->
const coords = new Spring({ x: 0, y: 0 }, { stiffness: 0.04, damping: 0.2 });
const opacity = new Spring(0, { stiffness: 0.1, damping: 0.4 });
<!-- Values flow into CSS variables each frame -->
style="--x: {coords.current.x}px; --y: {coords.current.y}px; --opacity: {opacity.current};"
The Spring class (Svelte 5 runes syntax) gives the glow its physical feel. Logic stays in JS, rendering stays in CSS ā no layout thrashing, smooth 60fps.
$props(), new Spring(), {@render children()})ā ļø This component uses the Svelte 5 runes API. It is not compatible with Svelte 4.
src/
āāā routes/
ā āāā +page.svelte # Demo page
ā āāā LiquidCard.svelte # The component
ā āāā liquidWrap.svelte # Grid demo layout
MIT ā free to use in personal and commercial projects.