JavaScript Document fullscreenchange Event

Beginner
⏱️ 12 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Document event
Limited availability

What You’ll Learn

The Document fullscreenchange event fires right after the page enters or leaves fullscreen. Learn why listening on document is powerful (the event bubbles), how to read document.fullscreenElement, how to toggle with requestFullscreen / exitFullscreen, and five try-it labs.

01

Kind

Document event

02

Type

Event

03

Cancelable

No

04

Bubbles

Yes (from Element)

05

State check

fullscreenElement

06

Status

Limited availability

Introduction

Games, video players, and slideshows often need the whole screen. The Fullscreen API lets an element go fullscreen with requestFullscreen(), and leave with document.exitFullscreen().

Per MDN, fullscreenchange is sent to the Element that is transitioning, then bubbles up to the Document. Listening on document is the usual app-wide pattern: one handler covers button toggles, Esc exits, and any widget going fullscreen.

💡
Beginner tip

Entering fullscreen usually requires a user gesture (click / key). Calling requestFullscreen() from a random timer often fails and may fire fullscreenerror instead. MDN marks this API Limited availability (not Baseline)—feature-detect and test.

Understanding fullscreenchange

A Document event that answers: “Did fullscreen mode just flip?”

  • Fires immediately after the browser switches into or out of fullscreen.
  • Target path — dispatched on the transitioning Element, then bubbles to document.
  • Does not encode enter vs exit — read document.fullscreenElement.
  • Not cancelable — it reports a change that already happened.
  • Event type — a plain Event.
  • Handlerdocument.onfullscreenchange or document.addEventListener("fullscreenchange", ...).
  • Limited availability on MDN (not Baseline)—test carefully.

📝 Syntax

Use the event name with addEventListener, or set the handler property on document:

JavaScript
addEventListener("fullscreenchange", (event) => { });

onfullscreenchange = (event) => { };

Event type

A generic Event.

Cancelable

No. This event is not cancelable.

Related Fullscreen API pieces

APIRole
element.requestFullscreen()Ask to enter fullscreen (returns a Promise)
document.exitFullscreen()Leave fullscreen (Document-only method)
document.fullscreenElementCurrent fullscreen element, or null
fullscreenerrorFires when enter/exit fails
:fullscreenCSS pseudo-class for the fullscreen element

🔁 Enter vs Exit

By the time your Document handler runs, the mode has already changed. Use this MDN pattern:

JavaScript
function fullscreenchangeHandler(event) {
  // document.fullscreenElement points to the fullscreen element if any;
  // otherwise it is null (left / canceled fullscreen).
  if (document.fullscreenElement) {
    console.log(
      `Element: ${document.fullscreenElement.id} entered fullscreen mode.`,
    );
  } else {
    console.log("Leaving fullscreen mode.");
  }
}

document.addEventListener("fullscreenchange", fullscreenchangeHandler);
  • document.fullscreenElement non-null → something is fullscreen.
  • null → no fullscreen element (left / canceled).

⚖️ Document vs Element listener

Listen onWhen to use
documentApp-wide UI that must react to any fullscreen change (including Esc)—MDN Document examples use this
The target ElementYou care about one widget only (video box, game canvas)

Because the event bubbles, a Document listener is often the simplest place for global chrome updates (button labels, overlays, analytics).

⚡ Quick Reference

GoalCode / note
Listen (Document)document.addEventListener("fullscreenchange", fn)
Handler propertydocument.onfullscreenchange = fn
Enterel.requestFullscreen() (user gesture)
Exitdocument.exitFullscreen()
Am I fullscreen?Boolean(document.fullscreenElement)
Cancelable?No
MDN statusLimited availability (not Baseline)

🔍 At a Glance

Four facts to remember about Document fullscreenchange.

Event type
Event

Plain Event

Means
FS toggled

Enter or exit

State check
fullscreenElement

null = exited

Baseline
no

Limited availability

Examples Gallery

Examples follow MDN Document: fullscreenchange event and listen on document. Try-it labs need a real browser click—some embedded previews block fullscreen.

📚 Getting Started

MDN-style Document listener and the handler property.

Example 1 — Toggle Fullscreen + Log (MDN)

Button toggles fullscreen; a Document fullscreenchange handler reports enter/exit.

JavaScript
const fullScreenElement = document.querySelector("#fullscreen-div");
const logger = document.querySelector("#logger");

