Flip Card
A two-sided card that turns over in 3D on hover, focus or tap.
AI prompt
Build a flip card, 240x150px, as a single button with aria-pressed. Inside, a 3D scene (perspective 900px) holds an inner element with transform-style preserve-3d and two absolutely positioned faces, each with backface-visibility hidden. The front shows the word "Latency" in 20px semibold with a small hint "Hover or tap"; the back (rotated 180deg around Y) shows the definition "The delay between an action and its visible response." in 13px text. On hover with a fine pointer, and on click, Enter or Space, rotate the inner element 180deg over 560ms cubic-bezier(.3,.8,.2,1). Toggle aria-pressed on click. Use :focus-visible for a 2px ring around the card. On devices without hover, only click toggles. Under prefers-reduced-motion replace rotation with a 150ms opacity cross-fade between faces.About this pattern
Definition
A card with a front and a back face. The card rotates 180 degrees around its vertical axis to show the other side, which carries secondary information.
Purpose & UX principles
- Fits content with a natural pair: term and meaning, product and specs, question and answer.
- The flip is triggered by hover on pointer devices and by tap or Enter on touch and keyboard, so it never depends on hover alone.
- Hidden faces are removed from the accessibility tree so only the visible side is read.
Interaction states
- Front, back, hover (flip begins), focus-visible ring, pressed (tiny scale).
aria-pressedon the card button reports whether the back is showing.
Motion specification
- Rotation 560ms cubic-bezier(.3,.8,.2,1) with perspective 900px.
- Faces use backface-visibility hidden.
- Reduced motion: the faces cross-fade in 150ms instead of rotating.
Responsive behaviour
- The card keeps a fixed aspect ratio and scales with its container.
- On touch, tapping toggles the flip; there is no hover state.
Code
<button class="flip" id="f" aria-pressed="false" aria-label="Latency, flip card for definition">
<span class="inner">
<span class="face front"><b>Latency</b><small>Hover or tap</small></span>
<span class="face back">The delay between an action and its visible response.</span>
</span>
</button>: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}
.flip{width:240px;height:150px;perspective:900px;background:none;border:0;padding:0;cursor:pointer;font:inherit;color:inherit;border-radius:14px}
.flip:focus-visible{outline:2px solid var(--accent);outline-offset:3px}
.inner{position:relative;display:block;width:100%;height:100%;transform-style:preserve-3d;transition:transform .56s cubic-bezier(.3,.8,.2,1)}
.face{position:absolute;inset:0;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:4px;padding:18px;border-radius:14px;border:1px solid var(--line);background:var(--surface);backface-visibility:hidden;-webkit-backface-visibility:hidden;text-align:center}
.front b{font-size:20px;font-weight:600}
.front small{font-size:12px;color:var(--muted)}
.back{transform:rotateY(180deg);background:var(--accent);color:var(--accent-ink);border-color:var(--accent);font-size:13px;line-height:1.5}
.flip.on .inner{transform:rotateY(180deg)}
@media (hover:hover){.flip:hover .inner{transform:rotateY(180deg)}}
@media (prefers-reduced-motion:reduce){.inner{transform:none!important;transition:none}.face{transition:opacity .15s}.back{transform:none;opacity:0}.front{opacity:1}.flip.on .back,.flip:hover .back{opacity:1}.flip.on .front,.flip:hover .front{opacity:0}}const f=document.getElementById('f');
f.addEventListener('click',()=>{const on=f.classList.toggle('on');f.setAttribute('aria-pressed',String(on));});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>Flip 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}}
.flip{width:240px;height:150px;perspective:900px;background:none;border:0;padding:0;cursor:pointer;font:inherit;color:inherit;border-radius:14px}
.flip:focus-visible{outline:2px solid var(--accent);outline-offset:3px}
.inner{position:relative;display:block;width:100%;height:100%;transform-style:preserve-3d;transition:transform .56s cubic-bezier(.3,.8,.2,1)}
.face{position:absolute;inset:0;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:4px;padding:18px;border-radius:14px;border:1px solid var(--line);background:var(--surface);backface-visibility:hidden;-webkit-backface-visibility:hidden;text-align:center}
.front b{font-size:20px;font-weight:600}
.front small{font-size:12px;color:var(--muted)}
.back{transform:rotateY(180deg);background:var(--accent);color:var(--accent-ink);border-color:var(--accent);font-size:13px;line-height:1.5}
.flip.on .inner{transform:rotateY(180deg)}
@media (hover:hover){.flip:hover .inner{transform:rotateY(180deg)}}
@media (prefers-reduced-motion:reduce){.inner{transform:none!important;transition:none}.face{transition:opacity .15s}.back{transform:none;opacity:0}.front{opacity:1}.flip.on .back,.flip:hover .back{opacity:1}.flip.on .front,.flip:hover .front{opacity:0}}
</style></head>
<body><div class="stage">
<button class="flip" id="f" aria-pressed="false" aria-label="Latency, flip card for definition">
<span class="inner">
<span class="face front"><b>Latency</b><small>Hover or tap</small></span>
<span class="face back">The delay between an action and its visible response.</span>
</span>
</button>
</div>
<script>
const f=document.getElementById('f');
f.addEventListener('click',()=>{const on=f.classList.toggle('on');f.setAttribute('aria-pressed',String(on));});
</script>
</body></html>