---
title: "Stack"
description: "A pile of any items: the front item whole and the rest peeking out behind it. It opens into a full list on hover, focus, tap, or a button."
url: https://gelatinui.com/components/stack
markdown_url: https://gelatinui.com/components/stack.md
access: free
install: "npx shadcn@latest add @gelatin-ui/stack"
registry_item: https://gelatinui.com/r/stack.json
version: "2026-11-10"
index: https://gelatinui.com/llms.txt
docs_index: https://gelatinui.com/docs/llms.txt
---

# Stack

> A pile of any items: the front item whole and the rest peeking out behind it. It opens into a full list on hover, focus, tap, or a button.

Page: https://gelatinui.com/components/stack

## When to use it

Best for: A few items of the same kind that take little room until the reader opens them.

- Put each item in a `StackItem` with a `key`. The first child is the front item.
- Give each item its own surface (a Card, a bordered box): the item draws nothing.
- Use `expandOn="click"` with a `StackTrigger` when the pile should open only on a press.
- Add `StackNext` and `StackPrevious` to bring another item to the front.
- Use `variant="fan"` for photos or cards that should turn and spread.

## When not to use it

- For slides that a reader swipes through side by side, use [Carousel](https://gelatinui.com/components/carousel.md).
- For cards that pin one after another as the page scrolls, use [Sticky Card Stack](https://gelatinui.com/components/sticky-card-stack.md).
- For a pile where each card is a yes or no choice, use [Swipe Deck](https://gelatinui.com/components/swipe-deck.md).

## Notes for agents

- `expandOn`: `hover` (default) opens on pointer hover, on focus inside, and on a tap on a touch screen; `click` opens only from a `StackTrigger` or the `expanded` prop; `always` stays open. Escape closes it.
- With `hover`, the list is a tab stop: focus on it, or on a control inside, opens the pile.
- While closed, every item behind the front one is `inert`, so only the front item can be reached.
- `direction` sets the side the items behind peek out of: `up`, `down`, `start`, or `end` (`start` and `end` follow the text direction).
- The list measures each item and moves to the new size on the toast clock. An item added later comes in past the anchor edge, as a new toast does.
- The fan spreads each card to the side by 0.6 of the front width. Leave room around a spread fan: the list does not grow for it.
- `index` and `onIndexChange` control the front item; `expanded` and `onExpandedChange` control the open state.

## Anatomy

```text
Stack
├─ StackList (0..n)
├─ StackItem (0..n)
├─ StackTrigger (0..n)
├─ StackNext (0..n)
└─ StackPrevious (0..n)
```

## API reference

### Stack

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `direction` | `"down" \| "end" \| "start" \| "up"` | "up" |  |
| `variant` | `"fan" \| "stack"` | "stack" |  |
| `peek` | `number` | 8 | How many px of each item behind shows past the item in front of it. Default 8. |
| `scaleStep` | `number` | 0.05 | How much smaller each item behind is: item n scales by `1 − scaleStep × n`. Default 0.05. |
| `maxVisible` | `number` | 3 | The most items that show while collapsed, the front one included. Default 3. |
| `gap` | `number` | 8 | The px between two items while expanded (`stack` variant). Default 8. |
| `fanAngle` | `number` | 3 | `fan`: the degrees each item behind turns while collapsed, to alternate sides. Default 3. |
| `fanSpread` | `number` | 12 | `fan`: the degrees between two cards of the spread hand while expanded. Default 12. |
| `expandOn` | `StackExpandOn` | "hover" | `hover` (default): expands while the pointer is over the list or focus is inside it, and on a tap on a touch screen (a tap outside collapses it). `click`: only a `StackTrigger` (or the `expanded` prop) expands it. `always`: always expanded. Escape collapses an expanded stack. |
| `expanded` | `boolean` |  | The expanded state, controlled. |
| `defaultExpanded` | `boolean` | false | The expanded state at the start, uncontrolled. Default `false`. |
| `onExpandedChange` | `function` |  |  |
| `index` | `number` |  | The child index of the front item, controlled. `StackNext` and `StackPrevious` change it. |
| `defaultIndex` | `number` | 0 | The child index of the front item at the start, uncontrolled. Default 0 (the first child). |
| `onIndexChange` | `function` |  | Gets the new front index, wrapped into `0 … count − 1`. |

### StackList

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

### StackItem

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

### StackTrigger

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `glass` | `"clear" \| "dark" \| "light"` |  |  |
| `rounded` | `"default" \| "full"` |  |  |
| `size` | `"default" \| "icon" \| "icon-lg" \| "icon-sm" \| "icon-xs" \| "lg" \| "sm" \| "xl" \| "xs"` | "sm" |  |
| `variant` | `"dashed" \| "default" \| "destructive" \| "destructive-outline" \| "ghost" \| "link" \| "media" \| "outline" \| "secondary"` | "ghost" |  |
| `className` | `string` |  |  |
| `busy` | `boolean` |  | The button waits for the app (busy words): a spinner, `aria-busy`, and no clicks. Focus stays on the button. The style hook stays `data-loading`. |
| `spinnerPlacement` | `"center" \| "start"` |  | `center` (default): the spinner covers the label. `start`: it takes the leading icon slot. The icon sizes always use `center`, because their one icon is the label. |

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

### StackNext

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `glass` | `"clear" \| "dark" \| "light"` |  |  |
| `rounded` | `"default" \| "full"` |  |  |
| `size` | `"default" \| "icon" \| "icon-lg" \| "icon-sm" \| "icon-xs" \| "lg" \| "sm" \| "xl" \| "xs"` | "icon-sm" |  |
| `variant` | `"dashed" \| "default" \| "destructive" \| "destructive-outline" \| "ghost" \| "link" \| "media" \| "outline" \| "secondary"` | "outline" |  |
| `className` | `string` |  |  |
| `busy` | `boolean` |  | The button waits for the app (busy words): a spinner, `aria-busy`, and no clicks. Focus stays on the button. The style hook stays `data-loading`. |
| `spinnerPlacement` | `"center" \| "start"` |  | `center` (default): the spinner covers the label. `start`: it takes the leading icon slot. The icon sizes always use `center`, because their one icon is the label. |

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

### StackPrevious

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `glass` | `"clear" \| "dark" \| "light"` |  |  |
| `rounded` | `"default" \| "full"` |  |  |
| `size` | `"default" \| "icon" \| "icon-lg" \| "icon-sm" \| "icon-xs" \| "lg" \| "sm" \| "xl" \| "xs"` | "icon-sm" |  |
| `variant` | `"dashed" \| "default" \| "destructive" \| "destructive-outline" \| "ghost" \| "link" \| "media" \| "outline" \| "secondary"` | "outline" |  |
| `className` | `string` |  |  |
| `busy` | `boolean` |  | The button waits for the app (busy words): a spinner, `aria-busy`, and no clicks. Focus stays on the button. The style hook stays `data-loading`. |
| `spinnerPlacement` | `"center" \| "start"` |  | `center` (default): the spinner covers the label. `start`: it takes the leading icon slot. The icon sizes always use `center`, because their one icon is the label. |

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

## Styling

| Part | Slot | States | CSS variables | Tokens |
| --- | --- | --- | --- | --- |
| Stack | `stack` | `data-clamped`, `data-ready`, `data-sized` | `--stack-list-size` |  |
| StackList | `stack-list` | `data-clamped`, `data-ready`, `data-sized` | `--stack-list-size` |  |
| StackItem | `stack-item` | `data-clamped`, `data-ready`, `data-sized` | `--stack-list-size` |  |
| StackTrigger | `stack-trigger` |  |  | `motion-timing` |
| StackNext | `stack-next` |  |  |  |
| StackPrevious | `stack-previous` |  |  |  |

## Usage

Put each item in a `StackItem` with a `key`, and add a trigger to open the pile.

```tsx title="notifications.tsx"
import { Stack, StackItem, StackList, StackTrigger } from "@/components/cards/stack";

const notifications = [
  { id: "comment", text: "Mila commented on Q3 roadmap" },
  { id: "assign", text: "Kenji assigned you Launch checklist" },
  { id: "invite", text: "Lena invited you to Design review" },
];

export function Notifications() {
  return (
    <Stack direction="down" expandOn="click">
      <StackTrigger />
      <StackList aria-label="Notifications">
        {notifications.map((item) => (
          <StackItem key={item.id}>
            <div className="w-80 rounded-xl border bg-card p-3 text-sm">{item.text}</div>
          </StackItem>
        ))}
      </StackList>
    </Stack>
  );
}
```

## 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/stack
```

It adds 30 registry items: 27 files, 4774 lines, and the npm packages `@base-ui/react`, `@mantine/hooks`, `@phosphor-icons/react`, `@xstate/react`, `clsx`, `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

- [Sticky Card Stack](https://gelatinui.com/components/sticky-card-stack.md)
- [Toast](https://gelatinui.com/components/toast.md)
- [Card](https://gelatinui.com/components/card.md)
- [Swipe Deck](https://gelatinui.com/components/swipe-deck.md)
- [Workspace](https://gelatinui.com/components/workspace.md)

## Keyboard

| Keys | Action |
| --- | --- |
| Tab | Move the focus onto the pile: with `hover`, the pile opens. |
| Enter / Space | On a `StackTrigger`, open or close the pile. On `StackNext` or `StackPrevious`, bring another item to the front. |
| Escape | Close an open pile. |

## Accessibility

The pile is a list. While it is closed, the items behind the front one are `inert`: out of the tab order and hidden from screen readers.

`StackTrigger` sets `aria-expanded` and `aria-controls`. `StackNext` and `StackPrevious` have names ("Show next item", "Show previous item"); translate them with `aria-label`.

## Motion

| Part | Motion |
| --- | --- |
| Open and close | toast · the items move apart or back together, and the list grows or shrinks on the same clock (300ms) |
| Cycle | toast · the front item goes to the back and the next one comes forward |
| Add | toast · a new item comes in from past the anchor edge and fades in |
| Remove | toast-exit · a removed item leaves past the anchor edge and fades out (150ms) |
