JavaScript Document exitFullscreen() Method

Beginner
⏱️ 11 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Limited availability
Instance method

What You’ll Learn

document.exitFullscreen() is an instance method that asks the browser to leave fullscreen mode (see MDN Document: exitFullscreen()). Learn its Promise return, how it pairs with Element.requestFullscreen() and fullscreenElement, fullscreenchange events, feature detection, and five try-it labs.

01

Kind

Instance method

02

Params

None

03

Returns

Promise

04

Reverses

requestFullscreen

05

Check with

fullscreenElement

06

Status

Limited availability

Introduction

Fullscreen mode fills the screen with one element — often a video player, slideshow, or game canvas. You enter with element.requestFullscreen(). To leave from script, call document.exitFullscreen().

MDN: this method requests that the element currently presented in fullscreen be taken out of fullscreen, restoring the previous screen state. It usually reverses a previous requestFullscreen() call.

💡
Think: exit door for fullscreen

1) Check document.fullscreenElement
2) If set, call document.exitFullscreen()
3) Await the Promise (or use .then() / .catch())
4) Update UI on fullscreenchange

Related tutorials: fullscreenElement, fullscreenEnabled, fullscreen (deprecated).

Understanding document.exitFullscreen()

An instance method on the page’s document object (Fullscreen API; MDN).

  • Parameters — none (MDN).
  • Return value — a Promise that resolves when exiting finishes (MDN).
  • Errors — if exiting fails, the promise rejects; handle with catch() (MDN).
  • Pair — enter with Element.requestFullscreen(); exit with this method.
  • Status check — read document.fullscreenElement (or listen for fullscreenchange).
  • User exit — Esc / system UI can also leave fullscreen without your call.

📝 Syntax

General form of Document.exitFullscreen (MDN):

JavaScript
exitFullscreen()

Parameters

None (MDN).

Return value

A Promise resolved once the user agent has finished exiting fullscreen. On failure, use the promise’s catch() handler (MDN).

MDN toggle example

JavaScript
document.onclick = (event) => {
  if (document.fullscreenElement) {
    document
      .exitFullscreen()
      .then(() => console.log("Document Exited from Full screen mode"))
      .catch((err) => console.error(err));
  } else {
    document.documentElement.requestFullscreen();
  }
};

MDN notes a more complete demo lives with Element.requestFullscreen() examples. Entering fullscreen normally needs a user gesture (click / tap).

⚡ Quick Reference

GoalCode
Exit fullscreenawait document.exitFullscreen()
Exit with handlersdocument.exitFullscreen().then(...).catch(...)
Only if activeif (document.fullscreenElement) { ... }
Enter firstawait el.requestFullscreen()
Feature-detecttypeof document.exitFullscreen === "function"
MDN statusLimited availability (not Baseline)

🔍 At a Glance

Four facts about document.exitFullscreen().

Returns
Promise

async exit

Params
none

MDN

Guard
fullscreenElement

check first

Status
limited

Not Baseline

📋 Script exit vs user Esc

exitFullscreen()Esc / system UI
Who starts it?Your scriptThe user / OS
Promise?Yes — resolve / reject (MDN)No script Promise
UI syncStill listen for fullscreenchangeSame event fires
Best practiceGuard with fullscreenElementDo not assume only your Exit button leaves

Examples Gallery

Examples follow MDN Document: exitFullscreen() and practical Fullscreen API patterns. Embedded try-it frames may block fullscreen — open labs in a full tab when testing enter/exit.

📚 Getting Started

Toggle in and out of fullscreen like MDN’s sample.

Example 1 — MDN: click to toggle fullscreen

If already fullscreen, exit; otherwise request fullscreen on documentElement.

JavaScript
document.onclick = () => {
  if (document.fullscreenElement) {
    document
      .exitFullscreen()
      .then(() => console.log("Document Exited from Full screen mode"))
      .catch((err) => console.error(err));
  } else {
    document.documentElement.requestFullscreen();
  }
};
Try It Yourself

How It Works

MDN uses document.fullscreenElement as the branch: truthy means “someone is fullscreen,” so call exitFullscreen().

Example 2 — Guard + await

Only exit when active; use async/await for clearer flow.

JavaScript
async function leaveFullscreen() {
  if (!document.fullscreenElement) {
    console.log("not in fullscreen");
    return;
  }
  await document.exitFullscreen();
  console.log("exited");
}

document.getElementById("exit").addEventListener("click", () => {
  leaveFullscreen().catch((err) => console.error(err));
});
Try It Yourself

How It Works

Guarding avoids pointless calls when nothing is fullscreen. Still wrap with .catch() because the Promise can reject (MDN).

📈 Practical Patterns

Promise errors, change events, and feature detection.

Example 3 — Explicit then / catch

Match MDN’s Promise style without async.

JavaScript
function exitNow() {
  if (!document.fullscreenElement) {
    console.log("skip — already windowed");
    return;
  }
  document
    .exitFullscreen()
    .then(() => console.log("exit finished"))
    .catch((err) => console.error("exit failed:", err));
}
Try It Yourself

How It Works

MDN: resolve means the agent finished leaving fullscreen; reject means something went wrong while trying.

Example 4 — Sync UI with fullscreenchange

