Dialog
A window over the page that keeps focus until it is closed. For a question that needs an answer before anything else, use Alert dialog.
Installation
Or with the shadcn CLI, from the registry:
It installs Button too.
Usage
Controlled
Pass open and onOpenChange to open the dialog from elsewhere, or to close it once a form is saved.
Sizes
size on DialogContent sets its width from the sm breakpoint: sm, default, lg, or full, which fills the window
less a margin and scrolls its body. Below sm, every size takes the window's width less a margin.
Without the close button
DialogContent draws a close button in its corner. Pass showCloseButton={false} when the footer already has one.
Villages
Open a dialog in a cell: it renders in a portal on <body>, yet wears that cell's village, because the cell is a
VillageScope.
Accessibility
- The popup is a
dialog, named byDialogTitleand described byDialogDescription. - Opening moves focus into the dialog, Tab stays inside it, and closing returns focus to the trigger.
- Esc and a click on the backdrop close it; the page behind can't be scrolled or reached by screen readers.
- The close button in the corner is labelled "Close".
API reference
The parts of Base UI's Dialog, styled:
| Part | Renders | Notes |
|---|---|---|
Dialog | nothing | open, defaultOpen, onOpenChange, modal |
DialogTrigger | <button> | render to use a Button |
DialogContent | portal, backdrop and popup | showCloseButton (default true), size ("sm" | "default" | "lg" | "full"); dialogContentVariants({ size }) returns its classes |
DialogHeader, DialogFooter | <div> | layout only |
DialogTitle | <h2> | names the dialog |
DialogDescription | <p> | describes the dialog |
DialogClose | <button> | closes the dialog |
DialogPortal, DialogOverlay | for a custom popup; the portal follows the nearest VillageScope |