All effectsHover & follow

Card Tilt

卡片倾斜

The card tilts in 3D as the pointer moves across it and returns to level when the pointer leaves.

Move across the card or tap it

Where to use it

Bring depth to a featured product, artwork, or portfolio card. Reserve the tilt for a featured image or a sparse row of cards. A small angle keeps the subject and nearby labels easy to read.

Practical example

On a ceramics studio's homepage, moving the pointer to the edge of a featured vase card tilts the whole card in perspective. It settles flat again as the pointer leaves.

Also called

  • 3D Tilt
  • Tilted Card

AI prompt

Add Card Tilt to [target card]. Use the pointer position relative to the card center to rotate on the X and Y axes by up to 8 degrees. Ease the card back to level on pointer leave. Keep its content, layout, link, and click behavior, and show the card flat on touch devices and with reduced motion.

Example code

Save the standalone HTML as a file and open it in your browser. It uses the same code as the preview.

View HTML
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Card Tilt</title>
  <style>
    :root {
      color-scheme: dark;
      --demo-bg: #171629;
      --demo-ink: #f8f5ff;
      --demo-accent: #b9a6ff;
      --demo-muted: #bfbbd3;
      font-family: system-ui, sans-serif;
      color: var(--demo-ink);
      background: var(--demo-bg);
    }

    *, *::before, *::after { box-sizing: border-box; }
    body { margin: 0; min-width: 0; }
    button, input { font: inherit; }

    .demo {
      display: grid;
      place-items: center;
      align-content: center;
      min-height: 100vh;
      padding: 14px;
      overflow: hidden;
      background: radial-gradient(ellipse at 50% 24%, #28233f, var(--demo-bg) 78%);
    }

    .demo-button {
      border: 1px solid #ffffff3d;
      border-radius: 7px;
      background: #ffffff12;
      color: var(--demo-ink);
      padding: 6px 11px;
      font-size: 12px;
      cursor: pointer;
    }

    :focus-visible {
      outline: 2px solid var(--demo-accent);
      outline-offset: 3px;
    }

    .tilt-area { display: grid; width: min(100%, 216px); perspective: 600px; }
    .tilt {
      --rest-x: 0deg;
      --rest-y: 0deg;
      position: relative;
      display: grid;
      align-content: space-between;
      gap: 21px;
      min-height: 112px;
      padding: 13px 15px;
      overflow: hidden;
      text-align: start;
      color: #fff;
      background: radial-gradient(circle at 98% 1%, #8e70bb, transparent 64%), #281d4c;
      border: 1px solid #beabe978;
      border-radius: 14px;
      box-shadow: 0 10px 22px #0a071c88, inset 0 1px #ffffff28;
      font: inherit;
      cursor: pointer;
      transform: rotateX(var(--tilt-x, var(--rest-x))) rotateY(var(--tilt-y, var(--rest-y)));
      transition: transform 220ms ease-out;
    }
    .tilt:is(:focus-visible, [aria-pressed="true"]) { --rest-x: -8deg; --rest-y: 8deg; }
    .tilt[data-tracking] { transition-duration: 50ms; }
    .tilt::after {
      position: absolute;
      inset: -50% -26% -40% 42%;
      border: 1px solid #e2d0ff55;
      border-radius: 50%;
      transform: rotate(-29deg);
      box-shadow: 0 0 0 10px #dbc3ff15, 0 0 0 21px #dbc3ff12, 0 0 0 33px #dbc3ff0b;
      content: "";
      pointer-events: none;
    }
    .tilt-symbol {
      width: 21px;
      height: 16px;
      background: linear-gradient(135deg, #ffe8cf 10%, #bda3eb);
      border-radius: 4px;
      box-shadow: inset 0 0 0 1px #fff8;
    }
    .tilt-copy { display: grid; gap: 3px; }
    .tilt-copy strong { font-size: 16px; }
    .tilt-copy small { color: #e1d4f4; font-size: 10px; }
    @media (prefers-reduced-motion: reduce) {
      .tilt { transform: none; transition: none; }
      .tilt[aria-pressed="true"] { border-color: #f2dfff; }
    }
  </style>
</head>
<body>
  <main class="demo">
    <div class="tilt-area">
      <button class="tilt" type="button" aria-pressed="false" data-testid="effect-demo-card-tilt">
        <span class="tilt-symbol" aria-hidden="true"></span>
        <span class="tilt-copy"><strong>Design pass</strong><small>Creative studio</small></span>
      </button>
    </div>
  </main>
  <script>
    const stage = document.querySelector(".tilt-area");
    const card = document.querySelector(".tilt");
    const reduceMotion = window.matchMedia("(prefers-reduced-motion: reduce)");

    stage.addEventListener("pointermove", (event) => {
      if (event.pointerType === "touch" || reduceMotion.matches) return;
      const { left, top, width, height } = stage.getBoundingClientRect();
      const x = Math.max(-1, Math.min(1, ((event.clientX - left) / width) * 2 - 1));
      const y = Math.max(-1, Math.min(1, ((event.clientY - top) / height) * 2 - 1));
      card.style.setProperty("--tilt-x", (-y * 8) + "deg");
      card.style.setProperty("--tilt-y", (x * 8) + "deg");
      card.setAttribute("data-tracking", "");
    });

    function resetTilt() {
      card.removeAttribute("data-tracking");
      card.style.removeProperty("--tilt-x");
      card.style.removeProperty("--tilt-y");
    }

    stage.addEventListener("pointerleave", resetTilt);
    stage.addEventListener("pointercancel", resetTilt);
    reduceMotion.addEventListener("change", resetTilt);
    card.addEventListener("click", () => {
      const tilted = card.getAttribute("aria-pressed") === "true";
      card.setAttribute("aria-pressed", String(!tilted));
    });
  </script>
</body>
</html>

Original example by UI Skills

Further examples