Copied!
Guide

How to make a 3D card tilt hover effect

The card that leans toward your pointer is a perspective, two rotations and one pointer listener. Here is the pattern, the glare highlight, and three finished versions to copy.

← Blog
Title card: 3D tilt card. Preview of the Card hover tilt element from the Enrichr Library.

December 4, 2026

3 min readPerspective plus two rotations

A 3D tilt card leans toward the pointer as it moves across the card. To build one, give the card a perspective, turn the pointer's position inside the card into two small angles, and apply them as rotateX and rotateY. It takes about ten lines of JavaScript and no library.

Try it on any site. The free animation library checker shows you which animation libraries actually run on a page (GSAP, Lenis, Framer Motion). Paste a URL, no sign-up for your first lookup.

What is the basic pattern?

.tilt {
  transform: perspective(800px) rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg));
  transition: transform 0.15s ease-out;
  will-change: transform;
}
.tilt.is-leaving { transition-duration: 0.5s; }
const MAX = 12; // degrees

document.querySelectorAll(".tilt").forEach((card) => {
  card.addEventListener("pointermove", (e) => {
    const r = card.getBoundingClientRect();
    const px = (e.clientX - r.left) / r.width  - 0.5;   // -0.5 to 0.5
    const py = (e.clientY - r.top)  / r.height - 0.5;
    card.classList.remove("is-leaving");
    card.style.setProperty("--ry", `${px * MAX}deg`);
    card.style.setProperty("--rx", `${-py * MAX}deg`);
    card.style.setProperty("--gx", `${(px + 0.5) * 100}%`);
    card.style.setProperty("--gy", `${(py + 0.5) * 100}%`);
  });
  card.addEventListener("pointerleave", () => {
    card.classList.add("is-leaving");
    card.style.setProperty("--rx", "0deg");
    card.style.setProperty("--ry", "0deg");
  });
});

Note the minus sign on --rx. Moving the pointer down should tip the top of the card away from you, and rotation around the X axis runs the other way by default.

How do I add the glare highlight?

.tilt { position: relative; overflow: hidden; }
.tilt::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(circle at var(--gx, 50%) var(--gy, 50%),
              rgb(255 255 255 / 0.35), transparent 60%);
}

The script above already writes --gx and --gy, so the bright spot follows the pointer.

How do I make the content float above the card?

Set transform-style: preserve-3d on the card and give the inner elements a translateZ(), for example 40 pixels for the title and 20 for the text. They then shift by different amounts as the card turns. Remove overflow: hidden if you do this, because it flattens 3D children.

Which finished examples can I copy?

ElementWhat it does
Card hover tiltA grid of cards that tilt in 3D toward the pointer with a moving glare highlight and a lifted shadow.
Skew hover cardsThree cards that bend, twist and tilt in 3D under the pointer, each with its own character.
Depth parallax cardLayered shapes that shift by different amounts as the pointer moves, drifting on touch screens.

All are free in the Enrichr Library with live controls and copyable code.

What should I be careful about?

Where to go next

FAQ

How do I make a card tilt toward the mouse?

Give the card transform: perspective(800px) rotateX() rotateY() and update the two angles on pointermove from the pointer's position inside the card. Reset them on pointerleave.

Do I need vanilla-tilt.js or another library?

No. The core effect is about ten lines. A library is useful if you want gyroscope support or many options without writing them.

Why does my tilt card look flat?

There is no perspective. 3D rotations need either perspective() at the start of the transform or a perspective property on the parent.

Does the tilt effect work on phones?

Not from hover. Either leave the cards flat on touch screens or give them a gentle automatic drift, as the Library's depth parallax card does.