Definition
The <dialog> tag represents part of an application that a user interacts with, such as a dialog box or window.
Example
<script>
var dialog = document.querySelector('dialog');
document.querySelector('#open').onclick = function() {
dialog.show();
};
document.querySelector('#close').onclick = function() {
dialog.close();
};
</script><dialog>
<p>This is dialogue window.</p>
<button id="close">Close me</button>
</dialog>
<button id="open">Open Dialog</button>Usage
- Controlling the behavior of the dialog box usually requires JavaScript.
- You must include both the opening and closing tags.
- The
<tabindex>attribute should not be used on<dialog>elements. <form>elements with the attributemethod="dialog"are able to close dialog windows.
Attributes
The <dialog> element only supports the Event Attributes and Global Attributes, along with the following:
openThe
openattribute is a boolean that states whether the<dialog>element is active or not. If theopenattribute is omitted, then the<dialog>element will be hidden from the user. For example<dialog open>This is dialogue window.</dialog>
Specification
Browser Support
Desktop
| Chrome | Edge | Firefox | IE | Opera | Safari |
|---|---|---|---|---|---|
| Yes | Yes | No | No | Yes | No |
Mobile
| Android Webview | Chrome Android | Firefox Android | Opera Android | iOS Safari | Samsung Internet |
|---|---|---|---|---|---|
| Yes | Yes | No | Yes | No | Yes |
