Tilt 3D

Mueve el cursor sobre la tarjeta para inclinarla en el espacio.

React + MotionCards

3D tilt card

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

Settings

1
16px

Code

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

Paste it into ChatGPT, Claude or Cursor and it will adapt the block to your project with these settings, even if you don’t use React.

More in Cards

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.