A window overlaid on either the primary window or another dialog window, rendering the content underneath inert.
Philosophy
Dialogs demand attention and block interaction - use them when the user must make a decision before continuing. We split the anatomy into DialogTrigger, DialogContent, DialogHeader, etc. because every dialog has different needs but the same accessibility requirements: focus trapping, escape dismissal, and return focus.
<Dialog> <DialogTrigger>Open</DialogTrigger> <DialogContent> <DialogHeader> <DialogTitle>Are you absolutely sure?</DialogTitle> <DialogDescription> This action cannot be undone. This will permanently delete your account
and remove your data from our servers.
</DialogDescription> </DialogHeader> </DialogContent></Dialog>
Examples
Controlled Dialog
Active Trigger on Open
Style the trigger to appear active while the dialog is open using data-[state=open]:
Component Composition
Notes
To use the Dialog component from within a Context Menu or Dropdown Menu, you must encase the Context Menu or
Dropdown Menu component in the Dialog component.
<Dialog> <ContextMenu> <ContextMenuTrigger>Right click</ContextMenuTrigger> <ContextMenuContent> <ContextMenuItem>Open</ContextMenuItem> <ContextMenuItem>Download</ContextMenuItem> <DialogTriggerasChild> <ContextMenuItem> <span>Delete</span> </ContextMenuItem> </DialogTrigger> </ContextMenuContent> </ContextMenu> <DialogContent> <DialogHeader> <DialogTitle>Are you absolutely sure?</DialogTitle> <DialogDescription> This action cannot be undone. Are you sure you want to permanently
delete this file from our servers?
</DialogDescription> </DialogHeader> <DialogFooter> <Buttontype="submit">Confirm</Button> </DialogFooter> </DialogContent></Dialog>
RTL Support
Set the direction once with DirectionProvider (or <html dir="rtl">) and the dialog follows. The portaled overlay and content get the resolved dir, so text, the close button and the footer order mirror without any extra props.
Motion components work standalone, but some compositions may behave unexpectedly: this is still under active development. If you find a broken composition, please file an issue.
Use MotionDialog and MotionDialogContent for smooth enter/exit animations powered by motion. The dialog scales and fades in with a blur effect, and reverses on exit.
Requires the motion package. Use MotionDialog instead of Dialog and MotionDialogContent instead of DialogContent. All other sub-components (DialogTrigger, DialogHeader, etc.) stay the same.
Additional props inherited from DialogPrimitive.Content
DialogContent renders a built-in close button in the top-end corner (top-right in LTR, top-left in RTL). Set hideClose to remove it when you handle closing via other UI (e.g. a custom header with its own close button).
DialogHeader
Prop
Type
Default
Description
className
string
-
Additional CSS classes applied to the header
children
React.ReactNode
-
Header content (typically DialogTitle and DialogDescription)
...props
React.HTMLAttributes<HTMLDivElement>
-
Additional props to spread to the header container
DialogFooter
Prop
Type
Default
Description
className
string
-
Additional CSS classes applied to the footer
children
React.ReactNode
-
Footer content (typically action buttons)
...props
React.HTMLAttributes<HTMLDivElement>
-
Additional props to spread to the footer container
The following responsive components automatically render a Dialog on desktop (>=768px) and a Drawer on mobile. Each accepts the same props as its non-responsive counterpart.