---
title: "Attachment"
description: "One file in your app as a chip, tile, row, card, or gallery photo. It shows upload progress and has Retry, Pause, and Undo."
url: https://gelatinui.com/components/attachment
markdown_url: https://gelatinui.com/components/attachment.md
access: free
install: "npx shadcn@latest add @gelatin-ui/attachment"
registry_item: https://gelatinui.com/r/attachment.json
version: "2026-11-16"
index: https://gelatinui.com/llms.txt
docs_index: https://gelatinui.com/docs/llms.txt
---

# Attachment

> One file in your app as a chip, tile, row, card, or gallery photo. It shows upload progress and has Retry, Pause, and Undo.

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

## When to use it

Best for: Every file a person sees in an app: a chip, a tile, a row, a card, or a gallery cell, with its upload status.

- Use it for the files of a composer, a message, an email, a task, or a form.
- Pass `uploads` from `useFileUploads` to show progress, Pause, Retry, and Undo.
- Set `mode="sent"` for files that were sent: a press opens the file.
- Pass `onOpen` to open a file in your own viewer.

## When not to use it

- To only show the icon of a file type, use [File Icon](https://gelatinui.com/components/file-icon.md).
- To let a person drop or pick files, use [Dropzone](https://gelatinui.com/components/dropzone.md).

## Notes for agents

- `Attachments` is the list root (`<ul>`); each `Attachment` is one `<li>` with a stable `key`.
- An `Attachment` needs a `file` or an `entry` from the upload queue; it throws with neither.
- With no children, `Attachments` renders the `uploads` entries, else `files`.
- Group parts (`AttachmentsHeader`, `AttachmentsSummary`, `AttachmentsFilters`, `AttachmentsBatchBar`) go inside `Attachments`.
- A saved file `url` must be http, https, blob, or relative; other links open nothing.
- `status` wins over the entry status, so an app can set `processing`, `blocked`, or `locked`.

## Anatomy

```text
Attachment
├─ Attachments (0..n)
├─ AttachmentPreview (0..n)
├─ AttachmentScan (0..n)
├─ AttachmentName (0..n)
├─ AttachmentMeta (0..n)
├─ AttachmentProgress (0..n)
├─ AttachmentActions (0..n)
├─ AttachmentRemove (0..n)
├─ AttachmentRetry (0..n)
├─ AttachmentPause (0..n)
├─ AttachmentDownload (0..n)
├─ AttachmentOpen (0..n)
├─ AttachmentMenu (0..n)
├─ AttachmentSelect (0..n)
├─ AttachmentsHeader (0..n)
├─ AttachmentsDownloadAll (0..n)
├─ AttachmentsSummary (0..n)
├─ AttachmentsFilters (0..n)
├─ AttachmentsOverflow (0..n)
├─ AttachmentsRemoved (0..n)
└─ AttachmentsBatchBar (0..n)
```

## API reference

### Attachments

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `layout` | `"card" \| "chip" \| "gallery" \| "row" \| "tile"` | "chip" | `chip` (default), `tile`, `row`, `card`, or `gallery` (photos sent together). |
| `size` | `"default" \| "sm"` | "default" | `default` or `sm` (chip 32, tile 72, a compact row, card 200). |
| `mode` | `"compose" \| "sent"` | "compose" | `compose` (default): a draft with Remove. `sent`: the files of a message; a press opens. |
| `uploads` | `FileUploadsSource` |  | The upload queue (`useFileUploads`): Remove, Retry, Pause, and Undo act on it by entry id. |
| `files` | `readonly AttachmentFile[]` |  | The saved files to show when there are no children (and no `uploads`). |
| `onOpen` | `AttachmentOpenHandler` |  | Opens a file (the File Viewer seam): a press on a sent file, Open, or a gallery photo. With none, Open goes to the safe `url` in a new tab, else it downloads the file. |
| `max` | `number` |  | Shows this many files, then a `+N` button (`AttachmentsOverflow`). |
| `filter` | `"active" \| "all" \| "done" \| "failed"` |  | The filter of the files (`AttachmentsFilters`). Controlled. |
| `defaultFilter` | `"active" \| "all" \| "done" \| "failed"` | "all" |  |
| `onFilterChange` | `function` |  |  |
| `selectable` | `boolean` | false | Shows a checkbox on each file and the selection of `AttachmentsBatchBar`. |
| `selected` | `readonly string[]` |  | The ids of the selected files. Controlled. |
| `defaultSelected` | `readonly string[]` | NO_IDS |  |
| `onSelectedChange` | `function` |  |  |
| `labels` | `Partial<AttachmentLabels>` |  | The words (`ATTACHMENT_LABELS`). Keep the object stable. |
| `locale` | `string` |  | The locale of sizes and times. Default: the `DisplayLocaleProvider` locale. |
| `children` | `ReactNode` |  | `Attachment` items (each with a stable `key`) and group parts. None: the default list. |

### Attachment

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` | `ReactNode` |  | The parts of the file. None: the default anatomy of the layout and mode. |
| `file` | `AttachmentFile` |  | The file: a page `File` (a draft) or a saved file. Optional with an `entry`. |
| `id` | `string` |  | A stable id. Default: the entry id, the saved file id, or the name. |
| `entry` | `FileUploadEntry` |  | The upload entry of `useFileUploads`: it sets the file, status, progress, error, and speed. |
| `status` | `"blocked" \| "done" \| "error" \| "locked" \| "paused" \| "processing" \| "queued" \| "uploading"` |  | Where the file is (wins over the entry status, so an app can set `processing`). |
| `progress` | `number \| null` |  | 0 to 100 while uploading; `null` while not known. |
| `error` | `string` |  | Why the file failed or was blocked. |
| `detail` | `string` |  | The meta words in your words ("Reading 3 of 12 pages", "Link expired on Nov 2"). |
| `onRemove` | `function` |  | Removes the file when the app owns the list (no `uploads`, no Dropzone around it). It wins over the queue and the host list. Remove shows only when one of them can act. |
| `onRetry` | `function` |  | Sends a failed file again when the app owns the upload. It wins over the queue and the host. |

### AttachmentPreview

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

### AttachmentName

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

### AttachmentMeta

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

### AttachmentProgress

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

### AttachmentActions

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

### AttachmentRemove

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `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. |
| `glass` | `"clear" \| "dark" \| "light"` |  |  |
| `children` | `ReactNode` |  | The icon. Default: an X (a trash can on a finished row). |

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

### AttachmentRetry

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `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. |
| `glass` | `"clear" \| "dark" \| "light"` |  |  |
| `children` | `ReactNode` |  | The word on a row, the icon elsewhere. Default: "Retry", a turn arrow. |

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

### AttachmentPause

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `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. |
| `glass` | `"clear" \| "dark" \| "light"` |  |  |

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

### AttachmentDownload

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `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. |
| `glass` | `"clear" \| "dark" \| "light"` |  |  |

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

### AttachmentOpen

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

### AttachmentMenu

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `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. |
| `glass` | `"clear" \| "dark" \| "light"` |  |  |
| `children` | `ReactNode` |  | The menu items. None: Open, Download, Copy link, and Delete (on a draft). |

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

### AttachmentSelect

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `className` | `string` |  |  |
| `size` | `"default" \| "lg"` |  | `default` 16px, or `lg` 20px. Default: the `CheckboxGroup` size, else `default`. |

Also takes every prop of Base UI `Checkbox.Root`: https://base-ui.com/react/components/checkbox

### AttachmentsHeader

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

### AttachmentsDownloadAll

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `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. |
| `glass` | `"clear" \| "dark" \| "light"` |  |  |
| `rounded` | `"default" \| "full"` |  |  |
| `children` | `ReactNode` |  |  |

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

### AttachmentsSummary

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `uploads` | `FileUploadsSource` |  | The queue, when the summary sits outside `Attachments` (the Uploads Panel head). |
| `labels` | `Partial<AttachmentLabels>` |  |  |

### AttachmentsFilters

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `uploads` | `FileUploadsSource` |  | The queue, when the filters sit outside `Attachments`. |
| `filter` | `"active" \| "all" \| "done" \| "failed"` |  | The filter, when the filters sit outside `Attachments`. Controlled. |
| `defaultFilter` | `"active" \| "all" \| "done" \| "failed"` | "all" | The first filter outside `Attachments`. Default `all`. |
| `onFilterChange` | `function` |  |  |
| `labels` | `Partial<AttachmentLabels>` |  |  |

### AttachmentsOverflow

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `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. |
| `glass` | `"clear" \| "dark" \| "light"` |  |  |
| `rounded` | `"default" \| "full"` |  |  |
| `children` | `ReactNode` |  |  |

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

### AttachmentsRemoved

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

### AttachmentsBatchBar

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

## Styling

| Part | Slot | States | CSS variables | Tokens |
| --- | --- | --- | --- | --- |
| Attachments | `attachments` |  | `--attachments-radius` |  |
| Attachment | `attachment` | `data-failed`, `data-mode`, `data-selected`, `data-status` | `--attachments-radius`, `--radius` | `status-colors` |
| AttachmentPreview | `attachment-preview` |  |  |  |
| AttachmentScan | `attachment-scan` |  |  | `status-colors` |
| AttachmentName | `attachment-name` |  |  |  |
| AttachmentMeta | `attachment-meta` |  |  | `status-colors` |
| AttachmentProgress | `attachment-progress` |  | `--primary-foreground` |  |
| AttachmentActions | `attachment-actions` |  |  | `motion-timing` |
| AttachmentRemove | `attachment-remove` |  |  |  |
| AttachmentRetry | `attachment-retry` |  |  | `status-colors` |
| AttachmentPause | `attachment-pause` |  |  |  |
| AttachmentDownload | `attachment-download` |  |  |  |
| AttachmentOpen | `attachment-open` |  |  | `motion-timing` |
| AttachmentMenu | `attachment-menu` |  |  |  |
| AttachmentSelect | `attachment-select` |  |  |  |
| AttachmentsHeader | `attachments-header` |  |  |  |
| AttachmentsDownloadAll | `attachments-download-all` |  |  |  |
| AttachmentsSummary | `attachments-summary` |  |  |  |
| AttachmentsFilters | `attachments-filters` |  |  | `status-colors` |
| AttachmentsOverflow | `attachments-overflow` |  |  |  |
| AttachmentsRemoved | `attachments-removed` |  | `--radius` |  |
| AttachmentsBatchBar | `attachments-batch-bar` |  |  |  |

## Usage

Put an `Attachment` for each file in `Attachments`, and compose its parts as children.

```tsx title="message-files.tsx"
import {
  Attachment,
  AttachmentActions,
  AttachmentDownload,
  AttachmentMenu,
  AttachmentMeta,
  AttachmentName,
  AttachmentPreview,
  Attachments,
  AttachmentsDownloadAll,
  AttachmentsHeader,
} from "@/components/files/attachment";

const FILES = [
  { id: "deck", name: "Q4-board-deck.pdf", size: 2_400_000, url: "/files/q4-board-deck.pdf", pages: 12 },
  { id: "sales", name: "Sales-2026.xlsx", size: 220_000, url: "/files/sales-2026.xlsx" },
];

export function MessageFiles() {
  return (
    <Attachments layout="row" mode="sent" className="w-md">
      <AttachmentsHeader>
        <AttachmentsDownloadAll />
      </AttachmentsHeader>
      {FILES.map((file) => (
        <Attachment key={file.id} file={file}>
          <AttachmentPreview />
          <span className="flex min-w-0 flex-1 flex-col">
            <AttachmentName />
            <AttachmentMeta />
          </span>
          <AttachmentActions>
            <AttachmentDownload />
            <AttachmentMenu />
          </AttachmentActions>
        </Attachment>
      ))}
    </Attachments>
  );
}
```

## Compose

Build it with:

- [Dropzone](https://gelatinui.com/components/dropzone.md): Takes the files by drop or by a press.
- [Progress](https://gelatinui.com/components/progress.md): Shows how far an upload is.
- [Files Illustration 01](https://gelatinui.com/components/files-illustration-01.md): Fills the empty drop area.

Rules:

- 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.
- No layout jump (`no-layout-jump`): When a state change adds, removes, or resizes content, reserve its space or animate its size, so nothing below it jumps.
- Real content (`real-content`): Fill the UI with content of the real product (real names, amounts, dates, and states), never lorem text or "Item 1".
- Compose the parts (`compose-parts`): Build each item from its named parts as children, and pass your text and icons in as parts.

Patterns: `gelatin://patterns/file-upload`

## Add it

```bash
npx shadcn@latest add @gelatin-ui/attachment
```

It adds 100 registry items: 95 files, 18676 lines, and the npm packages `@base-ui/react`, `@mantine/hooks`, `@phosphor-icons/react`, `@unpic/core`, `@xstate/react`, `clsx`, `motion`, `tailwind-merge`, `tailwind-variants`, `xstate`.

## Built on

- [Button](https://gelatinui.com/components/button.md)
- [Checkbox](https://gelatinui.com/components/checkbox.md)
- [Circular Progress](https://gelatinui.com/components/circular-progress.md)
- [File Icon](https://gelatinui.com/components/file-icon.md)
- [File Size](https://gelatinui.com/components/file-size.md)
- [Image](https://gelatinui.com/components/image.md)
- [Menu](https://gelatinui.com/components/menu.md)
- [Progress](https://gelatinui.com/components/progress.md)
- [Tabs](https://gelatinui.com/components/tabs.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

- [File Icon](https://gelatinui.com/components/file-icon.md)
- [Dropzone](https://gelatinui.com/components/dropzone.md)
- [File Trigger](https://gelatinui.com/components/file-trigger.md)
- [Progress](https://gelatinui.com/components/progress.md)
- [Circular Progress](https://gelatinui.com/components/circular-progress.md)

## Keyboard

| Keys | Action |
| --- | --- |
| Tab | Moves through the open layer and the actions of each file. |
| Enter, Space | Opens a sent file, or runs the focused action (Remove, Retry, Pause, Download). |
| Delete, Backspace | Removes a draft file from a control on it. The focus moves to the next file. |

## Motion

| Part | Motion |
| --- | --- |
| Enter | panel · a new file fades in from 96% scale |
| Exit | fade · a removed file fades out and leaves the flow at once |
| Reflow | chart · the files after a removed one glide to their new place |
| Scan | sine · a line moves down the preview while the server reads the file, 1.6 s a pass |
| Actions | fade · the actions of a sent card show on hover and focus |
