3D tilt card
A membership-style card that tilts in real 3D toward the cursor, with a moving glare and layers floating at different depths.
"use client";
import { useRef, useState, type PointerEvent } from "react";
import "./tilt-card.css";
type TiltCardProps = {
name?: string;
label?: string;
number?: string;
/** Maximum tilt in degrees. */
maxTilt?: number;
};
/**
* TiltCard
* - Mouse: the card rotates toward the pointer (rotateX / rotateY) and a glare
* follows it. Child layers use translateZ, so they float at different depths.
* - Touch: tap to toggle an automatic "showcase" tilt animation.
*/
export function TiltCard({
name = "Ada Moreno",
label = "Founding member",
number = "0042",
maxTilt = 14,
}: TiltCardProps) {
const card = useRef<HTMLDivElement>(null);
const [showcase, setShowcase] = useState(false);
const onMove = (e: PointerEvent<HTMLDivElement>) => {
const el = card.current;
if (!el || e.pointerType !== "mouse") return;
const r = el.getBoundingClientRect();
const px = (e.clientX - r.left) / r.width; // 0 → 1 across
const py = (e.clientY - r.top) / r.height; // 0 → 1 down
el.style.setProperty("--ry", `${(px - 0.5) * maxTilt * 2}deg`);
el.style.setProperty("--rx", `${(0.5 - py) * maxTilt * 2}deg`);
el.style.setProperty("--gx", `${px * 100}%`);
el.style.setProperty("--gy", `${py * 100}%`);
};
const reset = () => {
card.current?.style.setProperty("--rx", "0deg");
card.current?.style.setProperty("--ry", "0deg");
};
return (
<div className="gu-tilt">
<div
ref={card}
className="gu-tilt__card"
data-showcase={showcase || undefined}
onPointerMove={onMove}
onPointerLeave={reset}
onPointerUp={(e) => e.pointerType !== "mouse" && setShowcase((s) => !s)}
role="img"
aria-label={`${label} card for ${name}, number ${number}`}
>
<div className="gu-tilt__shine" aria-hidden="true" />
<div className="gu-tilt__orb" aria-hidden="true" />
<div className="gu-tilt__top" aria-hidden="true">
<span className="gu-tilt__chip" />
<span className="gu-tilt__brand">Atlas</span>
</div>
<div className="gu-tilt__bottom" aria-hidden="true">
<span className="gu-tilt__label">{label}</span>
<span className="gu-tilt__name">{name}</span>
<span className="gu-tilt__number">No. {number}</span>
</div>
</div>
</div>
);
}
Paste this into ChatGPT, Claude, Cursor, v0, Lovable or Bolt. It describes the layout, motion, colors and accessibility and includes the code, so the AI can rebuild it in any framework.
# Build this UI piece: 3D tilt card
You are a senior front-end engineer. Recreate the piece below in my project. If I don't say which framework I use, ask once, then build it in that framework (React, Vue, Svelte, Angular, Astro, plain HTML/CSS/JS or anything else). Keep the behavior, motion, colors, spacing and accessibility exactly as described. Keep the code clean and commented for beginners.
## What it is
A credit-card-shaped membership card (ratio 1.586) that tilts in real 3D toward the mouse. A glare spot follows the pointer, and inner layers float at different depths, so the card feels like a physical object.
## Layout and look
- Width min(80vw, 380px), radius 22px, padding 26px, content split top/bottom (flex column, space-between).
- Background: radial-gradient(120% 140% at 100% 0%, #ff6a1f 0%, #ff5a1f 28%, #b3260a 55%, #1b0b07 100%). Shadow 0 40px 60px -30px rgba(0,0,0,.65) plus a 1px inner top highlight.
- Top row: a 46×34px gold "chip" (gradient #f3e3c7 → #b9a07a, radius 8px) and the brand word "Atlas" (21px, weight 900, letter-spacing -0.04em).
- Bottom: small label (12.5px, 80% opacity), name (23px, weight 800), number (13.6px, tabular numbers, 75% opacity).
- A dark orb (radial #2a2b33 → #0e0e10) sits bottom-right, 70% card width, pushed back with translateZ(-30px).
- Text color #f4f5f7. Built for dark backgrounds.
## Behavior and motion
- Parent has perspective: 1100px. Card has transform-style: preserve-3d and transform rotateX(--rx) rotateY(--ry).
- On mouse move: px/py = pointer position 0–1. --ry = (px − 0.5) × maxTilt × 2, --rx = (0.5 − py) × maxTilt × 2 (maxTilt default 14deg). Glare position --gx/--gy = px/py in %.
- Transition: 120ms while hovering (tracks closely), 500ms cubic-bezier(0.16,1,0.3,1) when springing back on leave.
- Depth: top row translateZ(50px), bottom block translateZ(70px).
- Glare: radial white (45% alpha) spot at --gx --gy, mix-blend-mode overlay, opacity 0.6 → 1 on hover.
## Touch
Tap toggles a 5s infinite "showcase" animation: a figure-eight of rotateX ±8deg and rotateY ±14deg with slight translateZ, while the glare drifts between corners (register --gx/--gy with @property).
## Accessibility
- The card is decorative information: role="img" with an aria-label like "Founding member card for Ada Moreno, number 0042"; inner text is aria-hidden.
- prefers-reduced-motion: no rotation or showcase animation; only the glare brightens.
## Reference implementation
The original is written in React with one plain CSS file. Dependencies: none (plain React and CSS). Translate it faithfully; do not add new libraries unless my framework needs them.
### TiltCard.tsx
```tsx
"use client";
import { useRef, useState, type PointerEvent } from "react";
import "./tilt-card.css";
type TiltCardProps = {
name?: string;
label?: string;
number?: string;
/** Maximum tilt in degrees. */
maxTilt?: number;
};
/**
* TiltCard
* - Mouse: the card rotates toward the pointer (rotateX / rotateY) and a glare
* follows it. Child layers use translateZ, so they float at different depths.
* - Touch: tap to toggle an automatic "showcase" tilt animation.
*/
export function TiltCard({
name = "Ada Moreno",
label = "Founding member",
number = "0042",
maxTilt = 14,
}: TiltCardProps) {
const card = useRef<HTMLDivElement>(null);
const [showcase, setShowcase] = useState(false);
const onMove = (e: PointerEvent<HTMLDivElement>) => {
const el = card.current;
if (!el || e.pointerType !== "mouse") return;
const r = el.getBoundingClientRect();
const px = (e.clientX - r.left) / r.width; // 0 → 1 across
const py = (e.clientY - r.top) / r.height; // 0 → 1 down
el.style.setProperty("--ry", `${(px - 0.5) * maxTilt * 2}deg`);
el.style.setProperty("--rx", `${(0.5 - py) * maxTilt * 2}deg`);
el.style.setProperty("--gx", `${px * 100}%`);
el.style.setProperty("--gy", `${py * 100}%`);
};
const reset = () => {
card.current?.style.setProperty("--rx", "0deg");
card.current?.style.setProperty("--ry", "0deg");
};
return (
<div className="gu-tilt">
<div
ref={card}
className="gu-tilt__card"
data-showcase={showcase || undefined}
onPointerMove={onMove}
onPointerLeave={reset}
onPointerUp={(e) => e.pointerType !== "mouse" && setShowcase((s) => !s)}
role="img"
aria-label={`${label} card for ${name}, number ${number}`}
>
<div className="gu-tilt__shine" aria-hidden="true" />
<div className="gu-tilt__orb" aria-hidden="true" />
<div className="gu-tilt__top" aria-hidden="true">
<span className="gu-tilt__chip" />
<span className="gu-tilt__brand">Atlas</span>
</div>
<div className="gu-tilt__bottom" aria-hidden="true">
<span className="gu-tilt__label">{label}</span>
<span className="gu-tilt__name">{name}</span>
<span className="gu-tilt__number">No. {number}</span>
</div>
</div>
</div>
);
}
```
### tilt-card.css
```css
/* TiltCard: the 3D stage. Perspective lives on the parent. */
.gu-tilt {
perspective: 1100px;
font-family: system-ui, sans-serif;
}
.gu-tilt__card {
--rx: 0deg;
--ry: 0deg;
--gx: 50%;
--gy: 30%;
position: relative;
width: min(80vw, 380px);
aspect-ratio: 1.586; /* real card ratio */
border-radius: 22px;
padding: 26px;
display: flex;
flex-direction: column;
justify-content: space-between;
color: #f4f5f7;
background: radial-gradient(
120% 140% at 100% 0%,
#ff6a1f 0%,
#ff5a1f 28%,
#b3260a 55%,
#1b0b07 100%
);
box-shadow:
0 40px 60px -30px rgb(0 0 0 / 0.65),
inset 0 1px 0 rgb(255 255 255 / 0.35);
transform-style: preserve-3d;
transform: rotateX(var(--rx)) rotateY(var(--ry));
transition: transform 0.5s cubic-bezier(0.16, 1, 0.3, 1);
cursor: pointer;
user-select: none;
-webkit-tap-highlight-color: transparent;
}
.gu-tilt__card:hover {
transition-duration: 0.12s; /* follow the mouse closely while hovering */
}
/* Glare: a light spot that follows the pointer. */
.gu-tilt__shine {
position: absolute;
inset: 0;
border-radius: inherit;
background: radial-gradient(
circle at var(--gx) var(--gy),
rgb(255 255 255 / 0.45),
transparent 45%
);
mix-blend-mode: overlay;
opacity: 0.6;
transition: opacity 0.4s;
pointer-events: none;
}
.gu-tilt__card:hover .gu-tilt__shine {
opacity: 1;
}
/* A dark orb floating deep inside the card. */
.gu-tilt__orb {
position: absolute;
right: -8%;
bottom: -30%;
width: 70%;
aspect-ratio: 1;
border-radius: 50%;
background: radial-gradient(circle at 35% 35%, #2a2b33, #0e0e10 70%);
transform: translateZ(-30px);
opacity: 0.9;
}
/* Layers at different depths = the 3D feeling. */
.gu-tilt__top,
.gu-tilt__bottom {
position: relative;
display: flex;
transform: translateZ(50px);
}
.gu-tilt__top {
justify-content: space-between;
align-items: center;
}
.gu-tilt__bottom {
flex-direction: column;
gap: 2px;
transform: translateZ(70px);
}
.gu-tilt__chip {
width: 46px;
height: 34px;
border-radius: 8px;
background: linear-gradient(135deg, #f3e3c7, #b9a07a);
box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.2);
}
.gu-tilt__brand {
font-size: 1.3rem;
font-weight: 900;
letter-spacing: -0.04em;
}
.gu-tilt__label {
font-size: 0.78rem;
font-weight: 600;
opacity: 0.8;
}
.gu-tilt__name {
font-size: 1.45rem;
font-weight: 800;
letter-spacing: -0.03em;
}
.gu-tilt__number {
font-size: 0.85rem;
opacity: 0.75;
font-variant-numeric: tabular-nums;
}
/* Touch: tap toggles a slow figure-eight showcase. */
.gu-tilt__card[data-showcase] {
animation: gu-tilt-showcase 5s ease-in-out infinite;
}
.gu-tilt__card[data-showcase] .gu-tilt__shine {
opacity: 1;
animation: gu-tilt-glare 5s ease-in-out infinite;
}
@keyframes gu-tilt-showcase {
0%,
100% {
transform: rotateX(8deg) rotateY(-14deg) translateZ(20px);
}
25% {
transform: rotateX(-8deg) rotateY(0deg) translateZ(30px);
}
50% {
transform: rotateX(8deg) rotateY(14deg) translateZ(20px);
}
75% {
transform: rotateX(-6deg) rotateY(0deg) translateZ(30px);
}
}
@keyframes gu-tilt-glare {
0%,
100% {
--gx: 15%;
--gy: 20%;
}
50% {
--gx: 85%;
--gy: 70%;
}
}
@property --gx {
syntax: "<percentage>";
inherits: true;
initial-value: 50%;
}
@property --gy {
syntax: "<percentage>";
inherits: true;
initial-value: 30%;
}
@media (prefers-reduced-motion: reduce) {
.gu-tilt__card,
.gu-tilt__card[data-showcase] {
transform: none !important;
animation: none !important;
}
.gu-tilt__card[data-showcase] .gu-tilt__shine {
animation: none;
}
}
```
You might also want
Next piece: Motion polish promptDepth cards hero
Components, intermediate
Spotlight cards
Components, beginner
Contour map 3D hero
Components, advanced, needs three