The <dialog> element represents a modal or non-modal dialog box — for example a confirm message or a small panel. Modal dialogs block the rest of the page; non-modal ones do not.
Prefer JavaScript showModal() / show() / close() to open and close. Always include a clear close control (button or <form method="dialog">). Style the modal dimming layer with ::backdrop.
Baseline · Widely available.
Core <dialog> has been widely available since about March 2022. Some extras (such as closedby) have newer or uneven support — test if you rely on them.
Do not use tabindex on <dialog>.
The dialog itself is not meant to take a tabindex. Focus interactive content inside it (MDN). Prefer autofocus on the control users should hit first (often Close).
Prefer methods over toggling open.
Setting the open attribute alone creates a non-modal dialog. For modals, use showModal().
Syntax
HTML Syntax
syntax.html
<dialog>…content… </dialog>
Both start and end tags are required. Put headings, text, buttons, or a form inside. Without being opened (via method or open), the dialog is not shown to users.
Click OK to close. Reload the section or page to see it open again.
How It Works
Add open so the dialog starts visible (non-modal).
Nest <form method="dialog"> with a submit button.
Submit the form — the dialog closes; no page navigation.
For reopenable UIs, prefer show() / showModal() instead of only open.
Example 3 — Non-Modal with show()
Open a dialog that does not block the rest of the page.
HTML
<button type="button" id="open2">Open tip</button>
<p>You can still select this text while the tip is open.</p>
<dialog id="tip">
<p>Tip: Save often.</p>
<form method="dialog">
<button autofocus>Got it</button>
</form>
</dialog>
<script>
const tip = document.getElementById("tip");
document.getElementById("open2").onclick = () => tip.show();
</script>
Dialog: focused task with optional modal backdrop.
Details: inline expand in the document flow (no modal).
Pick by UX. Confirm/alert → dialog; FAQ tip in place → <details>.
Always offer a close path on dialogs (button or Esc for modals).
Edge Cases & Pitfalls
Most issues are missing close controls, wrong open method, or fighting native focus rules.
a11y
Always provide a close control
Not every device has Esc. Include Cancel/Close/OK that users can activate.
api
Modal vs non-modal API
showModal() for blocking UI; show() or open for non-modal. Do not assume open alone is modal.
focus
No tabindex on dialog
Focus contents instead. Use autofocus on the primary control when helpful.
css
Style the backdrop separately
Modal backdrops use ::backdrop. Closed dialogs stay in the DOM but are not displayed.
newer
closedby support varies
This attribute fine-tunes dismiss gestures. Treat it as progressive enhancement until your audience supports it.
Compatibility
Browser Support
The <dialog> element is standard HTML. Core support is widely available; some related attributes are newer.
✓ Baseline · Widely available*
<dialog>
Widely available since about March 2022. Chrome, Firefox, Safari, and Edge support showModal/show/close. Features like closedby and invoker commands need newer browsers.
94%Global support (approx.)
Google Chrome37+
Full support
Mozilla Firefox98+
Full support
Apple Safari15.4+
Full support
Microsoft Edge79+
Full support
Opera24+
Full support
Samsung InternetAll
Full support
Internet ExplorerNo
Not supported
<dialog>Widely supported
Bottom line: Safe for modern sites. Prefer showModal/show/close and a visible close button; enhance with closedby only after checking support.
Remember
Key Takeaways
Role: native dialog box — modal with showModal(), non-modal with show().
Close: button + close(), Esc (modal), or <form method="dialog">.
Focus: no tabindex on dialog; use autofocus inside when helpful.
Style:::backdrop for the modal dim layer behind the dialog.
One line: use <dialog> with showModal() for focused tasks — and always give users a clear way out.
UA style
Default CSS Settings
Closed dialogs are not displayed. Open dialogs are centered by the UA stylesheet (simplified):
Exact UA rules vary. Keep study CSS minimal; customize padding, border, and ::backdrop as needed.
Frequently Asked Questions
The dialog element creates a modal or non-modal dialog box — for alerts, confirmations, or small panels. Modal dialogs block the rest of the page; non-modal ones do not.
Call dialog.showModal() from JavaScript. Prefer that over setting the open attribute. Modal dialogs get a backdrop and can be closed with Esc by default.
Call dialog.show(), or (less preferred) add the open attribute. Non-modal dialogs allow interaction with the rest of the page.
Put a form inside the dialog with method="dialog" and a submit button. Submitting that form closes the dialog.
No. Do not use tabindex on the dialog element. Focus its interactive contents (for example a close button with autofocus).
No. details is an inline disclosure in the page flow. dialog is a dialog box that can be modal with a backdrop and focus management.