Skip to content

Dialog

A modal surface for a focused task that interrupts the page, with header, body and footer parts.

hero.tsx

Usage guidelines

  • Use Dialog for modal content that needs focus containment and scroll locking, such as editing settings or collecting short input. Use AlertDialog only for a destructive or must-confirm decision, and Drawer for a side panel.
  • Compose DialogHeader, DialogBody and DialogFooter inside DialogContent. The parts own the spacing, and DialogBody scrolls between the header and the footer when the surface reaches the viewport height.
  • Every dialog has a DialogTitle. Add a DialogDescription when a sentence of context helps before the user acts.
  • Use DialogHeaderCloseButton for the standard corner close icon and give it an aria-label. Use DialogClose with render for footer actions such as Cancel.
  • Outside-press dismissal is the default. Set disablePointerDismissal on the root only when an accidental close would throw away work the user would have to redo.
  • Use DialogTrigger under the root for a dedicated button. When a trigger lives outside the root or a menu command opens a sibling dialog, connect them with createDialogHandle.
  • Keep a dialog open while its request is pending only when closing would lose the way to see the outcome or retry. Close it on success and keep it open with the error on failure.

Anatomy

tsx
tsx

DialogContent bundles the portal, backdrop and centered popup. DialogPopup is the bare dialog element for a surface that places and dresses itself; compose it with DialogPortal, DialogBackdrop and DialogViewport.

Examples

Scrolling body

Long content scrolls inside DialogBody while the header and footer stay in place.

scrolling-body.tsx

Closing after a request

Control open to close the dialog when an async submission succeeds. While the request is pending, onOpenChange cancels dismissal and DialogHeaderCloseButton and Cancel stay disabled so the outcome remains visible. A failed request keeps the dialog open with the error and the user's input so they can retry; the first submit on each open fails in this demo.

async-close.tsx

One dialog for a list of items

A list whose items open the same dialog renders one Dialog around the list. Each DialogTrigger carries its item as payload, and the dialog reads the payload of the trigger that opened it.

  • Ada Lovelace

    ada@example.com

  • Alan Turing

    alan@example.com

  • Grace Hopper

    grace@example.com

payload.tsx

Opening with a handle

Keep a dialog opened by a menu command or a distant trigger as a sibling and connect it with createDialogHandle. Calling open(null) opens the dialog without controlled open state, and focus returns to the menu trigger when it closes.

detached-trigger.tsx

Keyboard

KeyAction
EnterorSpaceOpens the dialog from a focused trigger.
TaborShift+TabMoves focus between the dialog's controls. Focus stays inside the dialog while it is open.
EscapeCloses the dialog and returns focus to the trigger.

API reference

Dialog

Groups all parts of a modal dialog. Doesn't render its own HTML element.

Base UI Dialog.Root docs

DialogBackdrop

An overlay displayed beneath the popup. Renders a <div> element.

Base UI Dialog.Backdrop docs

Data attributes
AttributeDescription
data-open

Present when the dialog is open.

data-closed

Present when the dialog is closed.

data-starting-style

Present when the dialog begins animating in.

data-ending-style

Present when the dialog is animating out.

DialogBody

Accepts the props of the element it renders.

DialogClose

A button that closes the dialog. Renders a <button> element.

Base UI Dialog.Close docs

Data attributes
AttributeDescription
data-disabled

Present when the button is disabled.

DialogContent

A centered modal dialog surface bundled with a portal and backdrop. Renders a <div> element.

Base UI Dialog.Popup docs

Props
PropTypeDefaultDetails
children requiredReact.ReactNodeNo default
backdropPropsDialogBackdropPropsNo default
Base UI Dialog.Popup docs
Data attributes
AttributeDescription
data-open

Present when the dialog is open.

data-closed

Present when the dialog is closed.

data-starting-style

Present when the dialog begins animating in.

data-ending-style

Present when the dialog is animating out.

data-nested

Present when the dialog is nested within another dialog.

data-nested-dialog-open

Present when the dialog has other open dialogs nested within it.

CSS variables
VariableDescription
--nested-dialogs

Values: number

Indicates how many dialogs are nested within.

DialogDescription

A paragraph with additional information about the dialog. Renders a <p> element.

Base UI Dialog.Description docs

DialogFooter

Accepts the props of the element it renders.

DialogHeader

Accepts the props of the element it renders.

DialogHeaderCloseButton

An icon close button positioned in the corner of DialogHeader, which reserves space for it automatically. Renders a <button> element.

Base UI Dialog.Close docs

Props
PropTypeDefaultDetails
aria-label requiredstringNo default
Base UI Dialog.Close docs
Data attributes
AttributeDescription
data-disabled

Present when the button is disabled.

DialogPopup

A container for the dialog contents. Renders a <div> element.

Base UI Dialog.Popup docs

Data attributes
AttributeDescription
data-open

Present when the dialog is open.

data-closed

Present when the dialog is closed.

data-starting-style

Present when the dialog begins animating in.

data-ending-style

Present when the dialog is animating out.

data-nested

Present when the dialog is nested within another dialog.

data-nested-dialog-open

Present when the dialog has other open dialogs nested within it.

CSS variables
VariableDescription
--nested-dialogs

Values: number

Indicates how many dialogs are nested within.

DialogPortal

A portal element that moves the popup to a different part of the DOM. By default, the portal element is appended to <body>. Renders a <div> element.

Base UI Dialog.Portal docs

DialogTitle

A heading that labels the dialog. Renders an <h2> element.

Base UI Dialog.Title docs

DialogTrigger

A button that opens the dialog. Renders a <button> element.

Base UI Dialog.Trigger docs

Data attributes
AttributeDescription
data-disabled

Present when the trigger is disabled.

data-popup-open

Present when the corresponding dialog is open.

DialogViewport

A positioning container for the dialog popup that can be made scrollable. Renders a <div> element.

Base UI Dialog.Viewport docs

Data attributes
AttributeDescription
data-open

Present when the dialog is open.

data-closed

Present when the dialog is closed.

data-starting-style

Present when the dialog begins animating in.

data-ending-style

Present when the dialog is animating out.

data-nested

Present when the dialog is nested within another dialog.

data-nested-dialog-open

Present when the dialog has other open dialogs nested within it.

createDialogHandle

Creates a new handle to connect a Dialog.Root with detached Dialog.Trigger components.

Returns

BaseDialog.Handle<Payload>
Return properties
MemberTypeDescription
open required(triggerId: string | null) => void

Opens the dialog, optionally associating it with a trigger.

This method should only be called in an event handler or an effect (not during rendering).

openWithPayload required(payload: Payload) => void

Opens the dialog with the given payload, without associating it with any trigger.

This method should only be called in an event handler or an effect (not during rendering).

close required() => void

Closes the dialog.

This method should only be called in an event handler or an effect (not during rendering).

isOpen requiredboolean

Whether the dialog is currently open. Returns false while no root is attached to the handle.