HTMLDialogElement: show() method

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since March 2022.

The show() method of the HTMLDialogElement interface displays the dialog as a non-modal dialog.

A non-modal dialog is one where users can interact with content outside/behind the open dialog.

Syntax

js
show()

Parameters

None.

Return value

None (undefined).

Exceptions

InvalidStateError DOMException

Thrown if the dialog is already open and modal (i.e., if the dialog has already been opened with HTMLDialogElement.showModal()).

Examples

Basic usage

The following example shows a simple button that, when clicked, opens a <dialog> using the show() method.

When the dialog is open, you can still interact with the rest of the page, including clicking the Click me button that triggers an alert.

You can click the Close dialog button to close the dialog (via the close() method).

HTML

html
<dialog id="dialog">
  <button type="button" id="close">Close dialog</button>
</dialog>

<p><button id="open">Open dialog</button></p>
<p><button id="alert">Trigger alert</button></p>

JavaScript

js
const dialog = document.getElementById("dialog");
const openButton = document.getElementById("open");
const closeButton = document.getElementById("close");
const alertButton = document.getElementById("alert");

// Open button opens a modeless dialog
openButton.addEventListener("click", () => {
  dialog.show();
});

// Alert button triggers an alert
alertButton.addEventListener("click", () => {
  alert("you clicked me!");
});

// Close button closes the dialog box
closeButton.addEventListener("click", () => {
  dialog.close();
});

Result

Specifications

Specification
HTML
# dom-dialog-show-dev

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
show
Chrome – Full support
Chrome 37 (Release date: 2014-08-26)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Full support
Firefox 98 (Release date: 2022-03-08)
footnote Full support
Opera – Full support
Opera 24 (Release date: 2014-09-02)
footnote Full support
Safari – Full support
Safari 15.4 (Release date: 2022-03-14)
footnote Full support
Chrome Android – Full support
Chrome Android 37 (Release date: 2014-09-03)
footnote Full support
Firefox for Android – Full support
Firefox for Android 98 (Release date: 2022-03-08)
footnote Full support
Opera Android – Full support
Opera Android 24 (Release date: 2014-09-10)
footnote Full support
Safari on iOS – Full support
Safari on iOS 15.4 (Release date: 2022-03-14)
footnote Full support
Samsung Internet – Full support
Samsung Internet 3 (Release date: 2015-04-10)
footnote Full support
WebView Android – Full support
WebView Android 37 (Release date: 2014-09-03)
footnote Full support
WebView on iOS – Full support
WebView on iOS 15.4 (Release date: 2022-03-14)
footnote Full support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

See also