document.exitFullscreen() asks the browser to take the current fullscreen element out of fullscreen and restore the previous screen state. It usually reverses Element.requestFullscreen().
Pass the required arguments shown below. Check return values and browser support before you rely on the result.
Syntax
Call document.exitFullscreen. Start with this line.
JavaScript
document.exitFullscreen()
Call
What it does
document.exitFullscreen()
Primary signature.
document.exitFullscreen(...)
Call with the arguments your case needs.
Built into the browser. Call exitFullscreen(...) on document — no import required.
Library declarations
JavaScript
document.exitFullscreen()
Parameters
This member has no parameters beyond those shown in the signature.
Return Value
Return Value
Description
*
Promise that resolves when exit finishes
JavaScript Examples
Example 1 — Toggle Enter / Exit (MDN-style)
If something is fullscreen, exit; otherwise request fullscreen on the document element.
JavaScript
async function toggleFullscreen() {
if (document.fullscreenElement) {
await document.exitFullscreen();
console.log("Exited fullscreen");
} else {
await document.documentElement.requestFullscreen();
console.log("Entered fullscreen");
}
}
// Call from a click handler (user gesture required to enter)
It requests that the element currently in fullscreen mode leave fullscreen and restore the previous screen state. It usually reverses Element.requestFullscreen().
No. MDN does not mark Document.exitFullscreen() as Deprecated, Experimental, or Non-standard. It is Limited availability (not Baseline), so feature-detect in production.
A Promise that resolves when the browser has finished exiting fullscreen. If exiting fails, the promise rejects and you can handle it with catch().
No. exitFullscreen() has no parameters.
Check document.fullscreenElement. If it is non-null, an element is in fullscreen and exitFullscreen() can leave that mode.
Yes. Esc and system UI can leave fullscreen. Listen for the fullscreenchange event so your UI stays in sync.