DOM Methods

HTMLDialogElement.close()

Closes an open dialog and optionally assigns its return value. This does not dispatch a cancelable close request. Use requestClose when cancellation should be possible. Closing an open dialog leads to a close notification. Example result: false / saved.

Formal Syntax & Structure

html syntaxhtml
element.close(returnValue)

Parameters & Attributes

NameTypeDescription
returnValuestringOptional result string.

Return Value

undefined

No return value.

Working Example

Example Snippethtml
<dialog id="demo" aria-label="Notice">Notice</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(); e.close('saved'); result(e.open+' / '+e.returnValue);</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