Favorites

DOM HTMLDialogElement.showModal() Method

☕
Enjoying this site?

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

Buy us a coffee
HTMLDialogElement.showModal()
DOM HTMLDialogElement MethodThis method is supported by all modern browsers.
Updated 28th November 2026

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

<style>dialog::backdrop{background:#0006}</style>
<button id="open" type="button">Open</button>
<dialog id="dlg">
  <p>A modal dialog.</p>
  <form method="dialog"><button value="ok">OK</button></form>
</dialog>
const dlg = document.getElementById('dlg');
document.getElementById('open').addEventListener('click', () => {
  dlg.showModal();
  console.log('open:', dlg.open);
});
dlg.addEventListener('close', () => console.log('closed:', dlg.returnValue));

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.

This method 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