Flip business card
A tactile business card that tilts toward the cursor and flips over in 3D to show contact details on the back.
"use client";
import {
useRef,
useState,
type PointerEvent as ReactPointerEvent,
} from "react";
import "./flip-card.css";
type FlipCardProps = {
name: string;
role: string;
company: string;
details: { label: string; value: string; href?: string }[];
theme?: "light" | "dark";
};
/**
* FlipCard
* - Click / Enter / Space flips the card 180° around its vertical axis.
* - With a mouse, the card also leans a few degrees toward the cursor.
* - Both faces are real content; the hidden face is inert, so links on it can't be tabbed to.
*/
export function FlipCard({
name,
role,
company,
details,
theme = "light",
}: FlipCardProps) {
const [flipped, setFlipped] = useState(false);
const card = useRef<HTMLDivElement>(null);
const tilt = (e: ReactPointerEvent<HTMLDivElement>) => {
if (e.pointerType !== "mouse" || !card.current) return;
const r = card.current.getBoundingClientRect();
card.current.style.setProperty(
"--tx",
`${((e.clientY - r.top) / r.height - 0.5) * -10}deg`,
);
card.current.style.setProperty(
"--ty",
`${((e.clientX - r.left) / r.width - 0.5) * 12}deg`,
);
};
const reset = () => {
card.current?.style.setProperty("--tx", "0deg");
card.current?.style.setProperty("--ty", "0deg");
};
return (
<div className="gu-flip" data-theme={theme}>
<div
ref={card}
className="gu-flip__card"
data-flipped={flipped || undefined}
onPointerMove={tilt}
onPointerLeave={reset}
>
<button
type="button"
className="gu-flip__hit"
aria-pressed={flipped}
onClick={() => setFlipped((f) => !f)}
>
<span className="gu-flip__sr">
{flipped ? "Show front of card" : "Show contact details"}
</span>
</button>
<div className="gu-flip__face gu-flip__front" inert={flipped}>
<div className="gu-flip__mark" aria-hidden="true">
<span />
<span />
</div>
<div>
<p className="gu-flip__name">{name}</p>
<p className="gu-flip__role">
{role}, {company}
</p>
</div>
<p className="gu-flip__hint" aria-hidden="true">
Tap to flip
</p>
</div>
<div className="gu-flip__face gu-flip__back" inert={!flipped}>
<dl>
{details.map((d) => (
<div key={d.label}>
<dt>{d.label}</dt>
<dd>{d.href ? <a href={d.href}>{d.value}</a> : d.value}</dd>
</div>
))}
</dl>
<p className="gu-flip__company">{company}</p>
</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: Flip business 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 business card (ratio 1.75:1) that leans toward the mouse in 3D and flips over to reveal contact details on its back.
## Layout and look
- Max width 420px, radius 18px, deep shadow, perspective 1200px on the wrapper.
- Front: #0e0e10 (dark mode #f3eee3) with a two-circle mark (orange #ff5a1f and lime #d7ff3a overlapping with multiply), big name (weight 900, 27px, -0.04em), role + company underneath, a tiny "Tap to flip" hint top-right.
- Back: orange #ff5a1f with dark text: a definition list (Email, Phone, Studio) and the company name at the bottom.
## Behavior and motion
1. The card has preserve-3d; faces use backface-visibility hidden; the back is pre-rotated 180°.
2. Flip: rotateY adds 180° (800ms, cubic-bezier(0.16, 1, 0.3, 1)).
3. Mouse tilt: rotateX = (pointerY ratio - 0.5) × -10°, rotateY = (pointerX ratio - 0.5) × 12°, combined with the flip; reset on leave.
## Touch
Tap flips; no tilt.
## Accessibility
- A full-size invisible <button aria-pressed> with a screen-reader label does the flipping and shows a focus ring.
- The hidden face is inert. Links on the back sit above the button once flipped.
- prefers-reduced-motion: crossfade faces, no rotation or tilt.
## Props
name, role, company, details ({ label, value, href? }[]), 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.
### FlipCard.tsx
```tsx
"use client";
import {
useRef,
useState,
type PointerEvent as ReactPointerEvent,
} from "react";
import "./flip-card.css";
type FlipCardProps = {
name: string;
role: string;
company: string;
details: { label: string; value: string; href?: string }[];
theme?: "light" | "dark";
};
/**
* FlipCard
* - Click / Enter / Space flips the card 180° around its vertical axis.
* - With a mouse, the card also leans a few degrees toward the cursor.
* - Both faces are real content; the hidden face is inert, so links on it can't be tabbed to.
*/
export function FlipCard({
name,
role,
company,
details,
theme = "light",
}: FlipCardProps) {
const [flipped, setFlipped] = useState(false);
const card = useRef<HTMLDivElement>(null);
const tilt = (e: ReactPointerEvent<HTMLDivElement>) => {
if (e.pointerType !== "mouse" || !card.current) return;
const r = card.current.getBoundingClientRect();
card.current.style.setProperty(
"--tx",
`${((e.clientY - r.top) / r.height - 0.5) * -10}deg`,
);
card.current.style.setProperty(
"--ty",
`${((e.clientX - r.left) / r.width - 0.5) * 12}deg`,
);
};
const reset = () => {
card.current?.style.setProperty("--tx", "0deg");
card.current?.style.setProperty("--ty", "0deg");
};
return (
<div className="gu-flip" data-theme={theme}>
<div
ref={card}
className="gu-flip__card"
data-flipped={flipped || undefined}
onPointerMove={tilt}
onPointerLeave={reset}
>
<button
type="button"
className="gu-flip__hit"
aria-pressed={flipped}
onClick={() => setFlipped((f) => !f)}
>
<span className="gu-flip__sr">
{flipped ? "Show front of card" : "Show contact details"}
</span>
</button>
<div className="gu-flip__face gu-flip__front" inert={flipped}>
<div className="gu-flip__mark" aria-hidden="true">
<span />
<span />
</div>
<div>
<p className="gu-flip__name">{name}</p>
<p className="gu-flip__role">
{role}, {company}
</p>
</div>
<p className="gu-flip__hint" aria-hidden="true">
Tap to flip
</p>
</div>
<div className="gu-flip__face gu-flip__back" inert={!flipped}>
<dl>
{details.map((d) => (
<div key={d.label}>
<dt>{d.label}</dt>
<dd>{d.href ? <a href={d.href}>{d.value}</a> : d.value}</dd>
</div>
))}
</dl>
<p className="gu-flip__company">{company}</p>
</div>
</div>
</div>
);
}
```
### flip-card.css
```css
/* FlipCard: change these colors to match your brand. */
.gu-flip {
--front: #0e0e10; /* front face */
--front-text: #f3eee3;
--back: #ff5a1f; /* back face */
--back-text: #0e0e10;
--mark-a: #ff5a1f;
--mark-b: #d7ff3a;
--focus: #2b35ff;
--ease: cubic-bezier(0.16, 1, 0.3, 1);
width: min(100%, 420px);
perspective: 1200px;
font-family: system-ui, sans-serif;
}
.gu-flip[data-theme="dark"] {
--front: #f3eee3;
--front-text: #0e0e10;
--mark-b: #2b35ff;
--focus: #d7ff3a;
}
.gu-flip__card {
--tx: 0deg;
--ty: 0deg;
position: relative;
aspect-ratio: 1.75;
transform-style: preserve-3d;
transform: rotateX(var(--tx)) rotateY(calc(var(--ty) + var(--flip, 0deg)));
transition: transform 0.8s var(--ease);
}
.gu-flip__card[data-flipped] {
--flip: 180deg;
}
/* An invisible full-size button makes the whole card clickable and focusable */
.gu-flip__hit {
position: absolute;
inset: 0;
z-index: 2;
border: 0;
border-radius: 18px;
background: none;
cursor: pointer;
}
.gu-flip__hit:focus-visible {
outline: 3px solid var(--focus);
outline-offset: 4px;
}
.gu-flip__card[data-flipped] .gu-flip__hit {
z-index: 0; /* let links on the back be clicked */
}
.gu-flip__face {
position: absolute;
inset: 0;
display: flex;
flex-direction: column;
justify-content: space-between;
padding: 26px;
border-radius: 18px;
backface-visibility: hidden;
box-shadow: 0 30px 50px -30px rgb(14 14 16 / 0.6);
}
.gu-flip__front {
background: var(--front);
color: var(--front-text);
}
.gu-flip__back {
z-index: 1;
background: var(--back);
color: var(--back-text);
transform: rotateY(180deg);
}
.gu-flip__mark {
display: flex;
}
.gu-flip__mark span {
width: 30px;
height: 30px;
border-radius: 50%;
background: var(--mark-a);
}
.gu-flip__mark span + span {
margin-left: -12px;
background: var(--mark-b);
mix-blend-mode: multiply;
}
.gu-flip__name {
margin: 0;
font-size: 1.7rem;
font-weight: 900;
letter-spacing: -0.04em;
}
.gu-flip__role {
margin: 4px 0 0;
font-size: 0.9rem;
opacity: 0.75;
}
.gu-flip__hint {
position: absolute;
top: 26px;
right: 26px;
margin: 0;
font-size: 0.75rem;
font-weight: 700;
opacity: 0.6;
}
.gu-flip__back dl {
display: grid;
gap: 8px;
margin: 0;
}
.gu-flip__back dl div {
display: flex;
gap: 14px;
}
.gu-flip__back dt {
width: 64px;
font-size: 0.8rem;
font-weight: 700;
opacity: 0.7;
}
.gu-flip__back dd {
margin: 0;
font-size: 0.92rem;
font-weight: 600;
}
.gu-flip__back a {
position: relative;
z-index: 3;
color: inherit;
}
.gu-flip__company {
margin: 0;
font-weight: 900;
font-size: 1.2rem;
letter-spacing: -0.03em;
}
.gu-flip__sr {
position: absolute;
width: 1px;
height: 1px;
overflow: hidden;
clip-path: inset(50%);
}
@media (prefers-reduced-motion: reduce) {
.gu-flip__card,
.gu-flip__card[data-flipped] {
transform: none;
transition: none;
}
.gu-flip__face {
backface-visibility: visible;
transition: opacity 0.3s;
}
.gu-flip__back {
transform: none;
opacity: 0;
}
.gu-flip__card[data-flipped] .gu-flip__back {
opacity: 1;
}
.gu-flip__card[data-flipped] .gu-flip__front {
opacity: 0;
}
}
```
You might also want
Next piece: Floating label form3D tilt card
Components, intermediate
Depth cards hero
Components, intermediate
Contour map 3D hero
Components, advanced, needs three