3D tilt card
Also called tilt effect, hover tilt, or parallax tilt
A card that tips in 3D as the mouse moves over it, often with a moving glare, so it feels like a physical object in your hand.
import type { PointerEvent, ReactNode } from 'react';
import {
motion,
useMotionTemplate,
useMotionValue,
useReducedMotion,
useSpring
} from 'motion/react';
const MAX_TILT = 12; // degrees
const SPRING = { stiffness: 200, damping: 20 };
export function TiltCard({ children }: { children: ReactNode }) {
const reduceMotion = useReducedMotion();
const rotateX = useSpring(0, SPRING);
const rotateY = useSpring(0, SPRING);
const glareX = useMotionValue(50);
const glareY = useMotionValue(50);
const glareOpacity = useSpring(0, SPRING);
const glare = useMotionTemplate`radial-gradient(circle at ${glareX}% ${glareY}%, rgb(255 255 255 / 0.3), transparent 60%)`;
function onPointerMove(event: PointerEvent<HTMLDivElement>) {
// Touch has no hover, and some people prefer less motion.
if (event.pointerType !== 'mouse' || reduceMotion) return;
const rect = event.currentTarget.getBoundingClientRect();
const px = (event.clientX - rect.left) / rect.width; // 0 to 1
const py = (event.clientY - rect.top) / rect.height;
rotateX.set((0.5 - py) * 2 * MAX_TILT);
rotateY.set((px - 0.5) * 2 * MAX_TILT);
glareX.set(px * 100);
glareY.set(py * 100);
glareOpacity.set(1);
}
function onPointerLeave() {
rotateX.set(0);
rotateY.set(0);
glareOpacity.set(0);
}
return (
<div className='perspective-[800px]'>
<motion.div
onPointerMove={onPointerMove}
onPointerLeave={onPointerLeave}
style={{ rotateX, rotateY }}
className='relative w-72 overflow-hidden rounded-2xl border bg-background p-6 shadow-lg'
>
{children}
<motion.div
aria-hidden
style={{ background: glare, opacity: glareOpacity }}
className='pointer-events-none absolute inset-0'
/>
</motion.div>
</div>
);
}Make the pricing card tilt in 3D toward the mouse: from the pointer position relative to the card center, rotate up to 12 degrees on rotateX and rotateY with a spring (stiffness 200, damping 20), and set perspective: 800px on its wrapper. Add a white radial glare at 30% opacity that follows the pointer. Ease back to flat on pointer leave, and skip the effect on touch devices and with prefers-reduced-motion.
Paste into Layerwise or any AI coding tool.
What is 3D tilt card?
A tilt card tracks where the pointer is over it and rotates around its X and Y axes to match, as if the pointer were pressing on that spot, usually by 10 to 15 degrees at most. A perspective on the parent makes the near edge look bigger, and a soft glare that follows the pointer sells the effect, like light catching a credit card.
It works well for product shots, pricing cards, collectible cards, and feature highlights that invite play. Use it on one or a few hero elements; a page full of tilting cards feels busy.
Smooth the rotation with a spring so the card eases back to flat when the pointer leaves. Touch screens have no hover, so leave the card flat there, and turn the effect off when prefers-reduced-motion is set.
Often confused with
- 3D flip
- A 3D flip turns a card over to show its back. A tilt card only tips a few degrees to follow the pointer.
Related terms
All termsPerspective
A CSS property that sets how far the viewer sits from a 3D scene, so rotated elements look deep up close and flatter from far away.
Rotate
A CSS transform that turns an element around its transform origin by an angle, such as `rotate(45deg)`.
Magnetic button
A button that leans toward the mouse pointer as it gets close, then springs back when the pointer leaves.
Spotlight card
A card whose border and background light up with a soft radial glow that follows the mouse pointer, often across a whole grid of cards.
Build it with Layerwise
Describe your app, watch it run in a live preview, and publish it with a database, storage, and sign-in built in.