Tilt Card
A card that tilts toward the pointer in 3D and returns smoothly when the pointer leaves.
AI prompt
Create a 260x160px card with a title "Aurora" and a one-line description. Add a pointer-tracking tilt: on pointermove inside the card compute the pointer position relative to the card centre, map it to rotateX and rotateY of at most 8 degrees (rotateY follows horizontal position, rotateX inverse of vertical), and apply it with perspective(800px) via a CSS custom property so updates are batched with requestAnimationFrame. Add a radial-gradient highlight overlay that follows the pointer using custom properties for x and y at 10% white opacity. On pointerleave animate back to rotate(0) over 450ms cubic-bezier(.2,.7,.2,1). Only apply the effect for pointer type mouse or pen. Disable everything under prefers-reduced-motion. Keep a 2px focus-visible ring and do not tilt on focus.About this pattern
Definition
A card that rotates on its X and Y axes according to where the pointer is inside it, with a soft highlight following the pointer. When the pointer leaves, it eases back to flat.
Purpose & UX principles
- Adds depth and a sense of physical material to featured items.
- Strictly decorative: all information stays readable and the card works without the effect.
- The tilt is small (up to 8 degrees) so text never becomes hard to read.
Interaction states
- Rest (flat), hover (tracking the pointer), leave (eases back), focus-visible ring (no tilt on keyboard focus).
Motion specification
- While the pointer moves the transform updates every animation frame with a 90ms transition for smoothing.
- Return to flat: 450ms cubic-bezier(.2,.7,.2,1).
- Reduced motion: the tilt and highlight are disabled completely.
Responsive behaviour
- The effect is pointer-only and is disabled on touch devices.
- The card scales with its container.
Code
<div class="stage2"><article class="tc" id="tc" tabindex="0"><div class="shine"></div><h3>Aurora</h3><p>Move the pointer across the card.</p></article></div>:root{--bg:#F1F1EF;--surface:#fff;--surface-2:#F7F7F5;--line:#E0E0DC;--text:#171717;--muted:#6f6f6f;--accent:#171717;--accent-ink:#fff;--danger:#d92d20}
*{box-sizing:border-box;margin:0}
.stage2{perspective:800px}
.tc{--rx:0deg;--ry:0deg;--mx:50%;--my:50%;position:relative;width:260px;height:160px;padding:20px;border-radius:16px;background:var(--surface);border:1px solid var(--line);transform:rotateX(var(--rx)) rotateY(var(--ry));transform-style:preserve-3d;transition:transform .45s cubic-bezier(.2,.7,.2,1),box-shadow .3s;overflow:hidden}
.tc.moving{transition:transform .09s linear}
.tc:hover{box-shadow:0 16px 36px rgba(0,0,0,.12)}
.tc:focus-visible{outline:2px solid var(--accent);outline-offset:3px}
.shine{position:absolute;inset:0;background:radial-gradient(circle at var(--mx) var(--my),rgba(255,255,255,.7),transparent 55%);opacity:0;transition:opacity .25s;pointer-events:none}
.tc:hover .shine{opacity:1}
h3{font-size:18px;font-weight:600;position:relative}
p{font-size:13px;color:var(--muted);margin-top:6px;position:relative}
@media (prefers-reduced-motion:reduce){.tc,.tc.moving{transition:none;transform:none}.shine{display:none}}const c=document.getElementById('tc');let raf=0;
if(!matchMedia('(prefers-reduced-motion: reduce)').matches){
c.addEventListener('pointermove',e=>{if(e.pointerType==='touch')return;const r=c.getBoundingClientRect(),x=(e.clientX-r.left)/r.width,y=(e.clientY-r.top)/r.height;cancelAnimationFrame(raf);raf=requestAnimationFrame(()=>{c.classList.add('moving');c.style.setProperty('--ry',((x-.5)*16).toFixed(2)+'deg');c.style.setProperty('--rx',((.5-y)*16).toFixed(2)+'deg');c.style.setProperty('--mx',(x*100)+'%');c.style.setProperty('--my',(y*100)+'%');});});
c.addEventListener('pointerleave',()=>{cancelAnimationFrame(raf);c.classList.remove('moving');c.style.setProperty('--rx','0deg');c.style.setProperty('--ry','0deg');});
}One complete HTML file. Save it and open it in a browser.
<!doctype html>
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Tilt Card — demo</title>
<style>
:root{--bg:#F1F1EF;--surface:#fff;--surface-2:#F7F7F5;--line:#E0E0DC;--text:#171717;--muted:#6f6f6f;--accent:#171717;--accent-ink:#fff;--danger:#d92d20}
*{box-sizing:border-box;margin:0}
html,body{height:100%}body{background:var(--bg);color:var(--text);font:15px/1.5 -apple-system,BlinkMacSystemFont,'Segoe UI',Inter,Roboto,sans-serif;-webkit-font-smoothing:antialiased}.stage{min-height:100%;display:grid;place-items:center;padding:24px}button,input,select,textarea{font-family:inherit}@media (prefers-reduced-motion:reduce){html{scroll-behavior:auto}}
.stage2{perspective:800px}
.tc{--rx:0deg;--ry:0deg;--mx:50%;--my:50%;position:relative;width:260px;height:160px;padding:20px;border-radius:16px;background:var(--surface);border:1px solid var(--line);transform:rotateX(var(--rx)) rotateY(var(--ry));transform-style:preserve-3d;transition:transform .45s cubic-bezier(.2,.7,.2,1),box-shadow .3s;overflow:hidden}
.tc.moving{transition:transform .09s linear}
.tc:hover{box-shadow:0 16px 36px rgba(0,0,0,.12)}
.tc:focus-visible{outline:2px solid var(--accent);outline-offset:3px}
.shine{position:absolute;inset:0;background:radial-gradient(circle at var(--mx) var(--my),rgba(255,255,255,.7),transparent 55%);opacity:0;transition:opacity .25s;pointer-events:none}
.tc:hover .shine{opacity:1}
h3{font-size:18px;font-weight:600;position:relative}
p{font-size:13px;color:var(--muted);margin-top:6px;position:relative}
@media (prefers-reduced-motion:reduce){.tc,.tc.moving{transition:none;transform:none}.shine{display:none}}
</style></head>
<body><div class="stage">
<div class="stage2"><article class="tc" id="tc" tabindex="0"><div class="shine"></div><h3>Aurora</h3><p>Move the pointer across the card.</p></article></div>
</div>
<script>
const c=document.getElementById('tc');let raf=0;
if(!matchMedia('(prefers-reduced-motion: reduce)').matches){
c.addEventListener('pointermove',e=>{if(e.pointerType==='touch')return;const r=c.getBoundingClientRect(),x=(e.clientX-r.left)/r.width,y=(e.clientY-r.top)/r.height;cancelAnimationFrame(raf);raf=requestAnimationFrame(()=>{c.classList.add('moving');c.style.setProperty('--ry',((x-.5)*16).toFixed(2)+'deg');c.style.setProperty('--rx',((.5-y)*16).toFixed(2)+'deg');c.style.setProperty('--mx',(x*100)+'%');c.style.setProperty('--my',(y*100)+'%');});});
c.addEventListener('pointerleave',()=>{cancelAnimationFrame(raf);c.classList.remove('moving');c.style.setProperty('--rx','0deg');c.style.setProperty('--ry','0deg');});
}
</script>
</body></html>