The <dialog>
represents a dialog box or other interactive component, such as an inspector or window.
Content categories | Flow content, sectioning root |
---|---|
Permitted content | Flow content |
Tag omission | None, both the starting and ending tag are mandatory. |
Permitted parents | Any element that accepts flow content |
Permitted ARIA roles | alertdialog |
DOM interface | HTMLDialogElement |
This element includes the global attributes. The tabindex
attribute must not be used on the <dialog>
element.
open
open
attribute is not set, the dialog shouldn't be shown to the user.<form>
elements can be integrated within a dialog by specifying them with the attribute method="dialog"
. When such a form is submitted, the dialog is closed with its returnValue
attribute set to the value
of the form's submit button that was used.::backdrop
CSS pseudo-element can be used to style behind a <dialog>
element, for example to dim inaccessible content whilst a modal dialog is active. The backdrop is only drawn when the dialog element is displayed with HTMLDialogElement.showModal()
.<dialog open> <p>Greetings, one and all!</p> </dialog>
This example opens a pop-up dialog box containing a form when the "Update details" button is clicked.
<!-- Simple pop-up dialog box containing a form --> <dialog id="favDialog"> <form method="dialog"> <p><label>Favorite animal: <select> <option></option> <option>Brine shrimp</option> <option>Red panda</option> <option>Spider monkey</option> </select> </label></p> <menu> <button>Cancel</button> <button>Confirm</button> </menu> </form> </dialog> <menu> <button id="updateDetails">Update details</button> </menu> <div id="output"></div>
(function() { var updateButton = document.getElementById('updateDetails'); var favDialog = document.getElementById('favDialog'); var outputBox = document.getElementById("output"); // “Update details” button opens the <dialog> modally updateButton.addEventListener('click', function() { favDialog.showModal(); output.innerHTML += "<div>" + favDialog.returnValue + " button clicked!</div>"; }); })();
Which button was clicked can be determined from favDialog
’s returnValue
.
Specification | Status | Comment |
---|---|---|
HTML Living Standard The definition of '<dialog>' in that specification. | Living Standard | |
HTML 5.2 The definition of '<dialog>' in that specification. | Recommendation | Initial definition |
Desktop | ||||||
---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
Basic support | 37 | No | 53
|
No | 24 | No |
open |
37 | No | 53
|
No | 24 | No |
Mobile | |||||||
---|---|---|---|---|---|---|---|
Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
Basic support | 37 | 37 | No | 53
|
No | No | Yes |
open |
37 | 37 | No | 53
|
No | No | Yes |
Include this polyfill to provide support for older browsers.
close
eventcancel
event::backdrop
pseudo-element
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dialog