---
title: "Swipe Deck"
description: "A pile of cards: swipe the top card to a side to choose, as in a dating app. Buttons, arrow keys, and undo do the same without a drag."
url: https://gelatinui.com/components/swipe-deck
markdown_url: https://gelatinui.com/components/swipe-deck.md
access: pro
install: "npx shadcn@latest add @gelatin-ui-pro/swipe-deck"
version: "2026-11-10"
index: https://gelatinui.com/llms.txt
docs_index: https://gelatinui.com/docs/llms.txt
---

# Swipe Deck

> A pile of cards: swipe the top card to a side to choose, as in a dating app. Buttons, arrow keys, and undo do the same without a drag.

Page: https://gelatinui.com/components/swipe-deck

## When to use it

Best for: A quick yes or no on one item at a time, from a short list of cards.

- Set `count`, and give `SwipeDeckCards` the deck size (`h-96 w-72`) and a function that returns a `SwipeDeckCard` for an index.
- Read each choice in `onSwipe` (`index`, `direction`), and remove it again in `onUndo`.
- Add a `SwipeDeckButton` for each side and a `SwipeDeckUndo`, so a choice works without a drag.
- Add `up` or `down` to `directions` for a third answer, such as a strong yes.
- Put a `SwipeDeckEmpty` next to the cards for the end of the deck, with your own text and action.

## When not to use it

