Skip to content
WANCRAFT

B.05Cards & Containers

Tilt Card

A perspective card that tilts toward the pointer, with a spring-smoothed glare and layered depth.

UpdatedReactMotionTailwindintermediate

Overview

Tilt Card maps the pointer position to rotateX / rotateY through springs, lifts the surface slightly and sweeps a radial glare across it. The surface preserves 3D, so children can float above it with translateZ for a parallax effect. Pointer tracking writes to motion values only — the card never re-renders while you move. Touch input and prefers-reduced-motion get a calm, flat card.

01Installation

Method 01 · Registry

CLI verified

Uses the shadcn CLI in a project initialised with shadcn init. Installs the file to components/ui/tilt-card.tsx and adds its dependencies.

npx shadcn@latest add https://wancraft.my/r/tilt-card.json

Method 02 · Copy and paste

  1. 1. Install the dependencies below.
  2. 2. Copy the source from the Code tab into components/ui/tilt-card.tsx.
  3. 3. Import it and adjust props.
npm install motion
Dependencies
motion
Peer
react ≥ 18, tailwindcss ≥ 4
Added
1 Oct 2026
Updated
13 Oct 2026

02Usage

The default configuration. Change properties above to generate a tailored example in the Usage tab.

example.tsx
import { TiltCard } from "@/components/ui/tilt-card";

export function TiltCardExample() {
  return (
    <TiltCard className="w-72">
      <div className="p-6">
        <h3 className="text-lg font-medium">Perspective study</h3>
        <p className="text-sm opacity-70">Move the pointer across the card.</p>
      </div>
    </TiltCard>
  );
}

03Props

PropTypeDefaultDescription
tiltStrengthnumber12Maximum rotation in degrees at the edges.
spring{ stiffness: number; damping: number; mass: number }{ stiffness: 220, damping: 22, mass: 0.6 }Spring smoothing rotation, lift and glare.
scalenumber1.03Scale while hovered.
perspectivenumber900CSS perspective in px; lower values exaggerate depth.
glarebooleantrueShow a radial reflection following the pointer.
glareOpacitynumber0.35Peak glare opacity (0–1).
roundednumber20Surface corner radius in px.
surfaceClassNamestringwhite / graphite surfaceClasses for the tilting surface (background, border, shadow). Passing it replaces the default surface styling.
classNamestring—Classes for the outer wrapper — use it for sizing.
childrenReactNode—Card content. Add [transform:translateZ(…)] to float layers above the surface.

04Features

  • 01Spring-smoothed rotateX / rotateY mapped from the pointer
  • 02Pointer-following radial glare with configurable intensity
  • 03preserve-3d surface so children can use translateZ for parallax depth
  • 04Hit area on a non-rotating wrapper, so the tilt never jitters at the edges
  • 05No React re-renders while the pointer moves
motion · springinput · pointerinput · hover

05Accessibility

  • The card is a plain container — it adds no roles and does not trap focus; interactive children keep their own semantics.
  • When a child receives keyboard focus, the surface shows a focus outline (:has(:focus-visible)).
  • The glare layer is aria-hidden and ignores pointer events.
  • Touch input never tilts the card, so scrolling is unaffected.
  • With prefers-reduced-motion the card stays flat and the glare is removed.