function log(message) {
  logger.textContent = `${logger.textContent}\n${message}`;
}

function fullscreenchangeHandler() {
  if (document.fullscreenElement) {
    log(`Element: ${document.fullscreenElement.id} entered fullscreen mode.`);
  } else {
    log("Leaving fullscreen mode.");
  }
}

document.addEventListener("fullscreenchange", fullscreenchangeHandler);

document.getElementById("toggle-fullscreen").addEventListener("click", () => {
  if (document.fullscreenElement) {
    // exitFullscreen is only available on the Document object.
    document.exitFullscreen();
  } else {
    fullScreenElement.requestFullscreen();
  }
});
Try It Yourself

How It Works

The event reaches document via bubbling. Esc also exits and still fires fullscreenchange, so your Document handler stays in sync.

Example 2 — document.onfullscreenchange

Same idea using the Document handler property.

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

document.onfullscreenchange = () => {
  status.textContent = document.fullscreenElement
    ? "Fullscreen ON"
    : "Fullscreen OFF";
};

document.getElementById("toggle").addEventListener("click", () => {
  if (document.fullscreenElement) {
    document.exitFullscreen();
  } else {
    el.requestFullscreen();
  }
});
Try It Yourself

How It Works

Prefer addEventListener when you need multiple listeners or easy removal. Assigning onfullscreenchange again replaces the previous handler.

📈 Detect, Style & Errors

Feature-detect, sync CSS classes, and handle failures.

Example 3 — Feature-Detect Before Calling

Disable the button when Fullscreen API methods are missing.

JavaScript
const btn = document.getElementById("toggle");
const el = document.getElementById("fs");
const note = document.getElementById("note");

const canFs =
  typeof el.requestFullscreen === "function" &&
  typeof document.exitFullscreen === "function";

if (!canFs) {
  btn.disabled = true;
  note.textContent = "Fullscreen API not available in this environment.";
} else {
  note.textContent = "Fullscreen API looks available.";
  document.addEventListener("fullscreenchange", () => {
    note.textContent = document.fullscreenElement
      ? "Now fullscreen"
      : "Windowed again";
  });
  btn.addEventListener("click", () => {
    if (document.fullscreenElement) {
      document.exitFullscreen();
    } else {
      el.requestFullscreen();
    }
  });
}
Try It Yourself

How It Works

Limited availability means some engines or embedded frames may deny fullscreen even when the methods exist—still listen for fullscreenerror.

Example 4 — Sync a CSS Class on Document Change

Keep an is-fullscreen class in sync for custom chrome via a Document listener.

JavaScript
const el = document.getElementById("fs");
const btn = document.getElementById("toggle");

function syncClass() {
  el.classList.toggle("is-fullscreen", Boolean(document.fullscreenElement));
  btn.textContent = document.fullscreenElement
    ? "Exit fullscreen"
    : "Enter fullscreen";
}

document.addEventListener("fullscreenchange", syncClass);

btn.addEventListener("click", () => {
  if (document.fullscreenElement) {
    document.exitFullscreen();
  } else {
    el.requestFullscreen();
  }
});
Try It Yourself

How It Works

You can also style with the :fullscreen pseudo-class. The Document event keeps JS chrome (labels, overlays) aligned when Esc exits.

Example 5 — Pair with fullscreenerror

Handle failures and Promise rejection when enter/exit is denied.

JavaScript
const el = document.getElementById("fs");
const msg = document.getElementById("msg");

document.addEventListener("fullscreenchange", () => {
  msg.textContent = document.fullscreenElement
    ? "Fullscreen OK"
    : "Windowed mode";
});

document.addEventListener("fullscreenerror", () => {
  msg.textContent = "Could not change fullscreen (permission or environment).";
});

document.getElementById("toggle").addEventListener("click", () => {
  if (document.fullscreenElement) {
    document.exitFullscreen().catch(() => {});
  } else {
    el.requestFullscreen().catch(() => {
      msg.textContent = "requestFullscreen() rejected.";
    });
  }
});
Try It Yourself

How It Works

Always offer a non-fullscreen UI path. Embedded editors, missing gestures, and iframe policies are common failure causes.

🚀 Common Use Cases

  • Video / slideshow “fullscreen” buttons with live label updates.
  • Games that pause or resize when the user presses Esc to exit.
  • Analytics: count enter/exit without polling fullscreenElement.
  • Syncing custom chrome (toolbars, dark overlays) with fullscreen state.
  • One Document listener covering many widgets that can go fullscreen.

