coderef

dialog.requestClose()Baseline · Newly available

The requestClose() method of a <dialog> HTML element closes the dialog, firing a cancel event first, which listeners can use to prevent the dialog from closing. This differs from the close() method, which only fires the non-cancelable close event.

Works in the latest version of every major browser, but older devices may not support it yet. Baseline since May 27, 2025.

Browser support

DesktopChrome
1–133Not supported
134+Supportedsince Mar 4, 2025
Current: 155
Edge
12–133Not supported
134+Supportedsince Mar 6, 2025
Current: 154
Firefox
1–138Not supported
139+Supportedsince May 27, 2025
Current: 157
Safari
1–18.3Not supported
18.4+Supportedsince Mar 31, 2025
Current: 27
MobileChrome Android
18–133Not supported
134+Supportedsince Mar 4, 2025
Current: 155
Firefox Android
4–138Not supported
139+Supportedsince May 27, 2025
Current: 157
Safari iOS
1–18.3Not supported
18.4+Supportedsince Mar 31, 2025
Current: 27

How to use

Every current browser supports this, but it only became Baseline on May 27, 2025. Use it as a progressive enhancement, or keep a fallback if you support older devices.

Example

Full syntax and examples are on MDN: requestClose.

Feature detection

JS · check before using
if ("HTMLDialogElement" in globalThis && "requestClose" in HTMLDialogElement.prototype) {
  // HTMLDialogElement.requestClose is available
}