Element: fullscreenchange event

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

The fullscreenchange event is fired immediately after an Element switches into or out of fullscreen mode.

This event is sent to the Element which is transitioning into or out of fullscreen mode.

To find out whether the Element is entering or exiting fullscreen mode, check the value of Document.fullscreenElement: if this value is null then the element is exiting fullscreen mode, otherwise it is entering fullscreen mode.

This event is not cancelable.

Syntax

Use the event name in methods like addEventListener(), or set an event handler property.

js
addEventListener("fullscreenchange", (event) => { })

onfullscreenchange = (event) => { }

Event type

A generic Event.

Examples

In this example, a handler for the fullscreenchange event is added to the element whose ID is fullscreen-div.

If the user clicks on the "Toggle Fullscreen Mode" button, the click handler will toggle fullscreen mode for the div. If document.fullscreenElement has a value it will exit fullscreen mode. If not, the div will be placed into fullscreen mode.

Remember that by the time the fullscreenchange event is handled, the status of the element has already changed. So if the change is to fullscreen mode, document.fullscreenElement will point to the element that is now in fullscreen mode. On the other hand, if document.fullscreenElement is null, fullscreen mode has been canceled.

What that means to the example code is that, if an element is currently in fullscreen mode, the fullscreenchange handler logs the id of the fullscreen element to the console. If document.fullscreenElement is null, the code logs a message that the change is to leave fullscreen mode.

HTML

html
<h1>fullscreenchange event example</h1>
<div id="fullscreen-div">
  <button id="toggle-fullscreen">Toggle Fullscreen Mode</button>
</div>

JavaScript

js
function fullscreenchangeHandler(event) {
  // document.fullscreenElement will point to the element that
  // is in fullscreen mode if there is one. If not, the value
  // of the property is null.
  if (document.fullscreenElement) {
    console.log(
      `Element: ${document.fullscreenElement.id} entered fullscreen mode.`,
    );
  } else {
    console.log("Leaving fullscreen mode.");
  }
}

const el = document.getElementById("fullscreen-div");

el.addEventListener("fullscreenchange", fullscreenchangeHandler);
// or
el.onfullscreenchange = fullscreenchangeHandler;

// When the toggle button is clicked, enter/exit fullscreen
document
  .getElementById("toggle-fullscreen")
  .addEventListener("click", (event) => {
    if (document.fullscreenElement) {
      // exitFullscreen is only available on the Document object.
      document.exitFullscreen();
    } else {
      el.requestFullscreen();
    }
  });

Specifications

Specification
Fullscreen API
# handler-document-onfullscreenchange

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
fullscreenchange event
Chrome – Full support
Chrome 15 (Release date: 2011-10-25)
prefix
prefix Implemented with the vendor prefix: webkit
Chrome – Full support
Chrome 71 (Release date: 2018-12-04)
footnote Full support
Edge – No support
Edge 12 – 13 (Release date: 2015-07-29)
footnote Removed in 14 and later
Edge – Full support
Edge 12 (Release date: 2015-07-29)
prefix
prefix Implemented with the vendor prefix: webkit
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Full support
Firefox 10 (Release date: 2012-01-31)
prefix
prefix Implemented with the vendor prefix: moz
Firefox – Full support
Firefox 64 (Release date: 2018-12-11)
footnote Full support
Opera – No support
Opera 12.1 – 12.1 (Release date: 2012-11-20)
unknown Support unknown
Opera – Full support
Opera 15 (Release date: 2013-07-02)
prefix
prefix Implemented with the vendor prefix: webkit
Opera – Full support
Opera 58 (Release date: 2019-01-23)
footnote Full support
Safari – Full support
Safari 5.1 (Release date: 2011-07-20)
prefix
prefix Implemented with the vendor prefix: webkit
Safari – Full support
Safari 16.4 (Release date: 2023-03-27)
footnote Full support
Chrome Android – Full support
Chrome Android 18 (Release date: 2012-06-27)
prefix
prefix Implemented with the vendor prefix: webkit
Chrome Android – Full support
Chrome Android 71 (Release date: 2018-12-04)
footnote Full support
Firefox for Android – Full support
Firefox for Android 10 (Release date: 2012-01-31)
prefix
prefix Implemented with the vendor prefix: moz
Firefox for Android – Full support
Firefox for Android 64 (Release date: 2018-12-11)
footnote Full support
Opera Android – No support
Opera Android 12.1 – 12.1 (Release date: 2012-10-09)
unknown Support unknown
Opera Android – Full support
Opera Android 14 (Release date: 2013-05-21)
prefix
prefix Implemented with the vendor prefix: webkit
Opera Android – Full support
Opera Android 50 (Release date: 2019-02-18)
footnote Full support
Safari on iOS – Partial support
Safari on iOS 12 (Release date: 2018-09-17)
prefix
footnote Partial support
prefix Implemented with the vendor prefix: webkit
footnote Only available on iPad, not on iPhone.
Safari on iOS – Partial support
Safari on iOS 16.4 (Release date: 2023-03-27)
footnote Partial support
footnote Only available on iPad, not on iPhone.
footnote Shows an overlay button which can not be disabled. Swiping down exits fullscreen mode, making it unsuitable for some use cases like games.
Samsung Internet – Full support
Samsung Internet 1 (Release date: 2013-04-27)
prefix
prefix Implemented with the vendor prefix: webkit
Samsung Internet – Full support
Samsung Internet 10 (Release date: 2019-08-22)
footnote Full support
WebView Android – Full support
WebView Android 4.4 (Release date: 2013-12-09)
prefix
prefix Implemented with the vendor prefix: webkit
WebView Android – Full support
WebView Android 71 (Release date: 2018-12-04)
footnote Full support
WebView on iOS – No support
WebView on iOS
footnote No support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Partial support
Partial support
No support
No support
Requires a vendor prefix or different name for use.
Has more compatibility info.

See also