Codectionary / Developer documentation / HTML

<dialog>

The <dialog> element represents a native modal or non-modal dialog box, such as a confirmation prompt, settings panel, or alert. It comes with built-in modal behavior (via the showModal() JavaScript method) including a backdrop and focus trapping, removing the need to hand-build accessible modal logic from scratch.

Syntax

<dialog id="myDialog">
  <p>Dialog content</p>
  <button onclick="this.closest('dialog').close()">Close</button>
</dialog>

Examples

Basic Modal Dialog

A dialog opened and closed via JavaScript.

<dialog id="confirmDialog">
  <p>Are you sure you want to delete this item?</p>
  <button onclick="document.getElementById('confirmDialog').close()">Cancel</button>
  <button onclick="document.getElementById('confirmDialog').close()">Delete</button>
</dialog>
<button onclick="document.getElementById('confirmDialog').showModal()">Delete Item</button>

Non-modal Dialog

Using show() instead of showModal() for a non-blocking dialog.

<dialog id="tipDialog">
  <p>Tip: You can use keyboard shortcuts to navigate faster.</p>
</dialog>
<script>
  document.getElementById("tipDialog").show();
</script>

Styled Dialog

A dialog with custom appearance and backdrop styling.

<dialog style="border: none; border-radius: 12px; padding: 24px; max-width: 400px;">
  <h3>Settings</h3>
  <p>Dialog content goes here.</p>
</dialog>
<style>
  dialog::backdrop { background: rgba(0,0,0,0.5); }
</style>

Attributes

  • open (boolean): Reflects whether the dialog is currently visible

Best practices

  • Use showModal() rather than the open attribute directly when you need modal behavior with a backdrop and focus trapping
  • Always provide a clear way to close the dialog, such as a close button or the Escape key (built in by default)
  • Style the ::backdrop pseudo-element to dim the rest of the page behind a modal dialog
  • Prefer the native <dialog> over a hand-built modal — it handles focus management and accessibility concerns you would otherwise have to build yourself

Browser compatibility

Support applies to the named feature, not every attribute or behaviour in this article. Versions refer to browsers, not operating systems.

<dialog>

Desktop

Chrome
Supported
From 37
Firefox
Supported
From 98
Safari
Supported
From 15.4
Edge
Supported
From 79
Opera
Supported
From 24

Mobile

Safari on iOS
Supported
From 15.4
Chrome for Android
Supported
From 37
Firefox for Android
Supported
From 98
Samsung Internet
Supported
From 3.0

MDN BCD record for this feature · MDN reference

Support history and limitations

Chrome

  • From 37

Firefox

  • From 98

Safari

  • From 15.4

Edge

  • From 79

Opera

  • From 24

Safari on iOS

  • From 15.4

Chrome for Android

  • From 37

Firefox for Android

  • From 98

Samsung Internet

  • From 3.0
<dialog> open

Desktop

Chrome
Supported
From 37
Firefox
Supported
From 98
Safari
Supported
From 15.4
Edge
Supported
From 79
Opera
Supported
From 24

Mobile

Safari on iOS
Supported
From 15.4
Chrome for Android
Supported
From 37
Firefox for Android
Supported
From 98
Samsung Internet
Supported
From 3.0

MDN BCD record for this feature

Support history and limitations

Chrome

  • From 37

Firefox

  • From 98

Safari

  • From 15.4

Edge

  • From 79

Opera

  • From 24

Safari on iOS

  • From 15.4

Chrome for Android

  • From 37

Firefox for Android

  • From 98

Samsung Internet

  • From 3.0
HTMLDialogElement.showModal

Desktop

Chrome
Supported
From 37
Firefox
Supported
From 98
Safari
Supported
From 15.4
Edge
Supported
From 79
Opera
Supported
From 24

Mobile

Safari on iOS
Supported
From 15.4
Chrome for Android
Supported
From 37
Firefox for Android
Supported
From 98
Samsung Internet
Supported
From 3.0

MDN BCD record for this feature · MDN reference

Support history and limitations

Chrome

  • From 37

Firefox

  • From 98

Safari

  • From 15.4

Edge

  • From 79

Opera

  • From 24

Safari on iOS

  • From 15.4

Chrome for Android

  • From 37

Firefox for Android

  • From 98

Samsung Internet

  • From 3.0
HTMLDialogElement.show

Desktop

Chrome
Supported
From 37
Firefox
Supported
From 98
Safari
Supported
From 15.4
Edge
Supported
From 79
Opera
Supported
From 24

Mobile

Safari on iOS
Supported
From 15.4
Chrome for Android
Supported
From 37
Firefox for Android
Supported
From 98
Samsung Internet
Supported
From 3.0

MDN BCD record for this feature · MDN reference

Support history and limitations

Chrome

  • From 37

Firefox

  • From 98

Safari

  • From 15.4

Edge

  • From 79

Opera

  • From 24

Safari on iOS

  • From 15.4

Chrome for Android

  • From 37

Firefox for Android

  • From 98

Samsung Internet

  • From 3.0
HTMLDialogElement.close

Desktop

Chrome
Supported
From 37
Firefox
Supported
From 98
Safari
Supported
From 15.4
Edge
Supported
From 79
Opera
Supported
From 24

Mobile

Safari on iOS
Supported
From 15.4
Chrome for Android
Supported
From 37
Firefox for Android
Supported
From 98
Samsung Internet
Supported
From 3.0

MDN BCD record for this feature · MDN reference

Support history and limitations

Chrome

  • From 37

Firefox

  • From 98

Safari

  • From 15.4

Edge

  • From 79

Opera

  • From 24

Safari on iOS

  • From 15.4

Chrome for Android

  • From 37

Firefox for Android

  • From 98

Samsung Internet

  • From 3.0

MDN BCD 8.1.5 · Dataset built 2026-10-08 · Mapping reviewed 2026-10-21. These dates are not individual browser-test or claim-verification dates. Unknown means the data does not establish support.

HTML Living Standard

Specifications & further reading