🔧 How It Works

1

User gesture

Click (or similar) calls requestFullscreen() or exitFullscreen().

Gesture
2

Browser switches mode

fullscreenElement updates before your handler runs.

State
3

Event on Element, then Document

Dispatched on the transitioning element; bubbles to document.

Bubble
4

Update UI

Read fullscreenElement and refresh labels, classes, or layout.

📝 Notes

  • MDN: Limited availability (not Baseline)—test the browsers you support.
  • Not Deprecated, Experimental, or Non-standard—but permissions and iframes still matter.
  • Not cancelable; check document.fullscreenElement for enter vs exit.
  • exitFullscreen() exists only on document, not on the element.
  • Related learning: fullscreenElement, exitFullscreen(), fullscreenEnabled, JavaScript hub.

Limited Availability Support

Document fullscreenchange is marked Limited availability on MDN (not Baseline). Logos use the shared browser-image-sprite.png sprite from this project. Feature-detect requestFullscreen / exitFullscreen, and remember iframes and permissions can still block fullscreen.

Limited availability

Document fullscreenchange

Fullscreen enter/exit signal on Document (bubbles from the element). Confirm support and permissions in your target browsers.

Limited Not Baseline
Google Chrome Supported (check BCD / iframe policy)
Supported
Mozilla Firefox Supported in modern versions
Supported
Apple Safari Supported with platform quirks
Supported
Microsoft Edge Supported · Chromium
Supported
Opera Supported · Modern versions
Supported
Internet Explorer No modern Fullscreen API
No
fullscreenchange Limited

Bottom line: Listen on document for fullscreenchange, check document.fullscreenElement, and handle fullscreenerror. Prefer a user gesture for requestFullscreen().

Conclusion

Document fullscreenchange tells you fullscreen mode already flipped—often after the event bubbled from the element. Drive your UI from document.fullscreenElement, enter with requestFullscreen() after a user gesture, and exit with document.exitFullscreen().

Continue with fullscreenerror, exitFullscreen(), or the JavaScript hub.

💡 Best Practices

✅ Do

  • Listen on document for app-wide fullscreen UI updates
  • Check document.fullscreenElement inside the handler
  • Call requestFullscreen() from a user gesture
  • Feature-detect and handle fullscreenerror / Promise rejection
  • Keep a usable non-fullscreen layout as a fallback

❌ Don’t

  • Assume every browser / iframe allows fullscreen
  • Call enter fullscreen from a random timer
  • Expect the event itself to say “enter” vs “exit”
  • Call exitFullscreen on the element (it is on document)
  • Ignore Esc exits—they still fire fullscreenchange

Key Takeaways

Knowledge Unlocked

Five things to remember about Document fullscreenchange

Bubbled fullscreen toggle signal — read fullscreenElement for state.

5
Core concepts
🔁 02

Bubbles

Element → Document

Path
🔍 03

Check element

null = exited

State
👋 04

User gesture

for requestFullscreen

API
⚠️ 05

Limited avail.

feature-detect

Compat

❓ Frequently Asked Questions

It fires immediately after the browser switches into or out of fullscreen mode. The event is sent to the Element that is transitioning, then bubbles up to the Document, so listening on document catches every change.
No. MDN does not mark Document fullscreenchange as Deprecated, Experimental, or Non-standard. It has Limited availability (not Baseline), so always test the browsers and embedding contexts you care about.
After the event fires, check document.fullscreenElement. If it is non-null, an element is in fullscreen. If it is null, fullscreen mode was canceled or exited.
No. MDN states this event is not cancelable. It reports a change that already happened.
Call element.requestFullscreen() to enter (usually from a user gesture). Call document.exitFullscreen() to exit — exitFullscreen is only available on Document. Listen for fullscreenchange to update your UI.
Listen for the fullscreenerror event (on the element or document, depending on your setup). Failures often happen without a user gesture, in unsupported browsers, denied iframes, or when the browser refuses permission.
Did you know?

Pressing Esc to leave fullscreen still fires fullscreenchange on the way to document. That is why a Document listener is often better than only wiring your own “Exit” button—Esc would otherwise leave your UI out of date.

Next: Document fullscreenerror

Learn what to do when the browser cannot switch to fullscreen mode.

fullscreenerror →

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.

5 people found this page helpful