- To browse slides with no choice to make, use [Carousel](https://gelatinui.com/components/carousel.md).
- For one action that must be confirmed with a drag, use [Swipe to Confirm](https://gelatinui.com/components/swipe-to-confirm.md).

## Notes for agents

- A release past `threshold` (35% of the width, the height for `up` and `down`) or a fast flick sends the card off; an early release brings it back.
- Only the top cards render: the top one, `visible − 1` behind it, one hidden card, and the cards in flight.
- `index` and `onIndexChange` make it controlled. A new `index` from the parent (a reset) clears the undo history.
- Keys work only on the focused top card itself, not on a field inside it, so a button in a card still works.
- `SwipeDeckStamp` fades in with the drag toward its side, full at the threshold. Its tone comes from the side.
- `useSwipeDeckActor` and `SwipeDeckRootProvider` let the app send `card.swipe` and `card.undo` itself.
- `disabled` stops the drag, the keys, and the buttons.
- `driverRef` drives a real drag of the top card from code (the `DragDriver` contract: `pickUp(at)`, `carry`, `drop`, `putBack`, in viewport px), for a staged scene, a tour, or a test.

## Anatomy

```text
SwipeDeck
├─ SwipeDeckRootProvider (0..n)
├─ SwipeDeckCards (0..n)
│  └─ SwipeDeckStamp (0..n)
├─ SwipeDeckCard (0..n)
├─ SwipeDeckButton (0..n)
├─ SwipeDeckUndo (0..n)
└─ SwipeDeckEmpty (0..n)
```

## API reference

### SwipeDeck

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` | `ReactNode` |  |  |
| `count` | `number` |  | How many cards the deck has. The deck renders only the cards near the top. |
| `index` | `number` |  | The index of the top card (controlled). `count` means the deck is empty. |
| `defaultIndex` | `number` |  | The index of the top card at first (uncontrolled). Default 0. |
| `onIndexChange` | `function` |  | A swipe or an undo moved the top card. A controlled parent must take the new index. |
| `onSwipe` | `function` |  | A card left on a side: from a drag, a flick, a button, an arrow key, or the app (`actor.send`). |
| `onUndo` | `function` |  | Undo brought a card back: the index it has again, and the side it had left on. |
| `directions` | `readonly SwipeDeckDirection[]` |  | The sides a card can leave on. Default `left` and `right`; add `up` or `down`. |
| `threshold` | `number` |  | The share of the width (the height for `up` and `down`) a release must pass. Default 0.35. |
| `visible` | `number` |  | How many cards show in the pile, the top one included. Default 3. |
| `disabled` | `boolean` |  | No drag, no keys, no buttons. |
| `driverRef` | `Ref<DragDriver \| null>` |  | Drives a drag of the top card from code (`DragDriver`, no item): a staged scene or a test grabs the card, carries it, and lets go, and the deck's own release rules fly it out or bring it back, with the tilt, the stamps, and the pile as for a finger. |

### SwipeDeckCards

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` | `function` |  | One card for an index: usually a `SwipeDeckCard`. Called only for the cards near the top. |

### SwipeDeckCard

No props of its own: `className`, `children`, and every other prop go to the element it renders.

### SwipeDeckStamp

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` | `ReactNode` |  |  |
| `direction` | `SwipeDeckDirection` |  | The side whose drag shows this stamp. |

### SwipeDeckButton

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `className` | `string` |  |  |
| `direction` | `SwipeDeckDirection` |  | The side the top card leaves on. |

Also takes every prop of Base UI `Button`: https://base-ui.com/react/components/button

### SwipeDeckUndo

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `className` | `string` |  |  |

Also takes every prop of Base UI `Button`: https://base-ui.com/react/components/button

### SwipeDeckEmpty

No props of its own: `className`, `children`, and every other prop go to the element it renders.

## Styling

| Part | Slot | States | CSS variables | Tokens |
| --- | --- | --- | --- | --- |
| SwipeDeck | `swipe-deck` |  |  |  |
| SwipeDeckRootProvider | `swipe-deck` |  |  |  |
| SwipeDeckCards | `swipe-deck-cards` |  |  |  |
| SwipeDeckCard | `swipe-deck-card` |  |  |  |
| SwipeDeckStamp | `swipe-deck-stamp` |  | `--swipe-deck-opacity` |  |
| SwipeDeckButton | `swipe-deck-button` |  |  |  |
| SwipeDeckUndo | `swipe-deck-undo` |  |  |  |
| SwipeDeckEmpty | `swipe-deck-empty` |  |  |  |

## Usage

Give the cards a size and a card for each index, and read each choice in `onSwipe`.

```tsx title="stay-picker.tsx"
import { HeartIcon, XIcon } from "@phosphor-icons/react/ssr";

import {
  SwipeDeck,
  SwipeDeckButton,
  SwipeDeckCard,
  SwipeDeckCards,
  SwipeDeckStamp,
} from "@/components/pro/cards/swipe-deck";

const stays = ["Boathouse on the lake", "Pine cabin with a sauna", "Hut above the clouds"];

export function StayPicker() {
  return (
    <SwipeDeck
      count={stays.length}
      onSwipe={({ index, direction }) => console.log(stays[index], direction)}
    >
      <SwipeDeckCards className="h-96 w-72">
        {(index) => (
          <SwipeDeckCard className="justify-end p-4">
            <p className="font-semibold">{stays[index]}</p>
            <SwipeDeckStamp direction="right">Save</SwipeDeckStamp>
            <SwipeDeckStamp direction="left">Skip</SwipeDeckStamp>
          </SwipeDeckCard>
        )}
      </SwipeDeckCards>
      <div className="flex gap-4">
        <SwipeDeckButton direction="left" aria-label="Skip">
          <XIcon />
        </SwipeDeckButton>
        <SwipeDeckButton direction="right" aria-label="Save">
          <HeartIcon />
        </SwipeDeckButton>
      </div>
    </SwipeDeck>
  );
}
```

## Compose

Rules:

- Group with a Frame (`group-in-frames`): Put related panels in one `Frame` with its header and footer outside the panels, and keep a plain `Card` for one block of content.
- Compose the parts (`compose-parts`): Build each item from its named parts as children, and pass your text and icons in as parts.
- Every state is designed (`every-state`): Give each view of data its loading, empty, and error states: a skeleton in the final layout, an `Empty` with an illustration and one next action, and an error that says what failed and how to retry.

## Add it

```bash
npx shadcn@latest add @gelatin-ui-pro/swipe-deck
```

It adds 28 registry items: 25 files, 5091 lines, and the npm packages `@base-ui/react`, `@mantine/hooks`, `@xstate/react`, `motion`, `tailwind-merge`, `tailwind-variants`, `xstate`.

## Built on

- [Button](https://gelatinui.com/components/button.md)

## For AI agents

- Every item, one file: https://gelatinui.com/llms.txt
- MCP server (`search_items`, `get_item`, `get_install_plan`): https://gelatinui.com/mcp

## Related

- [Carousel](https://gelatinui.com/components/carousel.md)
- [Swipe to Confirm](https://gelatinui.com/components/swipe-to-confirm.md)
- [Button](https://gelatinui.com/components/button.md)
- [Stack](https://gelatinui.com/components/stack.md)
- [Workspace](https://gelatinui.com/components/workspace.md)

## Keyboard

| Keys | Action |
| --- | --- |
| Arrow Left / Arrow Right | Swipe the focused top card to that side. |
| Arrow Up / Arrow Down | Swipe the top card up or down, when `directions` has that side. |
| Backspace | Undo: bring the last card back. It works on the top card and on the empty deck. |
| Tab | Move from the top card to the buttons. The cards behind it are inert. |

## Accessibility

Only the top card is in the tab order. The cards behind it are `inert`, and each card has its place (`aria-posinset`, `aria-setsize`).

The top card names its keys in `aria-keyshortcuts`. The stamps are `aria-hidden`.

The buttons keep their focus when the deck is empty, so a keyboard user does not lose their place.

## Motion

| Part | Motion |
| --- | --- |
| Drag | none · the card follows the finger and tilts up to 12° at a full width, in the same frame |
| Release | sheet · a card let go before the threshold goes back on the sheet clock (300ms) |
| Fly out | panel · a thrown card keeps the speed of the finger, 200 to 360ms on the panel curve; a button or a key uses the sheet clock |
| Pile | panel · the cards behind rise one place on the clock of the card that left or came back |
| Undo | sheet · the last card slides back from its side to the top of the pile |
