Edge functions
Tilt me with your cursor.
Customize
Usage
import { TiltCard } from "@/components/motionkit/tilt-card";
<TiltCard className="w-64">
<h3>Edge functions</h3>
<p>Tilt me with your cursor.</p>
</TiltCard>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/tilt-card.tsx.
"use client";
import type { PointerEvent, ReactNode } from "react";
import {
motion,
useMotionTemplate,
useMotionValue,
useReducedMotion,
useSpring,
useTransform,
} from "motion/react";
type TiltCardProps = {
children?: ReactNode;
/** Maximum rotation in degrees. */
maxTilt?: number;
/** Show a light reflection that follows the pointer. */
glare?: boolean;
className?: string;
};
export function TiltCard({ children, maxTilt = 12, glare = true, className = "" }: TiltCardProps) {
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: 200, damping: 20 };
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.18), 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: 800 }} className={className}>
<motion.div
onPointerMove={handleMove}
onPointerLeave={handleLeave}
style={{ rotateX, rotateY, transformStyle: "preserve-3d" }}
className="group relative h-full overflow-hidden rounded-2xl border border-white/10 bg-gradient-to-br from-[#1D2727] to-[#0C1010] p-6 shadow-2xl shadow-black/50"
>
{children}
{glare && (
<motion.div
aria-hidden
style={{ background: glareBackground }}
className="pointer-events-none absolute inset-0 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. |
Launch kit
Tilt me to see the layers.
Depth Card
A card that tilts toward the cursor while its layers float at different depths, so each moves at its own speed.
Realtime sync
Move your cursor across this card.
Spotlight Card
A card with a soft glow that tracks the pointer across its surface.
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.