A card that tilts toward the cursor while its layers float at different depths, so each moves at its own speed.
A 3D card that tilts toward the pointer, with an optional moving glare.
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
Product shots, testimonial cards and profile cards where you want a sense of physical depth without extra artwork.
The pointer's position across the card, from 0 to 1 on each axis, maps to rotateX and rotateY up to maxTilt degrees. Both rotations run through springs, the parent sets a CSS perspective, and an optional glare gradient follows the pointer to sell the light. Leaving the card springs it back to flat.
Works in the App Router as is. Requires Tailwind CSS v4.
One command adds the file and installs its dependencies. Needs a components.json (run npx shadcn@latest init once if you don't have one).
npx shadcn@latest add https://www.motionkitui.com/r/tilt-card.jsonnpm 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. |
How we audit: the WCAG 2.2 animation checklist and respecting reduced motion in React.
Yes. The file starts with "use client", so you can import it straight into a Server Component page or layout. It works in Vite as is, and in Astro as a React island.
Only the motion package, beside React and Tailwind CSS v4. There is no MotionKit package and no Tailwind config to add.
Yes. Run npx shadcn@latest add https://www.motionkitui.com/r/tilt-card.json in any project with a components.json. It saves the file to components/motionkit and installs its dependencies.
With reduced motion on, the card does not tilt.
Map the pointer's position across the card to rotateX and rotateY, run both through springs so the card has weight, and set a CSS perspective on the parent. This component does exactly that, with an optional glare that follows the pointer.
Yes. Set glare to false for a plain tilt, and lower maxTilt (in degrees) for a subtler effect. With reduced motion on, the card doesn't tilt at all.
A card that tilts toward the cursor while its layers float at different depths, so each moves at its own speed.
A card with a soft glow that tracks the pointer across its surface.
A metallic rainbow foil that shifts and shimmers as the pointer moves, like a holographic trading card.
Edge functions
Tilt me with your cursor.