DOM HTMLDialogElement.showModal() Method
The showModal() method opens a dialog element as a modal, on top of the page, making everything behind it inert until it closes.
Description
The showModal() method displays the <dialog> as a modal in the top layer. The rest of the page becomes inert, so it can't be clicked or focused; focus moves into the dialog; Escape closes it; and the ::backdrop pseudo-element can dim the page behind. When it closes, focus returns to the element that opened it.
This gives you an accessible modal without writing focus-trapping code. show() opens a non-modal dialog instead.
It throws an InvalidStateError if the dialog is already open as a non-modal dialog, or isn't connected to the document. Avoid putting modals on top of other modals where possible; if you must, each new showModal() call places that dialog on top of the stack.
Syntax
dialog.showModal()Return Value
None (undefined).
Example
Browser Support
The following information will show you the current browser support for the HTMLDialogElement.showModal() method. Hover over a browser icon to see the version that first introduced support for this method.
Desktop





Tablets & Mobile





