A card that tilts toward the cursor while its layers float at different depths, so each moves at its own speed.
Launch kit
Tilt me to see the layers.
Customize
Usage
import { DepthCard, DepthLayer } from "@/components/motionkit/depth-card";
<DepthCard className="w-72">
<DepthLayer depth={0}>
<img src="/cover.jpg" alt="" className="rounded-t-2xl" />
</DepthLayer>
<DepthLayer depth={60}>
<img src="/product.png" alt="Launch kit" />
</DepthLayer>
<DepthLayer depth={30} className="p-5">
<h3>Launch kit</h3>
</DepthLayer>
</DepthCard>Motion
The exact curves this component runs, plotted with Motion's own maths.
Tilt
Pointer moves over the card
Works in the App Router as is. Requires Tailwind CSS v4.
npm install motionSave as components/motionkit/depth-card.tsx.
"use client";
import type { PointerEvent, ReactNode } from "react";
import {
motion,
useMotionTemplate,
useMotionValue,
useReducedMotion,
useSpring,
useTransform,
} from "motion/react";
type DepthCardProps = {
/** Usually a stack of <DepthLayer>s. */
children?: ReactNode;
/** Maximum rotation in degrees. */
maxTilt?: number;
/** Show a light reflection that follows the pointer. */
glare?: boolean;
className?: string;
};
type DepthLayerProps = {
children?: ReactNode;
/** How far the layer floats above the card, in pixels. Higher layers move more as the card tilts. */
depth?: number;
className?: string;
};
/**
* One layer of a DepthCard. Layers sit at different heights in real 3D space,
* so the tilt moves each one at its own speed.
*/
export function DepthLayer({ children, depth = 30, className = "" }: DepthLayerProps) {
return (
<div style={{ transform: `translateZ(${depth}px)`, transformStyle: "preserve-3d" }} className={className}>
{children}
</div>
);
}
export function DepthCard({ children, maxTilt = 12, glare = true, className = "" }: DepthCardProps) {
const reduceMotion = useReducedMotion();
// pointer position across the card, 0–1 on each axis
const px = useMotionValue(0.5);
const py = useMotionValue(0.5);
const spring = { stiffness: 160, damping: 18 };
const rotateX = useSpring(useTransform(py, [0, 1], [maxTilt, -maxTilt]), spring);
const rotateY = useSpring(useTransform(px, [0, 1], [-maxTilt, maxTilt]), spring);
const glareX = useTransform(px, (v) => v * 100);
const glareY = useTransform(py, (v) => v * 100);
const glareBackground = useMotionTemplate`radial-gradient(circle at ${glareX}% ${glareY}%, rgb(255 255 255 / 0.16), transparent 55%)`;
function handleMove(event: PointerEvent<HTMLDivElement>) {
if (reduceMotion) return;
const rect = event.currentTarget.getBoundingClientRect();
px.set((event.clientX - rect.left) / rect.width);
py.set((event.clientY - rect.top) / rect.height);
}
function handleLeave() {
px.set(0.5);
py.set(0.5);
}
return (
<div style={{ perspective: 1000 }} className={className}>
{/* no overflow-hidden here: clipping would flatten the 3D layers back onto the card */}
<motion.div
onPointerMove={handleMove}
onPointerLeave={handleLeave}
style={{ rotateX, rotateY, transformStyle: "preserve-3d" }}
className="group relative h-full rounded-2xl border border-white/10 bg-gradient-to-br from-[#1D2727] to-[#0C1010] shadow-2xl shadow-black/50"
>
{children}
{glare && (
<motion.div
aria-hidden
style={{ background: glareBackground, transform: "translateZ(1px)" }}
className="pointer-events-none absolute inset-0 rounded-[inherit] opacity-0 transition-opacity duration-300 group-hover:opacity-100"
/>
)}
</motion.div>
</div>
);
}
| Prop | Type | Default | Description |
|---|---|---|---|
| maxTilt | number | 12 | Maximum rotation in degrees. |
| glare | boolean | true | Show a light reflection that follows the pointer. |
| <DepthLayer depth> | number | 30 | How far a layer floats above the card, in pixels. Higher layers move more. |
Edge functions
Tilt me with your cursor.
Tilt Card
A 3D card that tilts toward the pointer, with an optional moving glare.
Founding member
No. 0042
Move your pointer across
Holographic Card
A metallic rainbow foil that shifts and shimmers as the pointer moves, like a holographic trading card.
Realtime sync
Move your cursor across this card.
Spotlight Card
A card with a soft glow that tracks the pointer across its surface.