# 3D tilt card

> A card that tilts in 3D towards your cursor and eases back flat when the mouse leaves.

- Category: [Cards](https://library.aimran.es/components/cards)
- Built with: React + Motion
- Live editor: https://library.aimran.es/blocks/tilt-card
- Library: AIMRAN Library (https://library.aimran.es), free, no sign-up, by Aimran Oukham

## Where to use it

Tilt works best on content you want people to linger on: a featured product, the cards of a portfolio, a gift card preview or a set of pricing plans. The movement makes a flat card feel like an object you could pick up. Product sites have used this 3D tilt card effect for years, and it still works.

Keep the intensity low for cards with a lot of text, or reading gets uncomfortable. It shines with one image and a short title. On touch devices there is no hover, so the card simply stays flat.

## Code

### React (Motion)

```tsx
import { useRef } from "react";
import { motion, useMotionValue, useSpring, useTransform } from "framer-motion";

interface TiltCardProps {
  intensity?: number;
  glow?: string;
  radius?: number;
}

export default function TiltCard({
  intensity = 1,
  glow = "#0071e3",
  radius = 16,
}: TiltCardProps) {
  const ref = useRef<HTMLDivElement>(null);
  const mx = useMotionValue(0);
  const my = useMotionValue(0);
  const rx = useSpring(
    useTransform(my, [-0.5, 0.5], [12 * intensity, -12 * intensity]),
    { stiffness: 220, damping: 20 },
  );
  const ry = useSpring(
    useTransform(mx, [-0.5, 0.5], [-12 * intensity, 12 * intensity]),
    { stiffness: 220, damping: 20 },
  );

  return (
    <div style={{ perspective: 900 }}>
      <motion.div
        ref={ref}
        style={{
          rotateX: rx,
          rotateY: ry,
          borderRadius: radius,
          boxShadow: `0 20px 60px -20px ${glow}66`,
        }}
        className="w-64 border border-black/10 bg-white p-6 text-[#1d1d1f] dark:border-white/10 dark:bg-[#1c1c1e] dark:text-[#f5f5f7]"
        onMouseMove={(e) => {
          const el = ref.current;
          if (!el) return;
          const r = el.getBoundingClientRect();
          mx.set((e.clientX - r.left) / r.width - 0.5);
          my.set((e.clientY - r.top) / r.height - 0.5);
        }}
        onMouseLeave={() => {
          mx.set(0);
          my.set(0);
        }}
      >
        <div className="mb-4 h-10 w-10 rounded-full" style={{ backgroundColor: glow }} />
        <h3 className="text-base font-semibold">Tilt 3D</h3>
        <p className="mt-1.5 text-sm text-[#86868b]">
          Move your cursor over the card to tilt it in space.
        </p>
      </motion.div>
    </div>
  );
}
```

## Prompt for AI assistants

Paste this into ChatGPT, Claude, Cursor, v0 or Lovable to adapt the block to your stack (Tailwind, Vue, Svelte…):

````text
I want to add the “3D tilt card” block (Cards) from AIMRAN Library to my project.

## What it is
A card that tilts in 3D towards your cursor and eases back flat when the mouse leaves.

## Chosen settings
- Intensity: 1 (from 0.2 to 2)
- Glow color: #0071e3
- Radius: 16px (from 0 to 32px)

## What I need
1. Add it to my project with the same look and animation as the reference code: same sizes, colours, radii, shadows, timings and easing.
2. It is built with React + TypeScript, with framer-motion for the animation and lucide-react for the icons. If my project uses something else (Vue, Svelte, Astro, plain HTML…), translate it without losing any behaviour. If I use Tailwind, turn the styles into classes; if not, keep the CSS in its own file.
3. Expose the settings above as props (or CSS variables) with those values as defaults.
4. Make it work well on phones: nothing that depends only on hover, touch targets of at least 44 px and no overflow on 320 px screens.
5. Make it look right in light and dark mode.
6. Keep it accessible: semantic HTML, roles and aria-* where needed, visible focus and keyboard support.
7. Respect prefers-reduced-motion: with reduced motion, no big animations but the same end result.

## Reference code
```tsx
import { useRef } from "react";
import { motion, useMotionValue, useSpring, useTransform } from "framer-motion";

interface TiltCardProps {
  intensity?: number;
  glow?: string;
  radius?: number;
}

export default function TiltCard({
  intensity = 1,
  glow = "#0071e3",
  radius = 16,
}: TiltCardProps) {
  const ref = useRef<HTMLDivElement>(null);
  const mx = useMotionValue(0);
  const my = useMotionValue(0);
  const rx = useSpring(
    useTransform(my, [-0.5, 0.5], [12 * intensity, -12 * intensity]),
    { stiffness: 220, damping: 20 },
  );
  const ry = useSpring(
    useTransform(mx, [-0.5, 0.5], [-12 * intensity, 12 * intensity]),
    { stiffness: 220, damping: 20 },
  );

  return (
    <div style={{ perspective: 900 }}>
      <motion.div
        ref={ref}
        style={{
          rotateX: rx,
          rotateY: ry,
          borderRadius: radius,
          boxShadow: `0 20px 60px -20px ${glow}66`,
        }}
        className="w-64 border border-black/10 bg-white p-6 text-[#1d1d1f] dark:border-white/10 dark:bg-[#1c1c1e] dark:text-[#f5f5f7]"
        onMouseMove={(e) => {
          const el = ref.current;
          if (!el) return;
          const r = el.getBoundingClientRect();
          mx.set((e.clientX - r.left) / r.width - 0.5);
          my.set((e.clientY - r.top) / r.height - 0.5);
        }}
        onMouseLeave={() => {
          mx.set(0);
          my.set(0);
        }}
      >
        <div className="mb-4 h-10 w-10 rounded-full" style={{ backgroundColor: glow }} />
        <h3 className="text-base font-semibold">Tilt 3D</h3>
        <p className="mt-1.5 text-sm text-[#86868b]">
          Move your cursor over the card to tilt it in space.
        </p>
      </motion.div>
    </div>
  );
}
```

Give me the complete final code, ready to paste, and tell me in one line where to put it in my project.
````
