---
title: "Alert Dialog"
description: "A window that asks a yes or no question before an action that deletes data or cannot be undone. The page waits until the person answers."
url: https://gelatinui.com/components/alert-dialog
markdown_url: https://gelatinui.com/components/alert-dialog.md
access: free
install: "npx shadcn@latest add @gelatin-ui/alert-dialog"
registry_item: https://gelatinui.com/r/alert-dialog.json
version: "2026-11-08"
index: https://gelatinui.com/llms.txt
docs_index: https://gelatinui.com/docs/llms.txt
---

# Alert Dialog

> A window that asks a yes or no question before an action that deletes data or cannot be undone. The page waits until the person answers.

Page: https://gelatinui.com/components/alert-dialog

## When to use it

Best for: A yes or no question before a destructive or blocking action.

- Use it when the user must answer before they go on. An outside click does nothing.
- Name the thing and the result in the title: "Delete Q3 roadmap.pdf?", not "Are you sure?".
- Put `AlertDialogCancel` first in the footer, so the safe choice gets the first focus.

## When not to use it

- For a task, a form, or a detail view, use a [Dialog](https://gelatinui.com/components/dialog.md).
- For a note that needs no answer, use a [Toast](https://gelatinui.com/components/toast.md).

## Notes for agents

- An outside click does not close it: the user must press Cancel or the action.
- Put `AlertDialogCancel` before the action in the footer, so the safe choice gets the first focus.

## Anatomy

```text
AlertDialog
├─ AlertDialogTrigger (0..n)
├─ AlertDialogPortal (0..n)
├─ AlertDialogOverlay (0..n)
├─ AlertDialogContent (0..n)
├─ AlertDialogHeader (0..n)
├─ AlertDialogMedia (0..n)
├─ AlertDialogTitle (0..n)
├─ AlertDialogDescription (0..n)
├─ AlertDialogFooter (0..n)
├─ AlertDialogCancel (0..n)
└─ AlertDialogAction (0..n)
```

## API reference

### AlertDialog

Also takes every prop of Base UI `AlertDialog.Root`: https://base-ui.com/react/components/alert-dialog

### AlertDialogTrigger

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

Also takes every prop of Base UI `Dialog.Trigger`: https://base-ui.com/react/components/dialog

### AlertDialogPortal

Also takes every prop of Base UI `Dialog.Portal`: https://base-ui.com/react/components/dialog

### AlertDialogOverlay

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

Also takes every prop of Base UI `Dialog.Backdrop`: https://base-ui.com/react/components/dialog

### AlertDialogContent

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `size` | `"default" \| "sm"` | "default" |  |
| `className` | `string` |  |  |
| `portalProps` | `Omit` |  | Other Base UI props of the inner parts. A `className` here adds to the component classes. |
| `backdropProps` | `AlertDialogOverlayProps` |  |  |
| `viewportProps` | `PopupPartProps` |  |  |

Also takes every prop of Base UI `Dialog.Popup`: https://base-ui.com/react/components/dialog

### AlertDialogHeader

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

### AlertDialogMedia

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `tone` | `"destructive" \| "info" \| "neutral" \| "success" \| "warning"` |  |  |

### AlertDialogTitle

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

### AlertDialogDescription

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

### AlertDialogFooter

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

### AlertDialogCancel

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `rounded` | `"default" \| "full"` |  |  |
| `size` | `"default" \| "icon" \| "icon-lg" \| "icon-sm" \| "icon-xs" \| "lg" \| "sm" \| "xl" \| "xs"` |  |  |
| `variant` | `"dashed" \| "default" \| "destructive" \| "destructive-outline" \| "ghost" \| "link" \| "media" \| "outline" \| "secondary"` | "outline" |  |
| `className` | `string` |  |  |

### AlertDialogAction

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `glass` | `"clear" \| "dark" \| "light"` |  |  |
| `rounded` | `"default" \| "full"` |  |  |
| `size` | `"default" \| "icon" \| "icon-lg" \| "icon-sm" \| "icon-xs" \| "lg" \| "sm" \| "xl" \| "xs"` |  |  |
| `variant` | `"dashed" \| "default" \| "destructive" \| "destructive-outline" \| "ghost" \| "link" \| "media" \| "outline" \| "secondary"` |  |  |
| `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 |
| --- | --- | --- | --- | --- |
| AlertDialogTrigger | `alert-dialog-trigger` | `data-disabled` |  |  |
| AlertDialogPortal | `alert-dialog-portal` |  |  |  |
| AlertDialogOverlay | `alert-dialog-overlay` |  |  |  |
| AlertDialogContent | `alert-dialog-content` |  |  |  |
| AlertDialogHeader | `alert-dialog-header` |  |  |  |
| AlertDialogMedia | `alert-dialog-media` |  |  |  |
| AlertDialogTitle | `alert-dialog-title` |  |  |  |
| AlertDialogDescription | `alert-dialog-description` |  |  |  |
| AlertDialogFooter | `alert-dialog-footer` |  |  |  |
| AlertDialogCancel | `alert-dialog-cancel` |  |  |  |
| AlertDialogAction | `alert-dialog-action` |  |  |  |

## Usage

`AlertDialogAction` does not close the alert. Control `open`, and close it when the action ends.

```tsx title="delete-file-dialog.tsx"
import { useState } from "react";
import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger } from "@/components/ui/alert-dialog";
import { Button } from "@/components/ui/button";

export function DeleteFileDialog({ onDelete }: { onDelete: () => void }) {
  const [open, setOpen] = useState(false);
  const remove = () => {
    onDelete();
    setOpen(false);
  };
  return (
    <AlertDialog open={open} onOpenChange={setOpen}>
      <AlertDialogTrigger render={<Button variant="destructive" />}>Delete file</AlertDialogTrigger>
      <AlertDialogContent>
        <AlertDialogHeader>
          <AlertDialogTitle>Delete Q3 roadmap.pdf?</AlertDialogTitle>
          <AlertDialogDescription>The file goes to the trash for 30 days.</AlertDialogDescription>
        </AlertDialogHeader>
        <AlertDialogFooter>
          <AlertDialogCancel>Cancel</AlertDialogCancel>
          <AlertDialogAction variant="destructive" onClick={remove}>Delete file</AlertDialogAction>
        </AlertDialogFooter>
      </AlertDialogContent>
    </AlertDialog>
  );
}
```

## Compose

Build it with:

- [Button](https://gelatinui.com/components/button.md): Confirms or cancels; the confirm label names the action.
- [Toast](https://gelatinui.com/components/toast.md): Says it is done, with Undo when you can undo it.

Rules:

- Sheets on phones (`phone-sheets`): Show a dialog or a large popover as a bottom sheet on a small screen.
- Labels real apps use (`real-labels`): Write the button and menu labels that real apps use ("Create API key", "Invite members"), with no "…" at the end.
- Touch targets (`touch-targets`): Give every control a hit area of at least 44 px on touch screens, even when it looks smaller.
- 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/confirm-action`

## Add it

```bash
npx shadcn@latest add @gelatin-ui/alert-dialog
```

It adds 22 registry items: 19 files, 3237 lines, and the npm packages `@base-ui/react`, `clsx`, `tailwind-merge`, `tailwind-variants`.

## 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

- [Dialog](https://gelatinui.com/components/dialog.md): Pick Dialog for a task, a form, or a detail view that needs more than a yes or no answer.
- [Button](https://gelatinui.com/components/button.md)
- [Toast](https://gelatinui.com/components/toast.md): Pick Toast for a note that needs no answer and closes on its own.
- [Alert](https://gelatinui.com/components/alert.md): Pick Alert for a message that stays in the page and needs no answer.

## Keyboard

| Keys | Action |
| --- | --- |
| Esc | Closes the alert dialog. Treat it as Cancel. |
| Tab | Moves the focus to the next button. The focus stays in the alert dialog. |
| Shift Tab | Moves the focus to the previous button. |
| Enter | Presses the focused button. |

## Accessibility

The popup has `role="alertdialog"` from Base UI, and it is always modal. `AlertDialogTitle` is an `h2` that names it, and a screen reader reads `AlertDialogDescription` when the alert opens.

The focus moves to the first focusable element and stays in the alert. Put `AlertDialogCancel` first, so the safe choice has the first focus and Enter never confirms by accident. An outside click does nothing. Esc closes the alert.

There is no close button: `AlertDialogCancel` is the way out for a touch screen reader. `AlertDialogMedia` is decorative (`aria-hidden`).

With `loading`, `AlertDialogAction` shows a spinner, sets `aria-busy`, and stops clicks, and the focus stays on it. Each button grows to a 44px touch target on a touch screen (`hit-area`).

## Motion

| Part | Motion |
| --- | --- |
| Open | overlay · 200ms · ease-panel (0.2, 0.4, 0.2, 1) · the panel fades in and scales from 95%, the backdrop fades in |
| Close | overlay-exit · 150ms · ease-out (0, 0, 0.2, 1) · the panel fades out and scales to 95%, the backdrop fades out |
