JavaScript Document exitFullscreen() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Method

Definition

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()
CallWhat 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 ValueDescription
*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)
Try It Yourself

How It Works

  1. Check state. Non-null fullscreenElement means exit is the next step.
  2. Exit path. exitFullscreen() returns a Promise — await it.
  3. Enter path. Use requestFullscreen() on an element (often documentElement).
  4. User gesture. Entering usually requires a click/tap; exiting is more flexible.

Example 2 — Exit Only When Active

Guard the call so you do not exit when nothing is fullscreen.

JavaScript
async function leaveFullscreen() {
  if (!document.fullscreenElement) {
    console.log("Not in fullscreen");
    return;
  }
  try {
    await document.exitFullscreen();
    console.log("Left fullscreen");
  } catch (err) {
    console.log("Exit failed:", err.name);
  }
}
Try It Yourself

How It Works

  1. Early return. Skip the API when fullscreenElement is null.
  2. Await exit. Wait until the browser finishes restoring the layout.
  3. Catch errors. Some environments reject the Promise — handle them.
  4. UI tip. Still listen for fullscreenchange for Esc exits.

Example 3 — Feature Detect

Limited availability means you should check before wiring UI buttons.

JavaScript
const canExit = typeof document.exitFullscreen === "function";
const canEnter = typeof document.documentElement.requestFullscreen === "function";

console.log(canExit); // true in supporting browsers
console.log(canEnter); // true in supporting browsers
console.log(document.fullscreenEnabled); // may be false if policy blocks it
Try It Yourself

How It Works

  1. Check the method. Missing function → hide fullscreen controls.
  2. Check enter too. Exit is useless without a way to enter.
  3. Read fullscreenEnabled. Policy may disable fullscreen even if methods exist.
  4. Ship safely. Limited availability means detection is required.

Browser Support

Document.exitFullscreen() is part of the Fullscreen API. MDN marks it Limited availability (not Baseline). Feature-detect before production use.

✓ Limited availability

Document.exitFullscreen()

Supported in modern Chromium, Firefox, and Safari with varying policy/iframe rules. Always check document.exitFullscreen and fullscreenEnabled.

Limited Not Baseline
Google Chrome Modern versions
Yes
Microsoft Edge Modern versions
Yes
Mozilla Firefox Modern versions
Yes
Apple Safari Modern versions
Yes
Opera Modern versions
Yes
Internet Explorer Not supported (use ms- prefixes historically)
No
exitFullscreen() Feature-detect required

Bottom line: Safe when you detect support and handle Promise rejection. See the MDN exitFullscreen() reference.

Frequently Asked Questions

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.

Next: exitPictureInPicture()

Learn how to leave Picture-in-Picture with document.exitPictureInPicture().

exitPictureInPicture() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

11 people found this page helpful