Stacked Cards
A compact pile of cards that fans out on hover, focus or tap to show every item.
AI prompt
Create a stacked-cards component with three notification cards (Payment received, New follower, Update available), each 280x56px with a 13px title and 12px secondary line. At rest the cards overlap: the first is on top at full scale, the second is offset 10px down at scale 0.96 and the third 20px down at scale 0.92, all inside a container 280px wide. Add a small toggle button "Show all" below with aria-expanded. On container hover, :focus-within or when expanded, each card translates down by index times 64px (gap 8px) and scales to 1, with a 300ms cubic-bezier(.2,.7,.2,1) transition and a 40ms transition-delay per index. The container height animates from 76px to 192px. Pressing the toggle expands or collapses and updates its label ("Show all" / "Collapse"). Under prefers-reduced-motion remove the stagger and use a 120ms transition.About this pattern
Definition
Several cards drawn on top of one another with small offsets. Interacting with the pile spreads them into a readable list, and moving away folds them back.
Purpose & UX principles
- Saves vertical space when many items of the same kind exist (notifications, tickets, wallet cards).
- The collapsed pile hints at how many items exist; the expanded list gives full access.
- A button toggles the stack for keyboard and touch users, and the pile also opens on hover for pointers.
Interaction states
- Collapsed, expanded (hover, focus-within or toggled), pressed, focus-visible ring on the toggle.
aria-expandedmirrors the toggle state.
Motion specification
- Each card translates by its index: 300ms cubic-bezier(.2,.7,.2,1) with a 40ms stagger.
- Scale of back cards 0.96 and 0.92 at rest.
- Reduced motion: the stack expands without staggered movement, using a plain 120ms transition.
Responsive behaviour
- The stack width follows its container; expanded height grows with the number of items.
- On touch devices the toggle button is the primary control.
Code
<div class="wrap">
<div class="stack" id="stack">
<article class="n" style="--i:0"><b>Payment received</b><small>$48.00 from Maya</small></article>
<article class="n" style="--i:1"><b>New follower</b><small>Jon started following you</small></article>
<article class="n" style="--i:2"><b>Update available</b><small>Version 2.4 is ready</small></article>
</div>
<button class="tg" id="tg" aria-expanded="false" aria-controls="stack">Show all</button>
</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}
.wrap{display:grid;justify-items:center;gap:14px}
.stack{position:relative;width:280px;height:76px;transition:height .3s cubic-bezier(.2,.7,.2,1)}
.n{position:absolute;left:0;right:0;top:0;height:56px;padding:10px 14px;border-radius:12px;background:var(--surface);border:1px solid var(--line);display:flex;flex-direction:column;justify-content:center;z-index:calc(10 - var(--i));transform:translateY(calc(var(--i) * 10px)) scale(calc(1 - var(--i) * .04));transform-origin:top center;transition:transform .3s cubic-bezier(.2,.7,.2,1) calc(var(--i) * 40ms)}
.n b{font-size:13px;font-weight:600}
.n small{font-size:12px;color:var(--muted)}
.stack.open,.stack:hover,.stack:focus-within{height:192px}
.stack.open .n,.stack:hover .n,.stack:focus-within .n{transform:translateY(calc(var(--i) * 68px)) scale(1)}
.tg{height:30px;padding:0 14px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font:inherit;font-size:12.5px;cursor:pointer}
.tg:hover{border-color:var(--accent)}
.tg:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
@media (prefers-reduced-motion:reduce){.stack{transition:height .12s}.n{transition:transform .12s}}const s=document.getElementById('stack'),t=document.getElementById('tg');
t.addEventListener('click',()=>{const o=s.classList.toggle('open');t.setAttribute('aria-expanded',String(o));t.textContent=o?'Collapse':'Show all';});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>Stacked Cards — 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}}
.wrap{display:grid;justify-items:center;gap:14px}
.stack{position:relative;width:280px;height:76px;transition:height .3s cubic-bezier(.2,.7,.2,1)}
.n{position:absolute;left:0;right:0;top:0;height:56px;padding:10px 14px;border-radius:12px;background:var(--surface);border:1px solid var(--line);display:flex;flex-direction:column;justify-content:center;z-index:calc(10 - var(--i));transform:translateY(calc(var(--i) * 10px)) scale(calc(1 - var(--i) * .04));transform-origin:top center;transition:transform .3s cubic-bezier(.2,.7,.2,1) calc(var(--i) * 40ms)}
.n b{font-size:13px;font-weight:600}
.n small{font-size:12px;color:var(--muted)}
.stack.open,.stack:hover,.stack:focus-within{height:192px}
.stack.open .n,.stack:hover .n,.stack:focus-within .n{transform:translateY(calc(var(--i) * 68px)) scale(1)}
.tg{height:30px;padding:0 14px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font:inherit;font-size:12.5px;cursor:pointer}
.tg:hover{border-color:var(--accent)}
.tg:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
@media (prefers-reduced-motion:reduce){.stack{transition:height .12s}.n{transition:transform .12s}}
</style></head>
<body><div class="stage">
<div class="wrap">
<div class="stack" id="stack">
<article class="n" style="--i:0"><b>Payment received</b><small>$48.00 from Maya</small></article>
<article class="n" style="--i:1"><b>New follower</b><small>Jon started following you</small></article>
<article class="n" style="--i:2"><b>Update available</b><small>Version 2.4 is ready</small></article>
</div>
<button class="tg" id="tg" aria-expanded="false" aria-controls="stack">Show all</button>
</div>
</div>
<script>
const s=document.getElementById('stack'),t=document.getElementById('tg');
t.addEventListener('click',()=>{const o=s.classList.toggle('open');t.setAttribute('aria-expanded',String(o));t.textContent=o?'Collapse':'Show all';});
</script>
</body></html>