A card that tilts in 3D toward the pointer and returns flat.
Installation
Install the packages
npm install @prequelui/react motion@prequelui/react reuses the primitive library your components already depend on.
Add the component
npx shadcn@latest add https://animate.prequelui.terravidhal.me/r/tilt.jsonnpx shadcn@latest add https://animate.prequelui.terravidhal.me/r/tilt.json
Turn on the motion
npx @prequelui/cli@latest animate tiltThe CLI finds the component through components.json, swaps the import and removes the CSS animation classes that Motion replaces.
Usage
Import the component and compose it exactly like the primitive it wraps. Motion is enabled by default; the tempo prop scales every duration and softens every spring.
import { Tilt } from "@/components/prequelui/effects/tilt";
export default function Demo() {
return (
<Tilt maxTilt={10} perspective={800} className="size-56 rounded-2xl border p-5">
Look at me.
</Tilt>
);
}import { Tilt } from "@/components/prequelui/tilt";
export function Variant() {
return (
<Tilt tempo={1.2}>
…
</Tilt>
);
}Animation
The card maps the pointer position to a pair of rotations. The raw values are passed through the same spring, so the tilt eases in, retargets while the pointer moves and returns flat when it leaves. Perspective is set on the transform itself so the card keeps its own layout.
- Spring: stiffness 300, damping 25, mass 0.5.
- Maximum tilt is 10° by default and perspective is 800.
- The pointer is read from the element rect and normalised to −1…1.
- Reduced motion settles both rotations at zero.
API Reference
Each part accepts the usual HTML props in addition to the motion props below. No accessibility prop is hidden behind the animation layer.
Tilt
| Prop | Type | Default |
|---|---|---|
| maxTilt | number | 10 |
| perspective | number | 800 |
| transition | SpringOptions | 300 / 25 / 0.5 |
| className | string | — |