Dialog

Source: https://getbootstrap.com/docs/6.0/components/dialog

A modern component built on the native <dialog> element with built-in accessibility and backdrop support that replaces the old Modal component.

How it works

The Dialog component leverages the browser’s native <dialog> element, providing built-in accessibility features, focus management, and backdrop handling without the complexity of custom implementations.

Key features of the native dialog:

  • Modal or inline via showModal() / show() — modal: true (default) promotes the dialog to the browser’s top layer with a backdrop and focus trapping; modal: false renders it inline.
  • Built-in backdrop using the ::backdrop pseudo-element (modal only); set backdrop: "static" to lock clicks outside, or backdrop: false to hide it.
  • Escape key handling closes the dialog by default; set keyboard: false to disable.
  • Accessibility — focus is trapped inside modal dialogs and returned to the trigger on close, with native <dialog> ARIA semantics.
  • Animated open and close — circumvent browser restrictions by using a .hiding class to keep dialogs in the top layer during close so the exit transition (including ::backdrop) are animated properly.

Example

Toggle a dialog by clicking the button below. The dialog uses the native showModal() API for true modal behavior.

Open dialog </button>

<dialog class="dialog" id="exampleDialog"> <div class="dialog-header"> <h1 class="dialog-title">Dialog title</h1> </div> <div class="dialog-body"> <p>This is a native dialog element. It uses the browser’s built-in modal behavior for accessibility and focus management.</p> </div> <div class="dialog-footer"> <button type="button" class="btn-solid theme-secondary" data-bs-dismiss="dialog">Close</button> <button type="button" class="btn-solid theme-primary">Save changes</button> </div> </dialog>`} />

Without JavaScript

Supported browsers can open and close a dialog with the Invoker Commands API—no Bootstrap JavaScript required. Set commandfor to the dialog’s id, use command="show-modal" to open, and command="close" to dismiss.

The Invoker Commands API is not supported in all browsers. For guaranteed support, use the data-bs-toggle examples above when you need our plugin options, events, or animated close.

Open dialog </button>

<dialog class="dialog" id="invokerDialog"> <div class="dialog-header"> <h1 class="dialog-title">Invoker Commands</h1> <button type="button" class="btn-close" commandfor="invokerDialog" command="close" aria-label="Close"></button> </div> <div class="dialog-body"> <p>This dialog opens with <code>command="show-modal"</code> and closes with <code>command="close"</code>. No Bootstrap JavaScript is involved.</p> </div> <div class="dialog-footer"> <button type="button" class="btn-solid theme-secondary" commandfor="invokerDialog" command="close">Close</button> </div> </dialog>`} />

Dark dialog

To make a dialog dark, add data-bs-theme="dark" to the <dialog> element.

Open dark dialog </button>

<dialog class="dialog" id="exampleDialogDark" data-bs-theme="dark"><!-- [!code highlight] --> <div class="dialog-header"> <h1 class="dialog-title">Dark dialog title</h1> </div> <div class="dialog-body"> <p>This is a native dialog element, only it’s set to dark mode. It uses the browser’s built-in modal behavior for accessibility and focus management.</p> </div> <div class="dialog-footer"> <button type="button" class="btn-solid theme-secondary" data-bs-dismiss="dialog">Close</button> <button type="button" class="btn-solid theme-primary">Save changes</button> </div> </dialog>`} />

Static backdrop

When backdrop is set to static, the dialog will not close when clicking outside of it. Click the button below to try it.

<Example code={`<button type="button" class="btn-solid theme-primary" data-bs-toggle="dialog" data-bs-target="#staticBackdropDialog" data-bs-backdrop="static"><!-- [!code highlight] --> Open static backdrop dialog </button>

