Favorites

DOM HTMLDialogElement Interface

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
HTMLDialogElement
DOM InterfaceThis interface is supported by all modern browsers.
Updated 28th November 2026

HTMLDialogElement represents a dialog element, with methods to open it as a modal or non-modal dialog and to close it.

Description

The HTMLDialogElement interface represents a <dialog> element. showModal() opens it as a modal dialog, which traps focus, makes the rest of the page inert and can be styled with ::backdrop; show() opens it without those effects; and close() closes it, optionally setting returnValue.

The open property reflects whether it's showing, and the close and cancel events fire when it closes or the user presses Escape. Using the native dialog avoids writing your own focus management.

The closedby attribute, supported in newer browsers, controls whether a dialog closes when the user clicks outside it or presses Escape. A form inside a dialog with method="dialog" closes the dialog when submitted, without sending data to a server, and sets returnValue to the submit button's value. The autofocus attribute on an element inside the dialog chooses where focus goes when it opens.

Inheritance

HTMLDialogElement inherits properties and methods from HTMLElement.

Methods

NameDescription
HTMLDialogElement.close()The close() method closes a dialog element and can pass back a value saying how it was closed.
HTMLDialogElement.showModal()The showModal() method opens a dialog element as a modal, on top of the page, making everything behind it inert until it closes.

Example

<button id="open" type="button">Open dialog</button>
<dialog id="dlg">
  <form method="dialog">
    <p>Save changes?</p>
    <button value="yes">Yes</button>
    <button value="no">No</button>
  </form>
</dialog>
const dlg = document.getElementById('dlg');
document.getElementById('open').addEventListener('click', () => dlg.showModal());
dlg.addEventListener('close', () => console.log('Closed with', dlg.returnValue));
console.log('open:', dlg.open);

Browser Support

The following information will show you the current browser support for the HTMLDialogElement interface. Hover over a browser icon to see the version that first introduced support for this interface.

This interface is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee