Card Stack is a Tinder-style React component that renders a deck of cards and lets the top one be grabbed and flicked left or right. Past the configurable drag threshold the card flies off and fires onSwipe; under it, the next card promotes to the top. Two more cards are mounted below in a scaled, offset stack to give a sense of depth without rendering the whole deck.
Useful for product tours, onboarding sequences, quote reels, and anywhere the "cycle through a small set" interaction beats a static carousel.
Installation
Usage
import { CardStack } from "@/components/ui/card-stack";
const items = [
{ id: "1", title: "First" },
{ id: "2", title: "Second" },
{ id: "3", title: "Third" },
];
export function Example() {
return (
<div className="relative h-72 w-xs">
<CardStack
items={items}
getKey={(item) => item.id}
renderCard={(item) => (
<div className="flex h-full items-center justify-center">
<h3 className="text-lg font-medium">{item.title}</h3>
</div>
)}
onSwipe={(item, direction) => console.log(item, direction)}
/>
</div>
);
}Props
| Prop | Type | Default | Description |
|---|---|---|---|
items | T[] | — | Items to render as cards. First is on top. |
renderCard | (item, index) => ReactNode | — | Renders each card's content. |
getKey | (item, index) => string | number | index | Stable key per item. |
threshold | number | 120 | Drag distance in pixels that triggers a swipe. |
stackSize | number | 3 | How many cards are mounted at once. |
stackOffset | number | 14 | Pixel offset between stacked cards. |
stackScale | number | 0.06 | Scale decrement per level back in the stack. |
onSwipe | (item, direction) => void | — | Fires when a card is swiped off ("left" | "right"). |
onEmpty | () => void | — | Fires when the stack has no cards left. |
className | string | — | Extra classes on the stack wrapper. |
cardClassName | string | — | Extra classes on each card surface. |
Related components
- 3D Layered Card
A 3D card with layered effects and animations.
- Animated Code Block
Code snippets with typing and highlighting effects.
- Audio Waveform
A live frequency visualiser for an HTML audio source, driven by WebAudio's AnalyserNode. Bars or waveform mode.
- Bubble Background
An interactive floating bubble animation for backgrounds.
