# Tilt Card

> A 3D card that tilts toward the pointer, with an optional moving glare.

Category: Cards · Free · Updated 2026-11-14 · Live demo: https://www.motionkitui.com/components/tilt-card

## When to use it

Product shots, testimonial cards and profile cards where you want a sense of physical depth without extra artwork.

## How it works

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.

## Installation

```bash
npx shadcn@latest add https://www.motionkitui.com/r/tilt-card.json
```

Or copy `components/motionkit/tilt-card.tsx` below. Requires react, motion and Tailwind CSS v4. Free for personal projects; commercial use needs MotionKit Plus (https://www.motionkitui.com/pricing).

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `maxTilt` | `number` | `12` | Maximum rotation in degrees. |
| `glare` | `boolean` | `true` | Show a light reflection that follows the pointer. |

## Accessibility

- **Keyboard: Not applicable.** A static container. The tilt is a pointer-only flourish and hides nothing.
- **Screen readers: Pass.** The glare layer is hidden from assistive tech.
- **Reduced motion: Pass.** With reduced motion on, the card does not tilt.
- **Colour contrast: Pass.** Default body text measures 7.7:1. Check any colours you add.

## Source

```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>
  );
}
```