Keep a label correct whether exit came from your button or Esc.

JavaScript
const status = document.getElementById("status");

function updateStatus() {
  status.textContent = document.fullscreenElement
    ? "fullscreen: " + document.fullscreenElement.tagName
    : "windowed";
}

document.addEventListener("fullscreenchange", updateStatus);
updateStatus();

document.getElementById("exit").addEventListener("click", () => {
  if (document.fullscreenElement) {
    document.exitFullscreen().catch(console.error);
  }
});
Try It Yourself

How It Works

Do not poll fullscreenElement in a loop. The fullscreenchange event is the reliable signal for UI updates.

Example 5 — Feature-detect before use

MDN marks Limited availability — check before shipping production UI.

JavaScript
const canExit = typeof document.exitFullscreen === "function";
const canEnter =
  typeof Element !== "undefined" &&
  typeof Element.prototype.requestFullscreen === "function";
const enabled = document.fullscreenEnabled === true;

console.log({ canExit, canEnter, enabled });
Try It Yourself

How It Works

Hide fullscreen controls when the API is missing or fullscreenEnabled is false (for example some iframe contexts).

🚀 Common Use Cases

  • Video players — Exit button next to Enter fullscreen.
  • Presentations / slides — Leave deck fullscreen from a toolbar.
  • Games / canvases — Return to windowed mode from a pause menu.
  • Toggle controls — One button that enters or exits based on fullscreenElement.
  • Cleanup — Exit before navigating away or closing a modal experience.
  • Not Esc replacement only — Users can still leave with Esc; keep UI event-driven.

🧠 How exitFullscreen() Works

1

Something is fullscreen

document.fullscreenElement points at the active element (or is null).

State
2

Script calls exitFullscreen()

No arguments. The browser starts leaving fullscreen (MDN).

Request
3

Promise settles

Resolves when exit finishes; rejects on error (MDN).

Async
4

Screen restored

fullscreenElement becomes null; fullscreenchange fires for UI.

📝 Notes

  • MDN: Limited availability (not Baseline) — feature-detect in production.
  • MDN: no parameters; returns a Promise.
  • Usually reverses Element.requestFullscreen() (MDN).
  • Prefer fullscreenElement over deprecated document.fullscreen.
  • Iframes / permissions may block fullscreen even when the method exists.
  • Related: fullscreenElement, fullscreenEnabled, execCommand().

Browser Support

Document.exitFullscreen() is marked Limited availability on MDN (not Baseline). Feature-detect before production use. Logos use the shared browser-image-sprite.png sprite from this project.

Limited availability · Not Baseline

Document.exitFullscreen()

Leave fullscreen with a Promise — pair with requestFullscreen, fullscreenElement, and fullscreenchange.

Limited Check compat
Google Chrome Widely supported · Desktop & Mobile
Supported
Mozilla Firefox Supported in modern versions
Supported
Apple Safari Supported with Fullscreen API
Supported
Microsoft Edge Chromium support
Supported
Opera Follow Chromium behavior
Supported
Internet Explorer Not modern Fullscreen API
No / legacy only
Document.exitFullscreen() Limited availability

Bottom line: Call exitFullscreen when fullscreenElement is set. Handle the Promise, listen for fullscreenchange, and feature-detect for Limited availability.

Conclusion

document.exitFullscreen() is the Fullscreen API’s exit door: no parameters, a Promise, and a restored window after a successful leave. Guard with fullscreenElement, catch rejections, and keep UI honest with fullscreenchange.

Continue with fullscreenElement, exitPictureInPicture(), or the JavaScript hub.

💡 Best Practices

✅ Do

  • Check document.fullscreenElement before exiting
  • Handle the Promise with await + try/catch or .catch()
  • Listen for fullscreenchange to update buttons and labels
  • Feature-detect (typeof document.exitFullscreen === "function")
  • Enter fullscreen only from a user gesture when calling requestFullscreen

❌ Don’t

  • Assume Baseline support in every browser yet (MDN: Limited availability)
  • Ignore promise rejections when exit fails
  • Rely on deprecated document.fullscreen for status
  • Forget Esc can exit without your Exit button
  • Expect fullscreen to work inside every iframe without permissions

Key Takeaways

Knowledge Unlocked

Five things to remember about exitFullscreen()

Leave fullscreen with a Promise; sync UI on change.

5
Core concepts
🔄02

Params

none

MDN
📄03

Guard

fullscreenElement

check
04

Pair

requestFullscreen

enter
🛡05

Status

Limited

not Baseline

❓ Frequently Asked Questions

MDN: Document.exitFullscreen() requests that the element currently presented in fullscreen mode be taken out of fullscreen, restoring 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 user agent has finished exiting fullscreen. If exiting fails, the promise rejects and you can handle it with catch() (MDN).
No. MDN: 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 whether exit came from script or the user.
Did you know?

You exit fullscreen on the Document, but you enter it on an Element via requestFullscreen(). That split is why status lives on document.fullscreenElement — one place to ask “who owns the screen right now?”

Next: exitPictureInPicture()

Learn how to leave Picture-in-Picture mode with document.exitPictureInPicture() and its Promise.

exitPictureInPicture() →

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.

6 people found this page helpful