DOM HTMLDialogElement Interface
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
| Name | Description |
|---|---|
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
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.
Desktop





Tablets & Mobile





