# Tilt Card

> A card that tilts in 3D to follow the pointer.

- Category: Cards
- Tier: Free (MIT)
- Page: https://bowls.dev/components/tilt-card
- Requires: React 18+, Tailwind CSS 4, motion

## Install

Copy the source below into `components/bowls/tilt-card.tsx`, then install its dependencies:

```bash
npm i motion
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` | `ReactNode` | — | Card content. |
| `max` | `number` | `14` | Maximum tilt, in degrees. |

## Usage

```tsx
"use client";

import { TiltCard } from "@/components/bowls/tilt-card";

export default function Demo() {
  return (
    <div className="flex h-full w-full items-center justify-center">
      <TiltCard className="flex h-[190px] w-[170px] flex-col justify-between rounded-[18px] bg-white dark:bg-black p-4 shadow-[18px_22px_40px_rgba(10,10,10,.16)]">
        <span className="block size-10 rounded-xl bg-[#0a0a0a] dark:bg-[#f5f5f5]" />
        <span>
          <span className="block text-base font-semibold">Tilt Card</span>
          <span className="mt-1 block font-mono text-[11px] text-[#666] dark:text-[#999999]">follow the pointer</span>
        </span>
      </TiltCard>
    </div>
  );
}
```

## Source

`components/bowls/tilt-card.tsx`

```tsx
"use client";

import { motion, useMotionValue, useSpring, useTransform } from "motion/react";
import type { ReactNode } from "react";

export type TiltCardProps = {
  children: ReactNode;
  /** Maximum tilt, in degrees. */
  max?: number;
  className?: string;
};

/** A card that tilts in 3D to follow the pointer. */
export function TiltCard({ children, max = 14, className }: TiltCardProps) {
  const px = useMotionValue(0.5);
  const py = useMotionValue(0.5);
  const spring = { stiffness: 220, damping: 18 };
  const rotateY = useSpring(useTransform(px, [0, 1], [-max, max]), spring);
  const rotateX = useSpring(useTransform(py, [0, 1], [max, -max]), spring);

  return (
    <div style={{ perspective: 700 }}>
      <motion.div
        onPointerMove={(e) => {
          const box = e.currentTarget.getBoundingClientRect();
          px.set((e.clientX - box.left) / box.width);
          py.set((e.clientY - box.top) / box.height);
        }}
        onPointerLeave={() => {
          px.set(0.5);
          py.set(0.5);
        }}
        style={{ rotateX, rotateY, transformStyle: "preserve-3d" }}
        className={className}
      >
        {children}
      </motion.div>
    </div>
  );
}
```
