Depth cards hero
A split hero where a stack of product cards floats in layers and tilts with real depth as the cursor moves.
"use client";
import { useEffect, useRef, type ReactNode } from "react";
import "./depth-cards-hero.css";
type DepthCardsHeroProps = {
title: ReactNode;
text: string;
cta: { label: string; href: string };
stats?: { value: string; label: string }[];
theme?: "light" | "dark";
};
/**
* DepthCardsHero
* - The right side is a "scene" of cards on different layers (data-depth).
* - Moving the pointer writes --mx / --my (-1..1) on the scene; CSS turns that into
* a tilt for the whole scene plus a parallax shift per layer, so near cards move more.
* - No pointer (touch): CSS keyframes make each layer drift on its own.
*/
export function DepthCardsHero({
title,
text,
cta,
stats = [],
theme = "light",
}: DepthCardsHeroProps) {
const scene = useRef<HTMLDivElement>(null);
useEffect(() => {
const el = scene.current;
if (!el || matchMedia("(prefers-reduced-motion: reduce)").matches) return;
let raf = 0,
tx = 0,
ty = 0,
x = 0,
y = 0;
const tick = () => {
x += (tx - x) * 0.08;
y += (ty - y) * 0.08;
el.style.setProperty("--mx", x.toFixed(3));
el.style.setProperty("--my", y.toFixed(3));
raf =
Math.abs(tx - x) + Math.abs(ty - y) > 0.001
? requestAnimationFrame(tick)
: 0;
};
const onMove = (e: PointerEvent) => {
if (e.pointerType !== "mouse") return;
const host = el.parentElement!.getBoundingClientRect();
tx = ((e.clientX - host.left) / host.width) * 2 - 1;
ty = ((e.clientY - host.top) / host.height) * 2 - 1;
if (!raf) raf = requestAnimationFrame(tick);
};
const onLeave = () => {
tx = 0;
ty = 0;
if (!raf) raf = requestAnimationFrame(tick);
};
const host = el.closest(".gu-depth")!;
host.addEventListener("pointermove", onMove as EventListener);
host.addEventListener("pointerleave", onLeave);
return () => {
cancelAnimationFrame(raf);
host.removeEventListener("pointermove", onMove as EventListener);
host.removeEventListener("pointerleave", onLeave);
};
}, []);
return (
<section className="gu-depth" data-theme={theme}>
<div className="gu-depth__copy">
<h1>{title}</h1>
<p>{text}</p>
<a className="gu-depth__cta" href={cta.href}>
{cta.label}
<span aria-hidden="true">→</span>
</a>
{stats.length > 0 && (
<dl className="gu-depth__stats">
{stats.map((s) => (
<div key={s.label}>
<dt>{s.label}</dt>
<dd>{s.value}</dd>
</div>
))}
</dl>
)}
</div>
{/* Decorative product scene */}
<div className="gu-depth__stage" aria-hidden="true">
<div ref={scene} className="gu-depth__scene">
<div className="gu-depth__card gu-depth__card--main" data-depth="1">
<div className="gu-depth__row">
<strong>Revenue</strong>
<span className="gu-depth__chip">+18.4%</span>
</div>
<p className="gu-depth__big">$48,210</p>
<div className="gu-depth__bars">
{[38, 52, 44, 66, 58, 80, 72, 94].map((h, i) => (
<span key={i} style={{ height: `${h}%` }} />
))}
</div>
</div>
<div className="gu-depth__card gu-depth__card--toast" data-depth="3">
<span className="gu-depth__icon">✓</span>
<div>
<strong>Payout sent</strong>
<span>$2,400 to Studio Ama</span>
</div>
</div>
<div className="gu-depth__card gu-depth__card--team" data-depth="2">
<div className="gu-depth__faces">
{["#ff5a1f", "#2b35ff", "#d7ff3a", "#0e0e10"].map((c) => (
<i key={c} style={{ background: c }} />
))}
</div>
<span>4 people editing</span>
</div>
<div className="gu-depth__card gu-depth__card--ring" data-depth="4">
<svg viewBox="0 0 44 44">
<circle cx="22" cy="22" r="18" />
<circle
cx="22"
cy="22"
r="18"
pathLength="100"
strokeDasharray="72 100"
/>
</svg>
<span>
<strong>72%</strong>
<span>goal</span>
</span>
</div>
</div>
</div>
</section>
);
}
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: Depth cards hero
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 two-column hero: headline, text, button and two stats on the left; on the right, a 3D "scene" of floating product cards (revenue chart, payout toast, team avatars, goal ring) on separate depth layers that tilt and parallax with the cursor.
## Layout and look
- Section min height 620px, background #f3eee3 (dark #0e0e10). Grid 1fr / 1.05fr, gap 40px; stacks under 760px container width.
- Headline up to ~5.4rem, weight 900, line-height 0.94, with an orange (#ff5a1f) <em> word. Muted 18px paragraph. Dark rounded-14px button with an arrow that nudges right on hover. Stats: big numbers (weight 900) above small muted labels.
- Cards: #fbf8f2 (dark #1f1f23), 1px border, radius 20px, long soft shadow.
- Main: revenue label, lime (#d7ff3a) "+18.4%" chip, a big number, 8 bar columns (last one orange).
- Toast: orange check tile + "Payout sent".
- Pill: 4 overlapping colored avatars + "4 people editing".
- Ring: SVG progress ring at 72%.
## Behavior and motion
1. Scene has perspective 1100px and preserve-3d, resting at rotateY(-8deg) rotateX(6deg).
2. Pointer position over the section becomes --mx/--my in -1..1, eased each frame (8% per frame). The scene rotates up to ±10°/±8°, and each card translates by (mx, my) × depth × -10px and sits depth × 30px forward (depth 1 to 4).
3. Each card drifts up and down forever with a slow keyframe (5s + depth × 0.7s, alternate), so nearer layers move at a different pace.
## Touch
No pointer tilt on touch; the idle drift keeps it alive.
## Accessibility
- The scene is decorative (aria-hidden); copy is real HTML with an <h1>, the stats are a <dl>.
- prefers-reduced-motion: no drift, fixed tilt.
## Props
title (ReactNode), text, cta ({ label, href }), stats ({ value, label }[]), theme.
## 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.
### DepthCardsHero.tsx
```tsx
"use client";
import { useEffect, useRef, type ReactNode } from "react";
import "./depth-cards-hero.css";
type DepthCardsHeroProps = {
title: ReactNode;
text: string;
cta: { label: string; href: string };
stats?: { value: string; label: string }[];
theme?: "light" | "dark";
};
/**
* DepthCardsHero
* - The right side is a "scene" of cards on different layers (data-depth).
* - Moving the pointer writes --mx / --my (-1..1) on the scene; CSS turns that into
* a tilt for the whole scene plus a parallax shift per layer, so near cards move more.
* - No pointer (touch): CSS keyframes make each layer drift on its own.
*/
export function DepthCardsHero({
title,
text,
cta,
stats = [],
theme = "light",
}: DepthCardsHeroProps) {
const scene = useRef<HTMLDivElement>(null);
useEffect(() => {
const el = scene.current;
if (!el || matchMedia("(prefers-reduced-motion: reduce)").matches) return;
let raf = 0,
tx = 0,
ty = 0,
x = 0,
y = 0;
const tick = () => {
x += (tx - x) * 0.08;
y += (ty - y) * 0.08;
el.style.setProperty("--mx", x.toFixed(3));
el.style.setProperty("--my", y.toFixed(3));
raf =
Math.abs(tx - x) + Math.abs(ty - y) > 0.001
? requestAnimationFrame(tick)
: 0;
};
const onMove = (e: PointerEvent) => {
if (e.pointerType !== "mouse") return;
const host = el.parentElement!.getBoundingClientRect();
tx = ((e.clientX - host.left) / host.width) * 2 - 1;
ty = ((e.clientY - host.top) / host.height) * 2 - 1;
if (!raf) raf = requestAnimationFrame(tick);
};
const onLeave = () => {
tx = 0;
ty = 0;
if (!raf) raf = requestAnimationFrame(tick);
};
const host = el.closest(".gu-depth")!;
host.addEventListener("pointermove", onMove as EventListener);
host.addEventListener("pointerleave", onLeave);
return () => {
cancelAnimationFrame(raf);
host.removeEventListener("pointermove", onMove as EventListener);
host.removeEventListener("pointerleave", onLeave);
};
}, []);
return (
<section className="gu-depth" data-theme={theme}>
<div className="gu-depth__copy">
<h1>{title}</h1>
<p>{text}</p>
<a className="gu-depth__cta" href={cta.href}>
{cta.label}
<span aria-hidden="true">→</span>
</a>
{stats.length > 0 && (
<dl className="gu-depth__stats">
{stats.map((s) => (
<div key={s.label}>
<dt>{s.label}</dt>
<dd>{s.value}</dd>
</div>
))}
</dl>
)}
</div>
{/* Decorative product scene */}
<div className="gu-depth__stage" aria-hidden="true">
<div ref={scene} className="gu-depth__scene">
<div className="gu-depth__card gu-depth__card--main" data-depth="1">
<div className="gu-depth__row">
<strong>Revenue</strong>
<span className="gu-depth__chip">+18.4%</span>
</div>
<p className="gu-depth__big">$48,210</p>
<div className="gu-depth__bars">
{[38, 52, 44, 66, 58, 80, 72, 94].map((h, i) => (
<span key={i} style={{ height: `${h}%` }} />
))}
</div>
</div>
<div className="gu-depth__card gu-depth__card--toast" data-depth="3">
<span className="gu-depth__icon">✓</span>
<div>
<strong>Payout sent</strong>
<span>$2,400 to Studio Ama</span>
</div>
</div>
<div className="gu-depth__card gu-depth__card--team" data-depth="2">
<div className="gu-depth__faces">
{["#ff5a1f", "#2b35ff", "#d7ff3a", "#0e0e10"].map((c) => (
<i key={c} style={{ background: c }} />
))}
</div>
<span>4 people editing</span>
</div>
<div className="gu-depth__card gu-depth__card--ring" data-depth="4">
<svg viewBox="0 0 44 44">
<circle cx="22" cy="22" r="18" />
<circle
cx="22"
cy="22"
r="18"
pathLength="100"
strokeDasharray="72 100"
/>
</svg>
<span>
<strong>72%</strong>
<span>goal</span>
</span>
</div>
</div>
</div>
</section>
);
}
```
### depth-cards-hero.css
```css
/* DepthCardsHero: change these colors to match your brand. */
.gu-depth {
--bg: #f3eee3;
--card: #fbf8f2;
--text: #0e0e10;
--muted: #57534b;
--line: rgb(14 14 16 / 0.1);
--accent: #ff5a1f;
--accent-text: #0e0e10;
--pop: #d7ff3a; /* small highlights */
--focus: #2b35ff;
--shadow: 0 30px 60px -30px rgb(14 14 16 / 0.45);
container-type: inline-size;
display: grid;
grid-template-columns: 1fr 1.05fr;
align-items: center;
gap: 40px;
min-height: 620px;
padding: 72px clamp(20px, 5%, 64px);
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family: system-ui, sans-serif;
}
.gu-depth[data-theme="dark"] {
--bg: #0e0e10;
--card: #1f1f23;
--text: #f3eee3;
--muted: #aea89c;
--line: rgb(243 238 227 / 0.1);
--focus: #d7ff3a;
--shadow: 0 30px 60px -30px rgb(0 0 0 / 0.9);
}
.gu-depth__copy h1 {
margin: 0;
font-size: clamp(2.6rem, 6.4cqi, 5.4rem);
font-weight: 900;
line-height: 0.94;
letter-spacing: -0.05em;
}
.gu-depth__copy h1 em {
font-style: normal;
color: var(--accent);
}
.gu-depth__copy > p {
max-width: 30em;
margin: 22px 0 0;
color: var(--muted);
font-size: 1.15rem;
line-height: 1.55;
}
.gu-depth__cta {
display: inline-flex;
align-items: center;
gap: 10px;
min-height: 54px;
margin-top: 32px;
padding: 0 26px;
border-radius: 14px;
background: var(--text);
color: var(--bg);
font-weight: 800;
text-decoration: none;
}
.gu-depth__cta span {
transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}
.gu-depth__cta:hover span {
transform: translateX(4px);
}
.gu-depth__cta:focus-visible {
outline: 3px solid var(--focus);
outline-offset: 3px;
}
.gu-depth__stats {
display: flex;
gap: 36px;
margin: 44px 0 0;
}
.gu-depth__stats div {
display: flex;
flex-direction: column-reverse;
}
.gu-depth__stats dd {
margin: 0;
font-size: 1.8rem;
font-weight: 900;
letter-spacing: -0.04em;
}
.gu-depth__stats dt {
color: var(--muted);
font-size: 0.85rem;
}
/* ---------- The 3D scene ---------- */
.gu-depth__stage {
perspective: 1100px;
}
.gu-depth__scene {
--mx: 0;
--my: 0;
position: relative;
height: 440px;
transform-style: preserve-3d;
transform: rotateY(calc(var(--mx) * 10deg - 8deg))
rotateX(calc(var(--my) * -8deg + 6deg));
}
.gu-depth__card {
position: absolute;
border: 1px solid var(--line);
border-radius: 20px;
background: var(--card);
box-shadow: var(--shadow);
/* Each layer floats at its own height and shifts more the nearer it is. */
transform: translate3d(
calc(var(--mx) * var(--d) * -10px),
calc(var(--my) * var(--d) * -10px),
calc(var(--d) * 30px)
);
animation: gu-depth-drift calc(5s + var(--d) * 0.7s) ease-in-out infinite
alternate;
}
.gu-depth__card[data-depth="1"] {
--d: 1;
}
.gu-depth__card[data-depth="2"] {
--d: 2;
}
.gu-depth__card[data-depth="3"] {
--d: 3;
}
.gu-depth__card[data-depth="4"] {
--d: 4;
}
@keyframes gu-depth-drift {
to {
translate: 0 calc(var(--d) * -4px);
}
}
.gu-depth__card--main {
inset: 40px 8% auto 6%;
padding: 22px;
}
.gu-depth__row {
display: flex;
align-items: center;
justify-content: space-between;
color: var(--muted);
font-size: 0.9rem;
}
.gu-depth__chip {
padding: 4px 9px;
border-radius: 999px;
background: var(--pop);
color: #0e0e10;
font-size: 0.78rem;
font-weight: 800;
}
.gu-depth__big {
margin: 8px 0 18px;
font-size: 2.6rem;
font-weight: 900;
letter-spacing: -0.04em;
}
.gu-depth__bars {
display: flex;
align-items: end;
gap: 8px;
height: 130px;
}
.gu-depth__bars span {
flex: 1;
border-radius: 6px 6px 2px 2px;
background: color-mix(in srgb, var(--text) 14%, transparent);
}
.gu-depth__bars span:last-child {
background: var(--accent);
}
.gu-depth__card--toast {
top: 6px;
right: 0;
display: flex;
align-items: center;
gap: 12px;
padding: 14px 18px 14px 14px;
border-radius: 16px;
}
.gu-depth__card--toast strong,
.gu-depth__card--team span,
.gu-depth__card--ring strong {
display: block;
font-size: 0.9rem;
}
.gu-depth__card--toast div span,
.gu-depth__card--ring span span {
color: var(--muted);
font-size: 0.8rem;
}
.gu-depth__icon {
display: grid;
place-items: center;
width: 34px;
height: 34px;
border-radius: 10px;
background: var(--accent);
color: var(--accent-text);
font-weight: 900;
}
.gu-depth__card--team {
bottom: 30px;
left: 0;
display: flex;
align-items: center;
gap: 12px;
padding: 12px 18px 12px 12px;
border-radius: 999px;
}
.gu-depth__faces {
display: flex;
}
.gu-depth__faces i {
width: 30px;
height: 30px;
margin-left: -8px;
border: 3px solid var(--card);
border-radius: 50%;
}
.gu-depth__faces i:first-child {
margin-left: 0;
}
.gu-depth__card--ring {
right: 4%;
bottom: 0;
display: flex;
align-items: center;
gap: 12px;
padding: 14px 18px 14px 14px;
}
.gu-depth__card--ring svg {
width: 46px;
height: 46px;
transform: rotate(-90deg);
fill: none;
stroke-width: 6;
stroke-linecap: round;
}
.gu-depth__card--ring circle:first-child {
stroke: var(--line);
}
.gu-depth__card--ring circle:last-child {
stroke: var(--accent);
}
@container (max-width: 640px) {
/* The root is the container, so it cannot query itself: its children span the full row instead */
.gu-depth > * {
grid-column: 1 / -1;
text-align: left;
}
.gu-depth__scene {
height: 380px;
}
}
@media (prefers-reduced-motion: reduce) {
.gu-depth__card {
animation: none;
}
.gu-depth__scene {
transform: rotateY(-8deg) rotateX(6deg);
}
}
```
You might also want
Next piece: Dot field heroContour map 3D hero
Components, advanced, needs three
Glass prism 3D hero
Components, advanced, needs three
Glossy toys physics 3D hero
Components, advanced, needs three