A closed dialog with a local method=dialog form
<button type="button">Open</button>
<dialog>
<form method="dialog">
<button type="submit" value="close">Close</button>
</form>
</dialog>The dialog is closed in the markup. A nested form with method=dialog is a close control, not a remote submission.
| Attribute | Description |
|---|---|
open | Omitted, so the dialog is closed in the markup. Adding open would show a non-modal dialog, not a showModal() top-layer dialog. |
method (form) | method="dialog" closes the dialog on submit and can set returnValue from the submitting button. It is not GET or POST and has no network endpoint. |
- There is no script in the fragment, so show() and showModal() are not called. There is no remote form action and no third-party image.
<button type="button" id="open-note">Open note</button>
<dialog id="note">
<form method="dialog">
<p>A practice note. This is not a live dialog test.</p>
<button type="submit" value="close">Close</button>
</form>
</dialog>What this markup means
The dialog has no open attribute, so it is closed in the tree. The button is type=button, so it does not submit anything. The nested form uses method="dialog" and would close the dialog with returnValue close if it were submitted while the dialog was open. Opening the dialog still requires show() or showModal() in script, which this fragment does not run. Escape is not demonstrated and is not treated as a universal close key.
Related: <form> method and submission, <button>, <details>, HTML tag catalog