Components

Card Stack

A swipeable card stack for React: drag the top card left or right (or use the buttons and arrow keys) and the cards behind spring forward to take its place. Loops or ends, reports every swipe with its direction, and works for testimonials, onboarding, voting and Tinder-style decks.

  • Swipe to dismiss
  • Buttons & arrow keys
  • Loop or finite
  • onSwipe callback
  • Spring physics
  • Reduced-motion crossfade
We replaced three carousel libraries with this. Swiping feels native on every phone we tested.
Ava ChenDesign lead, Northwind

Card 1 of 5

Installation

$ npx shadcn@latest add https://duskui.com/r/card-stack.json

Cards are stacked in a CSS grid, so the stack takes the height of its tallest card plus the peek, and never jumps as cards change. Give your card content a fixed height for the tidiest stack.

Usage

deck.tsx
"use client"

import { CardStack } from "@/components/dusk/card-stack/card-stack"

const people = [
  { name: "Ava", bio: "Designer" },
  { name: "Marcus", bio: "Founder" },
  { name: "Priya", bio: "Engineer" },
]

export function Deck() {
  return (
    <CardStack
      items={people}
      getKey={(p) => p.name}
      cardClassName="p-6"
      onSwipe={(direction, person) => console.log(direction, person.name)}
      renderItem={(p) => (
        <div className="h-40">
          <p className="text-lg font-semibold">{p.name}</p>
          <p className="text-sm text-muted-foreground">{p.bio}</p>
        </div>
      )}
    />
  )
}

Examples

Finite stack with callbacks

With loop={false} the stack ends and shows empty. onSwipe receives the direction and item, and labels renames the buttons. Change the stack's key to start over.

Would you use this?

Dark mode scheduling

Switch themes at sunset automatically.

Card 1 of 5

Your votes

  • Swipe, click or use ← →

Deep stack without buttons

visible, offset and scaleStep shape the pile. With controls={false} it is swiped by drag or with the arrow keys once focused.

Graphite

#3f3f46

Card 1 of 5

API Reference

Any other div prop is passed to the root. A drag past threshold or a fast flick counts as a swipe; anything less springs the card back.

PropTypeDefaultDescription
itemsT[]—The data for each card.
renderItem(item: T, index: number) => ReactNode—Renders one card's content.
getKey(item: T, index: number) => Key—Stable key for an item. Defaults to its index.
loopbooleantrueStart over after the last card.
visiblenumber3How many cards are visible in the pile.
offsetnumber14How far each card behind peeks out, in px.
scaleStepnumber0.05How much smaller each card behind is.
thresholdnumber100Drag distance in px that counts as a swipe.
draggablebooleantrueLet people drag the top card away.
controlsbooleantrueShow the swipe left / right buttons and the counter.
onSwipe(direction: "left" | "right", item: T, index: number) => void—Called when a card leaves.
onEnd() => void—Called after the last card when loop is off.
emptyReactNode"No more cards"Shown when a finite stack is done.
labels{ left?: string; right?: string }—Accessible labels for the buttons.
labelstring"Card stack"Accessible name of the stack.
cardClassNamestring—Classes for every card.

Accessibility

  • The stack is a focusable, labelled region: ArrowLeft and ArrowRight swipe the top card.
  • The buttons have accessible labels and use aria-disabled when the stack is done, so focus is never lost.
  • Only the top card is exposed; cards behind it are inert and hidden from assistive tech.
  • A polite live region announces "Card 2 of 5" after every swipe.
  • With prefers-reduced-motion cards no longer fly or rotate: they simply crossfade.