DOM Methods

HTMLDialogElement.showModal()

Opens a dialog modally in the top layer. Outside content becomes inert within the document. An already open non-modal dialog cannot simply be converted by calling showModal; close it first. Provide an accessible name and a close mechanism. Example result: true.

Formal Syntax & Structure

html syntaxhtml
element.showModal()

Return Value

undefined

No return value.

Working Example

Example Snippethtml
<dialog id="demo" aria-label="Notice">  <button>OK</button></dialog><p>  Result:  <output id="result"></output></p><script>  const e = document.getElementById('demo');  const result = value => { document.getElementById("result").textContent = String(value); };  e.showModal(); result(e.matches(':modal'));</script>

Browser Compatibility

Minimum supported versions across modern rendering engines

Widely Available (2022)
Blink
Chrome
37+
Yes
Gecko
Firefox
98+
Yes
WebKit
Safari
15.4+
Yes
Basic feature support; newer dialog members have their own compatibility.
HTML Living Standard
HTML Reference