<dialog class="dialog" id="staticBackdropDialog"> <div class="dialog-header"> <h1 class="dialog-title">Static backdrop</h1> </div> <div class="dialog-body"> <p>I will not close if you click outside of me. Use the close button or press Escape.</p> </div> <div class="dialog-footer"> <button type="button" class="btn-solid theme-secondary" data-bs-dismiss="dialog">Close</button> </div> </dialog>`} />

Overlays

Tooltips, popovers, and toasts all work inside dialogs, but require some extra care. Since dialogs render in the browser’s top layer, overlays appended to <body> will appear behind the dialog. Set data-bs-container to the dialog element so tooltips and popovers render inside it. Toasts already work as long as they’re placed in the dialog markup.

Tooltips, popovers, toasts, and menus all work inside modal dialogs. Modal dialogs use showModal(), which promotes the dialog to the browser’s top layer -- a special rendering layer above everything else on the page.

Open dialog </button>

<dialog class="dialog not-prose" id="dialogWithComponents"> <div class="dialog-header"> <h1 class="dialog-title">Overlays inside dialogs</h1> </div> <div class="dialog-body"> <p>These components work inside modal dialogs.</p> <div class="d-flex gap-2 flex-wrap"> <button type="button" class="btn-solid theme-secondary" data-bs-toggle="tooltip" data-bs-title="Tooltip inside a dialog!">Tooltip</button> <button type="button" class="btn-solid theme-secondary" data-bs-toggle="popover" data-bs-title="Popover title" data-bs-content="This popover is inside a dialog and renders in the top layer. We include some longer content here to demonstrate the placement and wrapping behavior." data-bs-placement="top">Popover</button> <button type="button" class="btn-solid theme-secondary" id="dialogToastBtn">Show toast</button> <button class="btn-solid theme-secondary" type="button" data-bs-toggle="menu" aria-expanded="false">Menu</button> <div class="menu"> <a class="menu-item" href="#">Action</a> <a class="menu-item" href="#">Another action</a> <hr class="menu-divider" /> <div class="submenu"> <button class="menu-item" type="button">More options</button> <div class="menu"> <a class="menu-item" href="#">Sub-action A</a> <a class="menu-item" href="#">Sub-action B</a> <div class="submenu"> <button class="menu-item" type="button">Even more</button> <div class="menu"> <a class="menu-item" href="#">Deep action 1</a> <a class="menu-item" href="#">Deep action 2</a> </div> </div> </div> </div> </div> </div> </div> <div class="dialog-footer"> <button type="button" class="btn-solid theme-secondary" data-bs-dismiss="dialog">Close</button> </div> <div class="toast-container position-fixed bottom-0 end-0 p-3"> <div class="toast" id="dialogToast" role="alert" aria-live="assertive" aria-atomic="true"> <div class="toast-body"> Toast inside a dialog! <div class="mt-2 pt-2 border-top"> <button type="button" class="btn-solid theme-primary btn-sm" data-bs-dismiss="toast">Close</button> </div> </div> </div> </div> </dialog>`} />

Animations

Instant

By default, dialogs animate with a fade on open and close. To disable animations, add .dialog-instant to the <dialog> element.

Instant dialog </button>

<dialog class="dialog dialog-instant" id="instantDialog"> <div class="dialog-header"> <h1 class="dialog-title">Instant dialog</h1> </div> <div class="dialog-body"> <p>This dialog doesn’t animate and appears instantly on open and close.</p> </div> <div class="dialog-footer"> <button type="button" class="btn-solid theme-secondary" data-bs-dismiss="dialog">Close</button> <button type="button" class="btn-solid theme-primary">Save changes</button> </div> </dialog>`} />

Slide down

Add .dialog-slide-down to the <dialog> and it will slide down from the top of the viewport when opened.

Slide down dialog </button>

<dialog class="dialog dialog-slide-down" id="slideDownDialog"> <div class="dialog-header"> <h1 class="dialog-title">Slide down dialog</h1> </div> <div class="dialog-body"> <p>This dialog slides down from the top of the viewport.</p> </div> <div class="dialog-footer"> <button type="button" class="btn-solid theme-secondary" data-bs-dismiss="dialog">Close</button> <button type="button" class="btn-solid theme-primary">Save changes</button> </div> </dialog>`} />

Slide up

Add .dialog-slide-up to the <dialog> and it will slide up from the bottom of the viewport when opened.

Slide up dialog </button>

<dialog class="dialog dialog-slide-up" id="slideUpDialog"> <div class="dialog-header"> <h1 class="dialog-title">Slide up dialog</h1> </div> <div class="dialog-body"> <p>This dialog slides up from the bottom of the viewport.</p> </div> <div class="dialog-footer"> <button type="button" class="btn-solid theme-secondary" data-bs-dismiss="dialog">Close</button> <button type="button" class="btn-solid theme-primary">Save changes</button> </div> </dialog>`} />

Scrollable

Create a scrollable dialog that scrolls the dialog body while keeping the header and footer fixed. Add .dialog-scrollable to the .dialog element.

Launch scrollable body dialog </button>

<dialog class="dialog dialog-scrollable" id="scrollableBodyDialog"><!-- [!code highlight] --> <div class="dialog-header"> <h1 class="dialog-title">Scrollable body</h1> </div> <div class="dialog-body"> <p>This is some placeholder content to show the scrolling behavior for dialogs. We use repeated line breaks to demonstrate how content can exceed the dialog’s inner height, showing scrolling within the body while the header and footer remain fixed.</p> <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/> <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/> <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/> <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/> <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/> <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/> <p>This content should appear at the bottom after you scroll.</p> </div> <div class="dialog-footer"> <button type="button" class="btn-solid theme-secondary" data-bs-dismiss="dialog">Close</button> <button type="button" class="btn-solid theme-primary">Save changes</button> </div> </dialog>`} />