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
Fundamentals
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.
Concept
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.
Handler — document.onfullscreenchange or document.addEventListener("fullscreenchange", ...).
Limited availability on MDN (not Baseline)—test carefully.
Foundation
📝 Syntax
Use the event name with addEventListener, or set the handler property on document:
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).
Compare
⚖️ Document vs Element listener
Listen on
When to use
document
App-wide UI that must react to any fullscreen change (including Esc)—MDN Document examples use this
The target Element
You 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).
Cheat Sheet
⚡ Quick Reference
Goal
Code / note
Listen (Document)
document.addEventListener("fullscreenchange", fn)
Handler property
document.onfullscreenchange = fn
Enter
el.requestFullscreen() (user gesture)
Exit
document.exitFullscreen()
Am I fullscreen?
Boolean(document.fullscreenElement)
Cancelable?
No
MDN status
Limited availability (not Baseline)
Snapshot
🔍 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
Hands-On
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();
}
});
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.
LimitedNot Baseline
Google ChromeSupported (check BCD / iframe policy)
Supported
Mozilla FirefoxSupported in modern versions
Supported
Apple SafariSupported with platform quirks
Supported
Microsoft EdgeSupported · Chromium
Supported
OperaSupported · Modern versions
Supported
Internet ExplorerNo modern Fullscreen API
No
fullscreenchangeLimited
Bottom line: Listen on document for fullscreenchange, check document.fullscreenElement, and handle fullscreenerror. Prefer a user gesture for requestFullscreen().
Wrap Up
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().
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
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about Document fullscreenchange
Bubbled fullscreen toggle signal — read fullscreenElement for state.
5
Core concepts
📄01
After toggle
enter or exit
Event
🔁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.