Get to know MDN better
This feature is well established and works across many devices and browser versions. It’s been available across browsers since March 2022.
The close() method of the HTMLDialogElement interface closes the <dialog>. An optional string may be passed as an argument, updating the returnValue of the dialog.
The close event is fired after the dialog has closed. Unlike when calling HTMLDialogElement.requestClose(), the close operation cannot be cancelled.
A string that replaces the existing value of HTMLDialogElement.returnValue.
None (undefined).
The following example shows a button that, when clicked, opens a <dialog> via the showModal() method. From there you can click the either Close button to close the dialog (via the close() method).
The Close button closes the dialog without a returnValue, while the Close w/ return value button closes the dialog with a returnValue.
Note:
You know you can also automatically close a <dialog> by submitting a <form> element with a method="dialog" attribute.
| HTML # dom-dialog-close-dev |
Enable JavaScript to view this browser compatibility table.
This page was last modified on Jan 26, 2026 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.