Fullscreen API

Living Standard — Last Updated

Participate:
open issues)
Chat on Matrix
Commits:
GitHub whatwg/fullscreen/commits
Snapshot as of this commit
@fullscreenapi
Tests:
ongoing work)
Translations (non-normative):
日本語
简体中文

Abstract

The Fullscreen API standard defines an API for elements to display themselves fullscreen.

1. Terminology

This specification depends on the Infra Standard. [INFRA]

Most terminology used in this specification is from CSS, DOM, HTML, and Web IDL. [CSS] [DOM] [HTML] [WEBIDL]

2. Model

All elements have an associated fullscreen flag. Unless stated otherwise it is unset.

All elements have an associated iframe fullscreen flag. Unless stated otherwise it is unset.

All top layer whose fullscreen flag is set, if any, and null otherwise.

All documents have an associated list of pending fullscreen events, which is an tuples. It is initially empty.

To fullscreen an element:

  1. Let hideUntil be the result of running topmost popover ancestor given element, null, and false.

  2. If hideUntil is null, then set hideUntil to element’s node document.

  3. Run hide all popovers until given hideUntil, false, and true.

  4. Set element’s fullscreen flag.

  5. Remove from the top layer immediately given element.

  6. Add to the top layer given element.

To unfullscreen an element, unset element’s fullscreen flag and iframe fullscreen flag (if any), and remove from the top layer immediately given element.

To unfullscreen a document, unfullscreen all top layer, whose fullscreen flag is set.


To fully exit fullscreen a document document, run these steps:

  1. If document’s fullscreen element is null, terminate these steps.

  2. Unfullscreen elements whose fullscreen flag is set, within document’s top layer, except for document’s fullscreen element.

  3. Exit fullscreen document.

Whenever the removing steps run with a removedNode, run these steps:

  1. Let document be removedNode’s node document.

  2. Let nodes be removedNode’s shadow-including tree order.

  3. For each node in nodes:

    1. If node is document’s fullscreen element, exit fullscreen document.

    2. Otherwise, unfullscreen node.

    3. If document’s remove from the top layer immediately given node.

      Other specifications can add and remove elements from dialog element.

Whenever the unloading document cleanup steps run with a document, fully exit fullscreen document.


Fullscreen is supported if there is no previously-established user preference, security risk, or platform limitation.


To run the fullscreen steps for a document document, run these steps:

  1. Let pendingEvents be document’s list of pending fullscreen events.

  2. Empty document’s list of pending fullscreen events.

  3. For each (type, element) in pendingEvents:

    1. Let target be element if element is node document is document, and otherwise let target be document.

    2. composed attributes set to true, at target.

These steps integrate with the event loop defined in HTML. [HTML]

3. API

enum FullscreenNavigationUI {
  "auto",
  "show",
  "hide"
};

dictionary FullscreenOptions {
  FullscreenNavigationUI navigationUI = "auto";
};

partial interface Element {
  undefined> requestFullscreen(optional FullscreenOptions options = {});

  attribute EventHandler onfullscreenchange;
  attribute EventHandler onfullscreenerror;
};

partial interface Document {
  [boolean fullscreenEnabled;
  [boolean fullscreen; / historical

  undefined> exitFullscreen();

  attribute EventHandler onfullscreenchange;
  attribute EventHandler onfullscreenerror;
};

partial interface mixin DocumentOrShadowRoot {
  [Element? fullscreenElement;
};
promise = element . requestFullscreen([options])
Displays element fullscreen and resolves promise when done.

When supplied, options’s navigationUI member indicates whether showing navigation UI while in fullscreen is preferred or not. If set to "show", navigation simplicity is preferred over screen space, and if set to "hide", more screen space is preferred. User agents are always free to honor user preference over the application’s. The default value "auto" indicates no application preference.

document . fullscreenEnabled

Returns true if document has the ability to display elements fullscreen and fullscreen is supported, or false otherwise.

promise = document . exitFullscreen()

Stops document’s fullscreen element from being displayed fullscreen and resolves promise when done.

document . fullscreenElement

Returns document’s fullscreen element.

shadowroot . fullscreenElement

Returns shadowroot’s fullscreen element.

A fullscreen element ready check for an element element returns true if all of the following are true, and false otherwise:

The requestFullscreen(options) method steps are:

  1. Let pendingDoc be node document.

  2. Let promise be a new promise.

  3. If pendingDoc is not TypeError exception and return promise.

  4. Let error be false.

  5. If any of the following conditions are false, then set error to true:

  6. If error is false, then relevant global object.

  7. Return promise, and run the remaining steps in parallel.

  8. If error is false, then resize pendingDoc’s active document’s viewport’s dimensions, optionally taking into account options["navigationUI"]:

    value viewport dimensions
    "hide" full dimensions of the screen of the output device
    "show" dimensions of the screen of the output device clamped to allow the user agent to show page navigation controls
    "auto" user-agent defined, but matching one of the above

    Optionally display a message how the end user can revert this.

  9. If any of the following conditions are false, then set error to true:

  10. If error is true:

    1. this) to pendingDoc’s list of pending fullscreen events.

    2. Reject promise with a TypeError exception and terminate these steps.

  11. Let fullscreenElements be an this.

  12. While true:

    1. Let last be the last item of fullscreenElements.

    2. Let container be last’s container.

    3. If container is null, then break.

    4. Append container to fullscreenElements.

  13. For each element in fullscreenElements:

    1. Let doc be element’s node document.

    2. If element is doc’s fullscreen element, continue.

      No need to notify observers when nothing has changed.

    3. If element is element, then set element’s iframe fullscreen flag.

    4. Fullscreen element within doc.

    5. Append (fullscreenchange, element) to doc’s list of pending fullscreen events.

    The order in which elements are fullscreened is not observable, because run the fullscreen steps is invoked in tree order.

  14. Resolve promise with undefined.

Implementations with out-of-process navigables are left as an exercise to the reader. Input welcome on potential improvements.

The fullscreenEnabled getter steps are to return true if allowed to use the "fullscreen" feature and fullscreen is supported, and false otherwise.

The fullscreen getter steps are to return false if this’s fullscreen element is null, and true otherwise.

Use the fullscreenElement attribute instead.

The fullscreenElement getter steps are:

  1. If connected, then return null.

  2. Let candidate be the result of this.

  3. If candidate and tree, then return candidate.

  4. Return null.

A top layer that has its fullscreen flag set.

A top layer can be a simple fullscreen document. For example, in addition to the fullscreen element there could be an open dialog element.

To collect documents to unfullscreen given doc, run these steps:

  1. Let docs be an ordered set consisting of doc.

  2. While true:

    1. Let lastDoc be docs’s last document.

    2. Assert: lastDoc’s fullscreen element is not null.

    3. If lastDoc is not a simple fullscreen document, break.

    4. Let container be lastDoc’s container.

    5. If container is null, then break.

    6. If container’s iframe fullscreen flag is set, break.

    7. node document to docs.

  3. Return docs.

    This is the set of documents for which the fullscreen element will be unfullscreened, but the last document in docs might have more than one top layer with the fullscreen flag set, in which case that document will still remain in fullscreen.

To exit fullscreen a document doc, run these steps:

  1. Let promise be a new promise.

  2. If doc is not TypeError exception and return promise.

  3. Let resize be false.

  4. Let docs be the result of collecting documents to unfullscreen given doc.

  5. Let topLevelDoc be doc’s active document.

  6. If topLevelDoc is in docs, and it is a simple fullscreen document, then set doc to topLevelDoc and resize to true.

  7. If doc’s fullscreen element is not connected:

    1. Append (fullscreenchange, doc’s fullscreen element) to doc’s list of pending fullscreen events.

    2. Unfullscreen doc’s fullscreen element.

  8. Return promise, and run the remaining steps in parallel.

  9. Run the fully unlock the screen orientation steps with doc.

  10. If resize is true, resize doc’s viewport to its "normal" dimensions.

  11. If doc’s fullscreen element is null, then resolve promise with undefined and terminate these steps.

  12. Let exitDocs be the result of collecting documents to unfullscreen given doc.

  13. Let descendantDocs be an tree order.

  14. For each exitDoc in exitDocs:

    1. Append (fullscreenchange, exitDoc’s fullscreen element) to exitDoc’s list of pending fullscreen events.

    2. If resize is true, unfullscreen exitDoc.

    3. Otherwise, unfullscreen exitDoc’s fullscreen element.

  15. For each descendantDoc in descendantDocs:

    1. Append (fullscreenchange, descendantDoc’s fullscreen element) to descendantDoc’s list of pending fullscreen events.

    2. Unfullscreen descendantDoc.

    The order in which documents are unfullscreened is not observable, because run the fullscreen steps is invoked in tree order.

  16. Resolve promise with undefined.

The exitFullscreen() method steps are to return the result of running exit fullscreen on this.


The following are the Document objects as event handler IDL attributes:

event handler event handler event type
onfullscreenchange fullscreenchange
onfullscreenerror fullscreenerror

These are not supported by Window objects, and there are no corresponding Element objects in any namespace.

4. UI

User agents are encouraged to implement native media fullscreen controls in terms of requestFullscreen() and exitFullscreen().

If the end user instructs the user agent to end a fullscreen session initiated via requestFullscreen(), fully exit fullscreen given the active document.

The user agent may end any fullscreen session without instruction from the end user or call to exitFullscreen() whenever the user agent deems it necessary.

5. Rendering

This section is to be interpreted equivalently to the Rendering section of HTML. [HTML]

5.1. :fullscreen pseudo-class

The :fullscreen pseudo-class must match any element element for which one of the following conditions is true:

This makes it different from the fullscreenElement API, which returns the topmost fullscreen element.

5.2. User-agent level style sheet defaults

@namespace "http://www.w3.org/1999/xhtml";

*|*:not(:root):fullscreen {
  position:fixed !important;
  inset:0 !important;
  margin:0 !important;
  box-sizing:border-box !important;
  min-width:0 !important;
  max-width:none !important;
  min-height:0 !important;
  max-height:none !important;
  width:100% !important;
  height:100% !important;
  transform:none !important;

  /* intentionally not !important */
  object-fit:contain;
}

iframe:fullscreen {
  border:none !important;
  padding:0 !important;
}

*|*:not(:root):fullscreen::backdrop {
  background:black;
}

6. Permissions Policy Integration

This specification defines a policy-controlled feature identified by the string "fullscreen". Its default allowlist is 'self'.

A permissions policy determines whether any content in that document is allowed to go fullscreen. If disabled in any document, no content in the document will be allowed to use fullscreen.

The container policy for any document nested in that iframe. Unless overridden by the allowfullscreen on an iframe is equivalent to <iframe allow="fullscreen *">, as described in Permissions Policy § 6.3.1 allowfullscreen.

7. Security and Privacy Considerations

User agents should ensure, e.g. by means of an overlay, that the end user is aware something is displayed fullscreen. User agents should provide a means of exiting fullscreen that always works and advertise this to the user. This is to prevent a site from spoofing the end user by recreating the user agent or even operating system environment when fullscreen. See also the definition of requestFullscreen().

To enable content in a child navigable to go fullscreen, it needs to be specifically allowed via permissions policy, either through the iframe element, or through a `Permissions-Policy` HTTP header delivered with the document through which it is nested.

This prevents e.g. content from third parties to go fullscreen without explicit permission.

This specification previously hosted the definitions of top layer.

Acknowledgments

Many thanks to Robert O’Callahan for designing the initial model and being awesome.

Thanks to Andy Earnshaw, Changwan Hong, Chris Pearce, Darin Fisher, Dave Tapuska, fantasai, Giuseppe Pascale, Glenn Maynard, Ian Clelland, Ian Hickson, Ignacio Solla, João Eiras, Josh Soref, Kagami Sascha Rosylight, Matt Falkenhagen, Mihai Balan, Mounir Lamouri, Øyvind Stenhaug, Pat Ladd, Rafał Chłodnicki, Riff Jiang, Rune Lillesveen, Sigbjørn Vik, Simon Pieters, Tab Atkins-Bittner, Takayoshi Kochi, Theresa O’Connor, triple-underscore, Vincent Scheib, and Xidorn Quan for also being awesome.

This standard is edited by Philip Jägenstedt (Google, [email protected]). It was originally written by Anne van Kesteren (Apple, [email protected]). Tantek Çelik (Mozilla, [email protected]) sorted out legal hassles.

Intellectual property rights

Copyright © WHATWG (Apple, Google, Mozilla, Microsoft). This work is licensed under a Creative Commons Attribution 4.0 International License. To the extent portions of it are incorporated into source code, such portions in the source code are licensed under the BSD 3-Clause License instead.

This is the Living Standard. Those interested in the patent-review version should view the Living Standard Review Draft.

Index

Terms defined by this specification

Terms defined by reference

References

Normative References

[CSS]
Bert Bos; et al. https://drafts.csswg.org/css2/
[CSS-POSITION-4]
https://drafts.csswg.org/css-position-4/
[DOM]
Anne van Kesteren. DOM Standard. Living Standard. URL: https://dom.spec.whatwg.org/
[HTML]
Anne van Kesteren; et al. https://html.spec.whatwg.org/multipage/
[INFRA]
Anne van Kesteren; Domenic Denicola. Infra Standard. Living Standard. URL: https://infra.spec.whatwg.org/
[MATHML]
Patrick D F Ion; Robert R Miner. [PERMISSIONS-POLICY-1]
Ian Clelland. https://w3c.github.io/webappsec-permissions-policy/
[SCREEN-ORIENTATION]
Marcos Caceres. [SVG]
Erik Dahlström; et al. https://www.w3.org/TR/SVG11/
[WEBIDL]
Edgar Chen; Timothy Gu. Web IDL Standard. Living Standard. URL: https://webidl.spec.whatwg.org/

IDL Index

enum FullscreenNavigationUI {
  "auto",
  "show",
  "hide"
};

dictionary FullscreenOptions {
  FullscreenNavigationUI navigationUI = "auto";
};

partial interface Element {
  undefined> requestFullscreen(optional FullscreenOptions options = {});

  attribute EventHandler onfullscreenchange;
  attribute EventHandler onfullscreenerror;
};

partial interface Document {
  [boolean fullscreenEnabled;
  [boolean fullscreen; / historical

  undefined> exitFullscreen();

  attribute EventHandler onfullscreenchange;
  attribute EventHandler onfullscreenerror;
};

partial interface mixin DocumentOrShadowRoot {
  [Element? fullscreenElement;
};

MDN

Document/exitFullscreen

In all current engines.

Firefox64+Safari16.4+Chrome71+
Opera58+Edge79+
Edge (Legacy)NoneIENone
Firefox for Android?iOS SafariNoneChrome for Android?Android WebView71+Samsung Internet?Opera Mobile50+
MDN

Document/fullscreenchange_event

In all current engines.

Firefox64+Safari16.4+Chrome71+
Opera58+Edge79+
Edge (Legacy)NoneIENone
Firefox for Android?iOS SafariNoneChrome for Android?Android WebView71+Samsung Internet?Opera Mobile50+

Element/fullscreenchange_event

In all current engines.

Firefox64+Safari16.4+Chrome71+
Opera58+Edge79+
Edge (Legacy)NoneIENone
Firefox for Android?iOS SafariNoneChrome for Android?Android WebView71+Samsung Internet?Opera Mobile50+
MDN

Document/fullscreenElement

In all current engines.

Firefox64+Safari16.4+Chrome71+
Opera58+Edge79+
Edge (Legacy)NoneIENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile50+
MDN

Document/fullscreenEnabled

In all current engines.

Firefox64+Safari16.4+Chrome71+
Opera58+Edge79+
Edge (Legacy)12+IENone
Firefox for Android?iOS SafariNoneChrome for Android?Android WebView?Samsung Internet?Opera Mobile50+
MDN

Document/fullscreenerror_event

In all current engines.

Firefox64+Safari16.4+Chrome71+
Opera58+Edge79+
Edge (Legacy)NoneIENone
Firefox for Android?iOS SafariNoneChrome for Android?Android WebView71+Samsung Internet?Opera Mobile50+

Element/fullscreenerror_event

In all current engines.

Firefox64+Safari16.4+Chrome71+
Opera58+Edge79+
Edge (Legacy)NoneIENone
Firefox for Android?iOS SafariNoneChrome for Android?Android WebView71+Samsung Internet?Opera Mobile50+
MDN

Element/requestFullscreen

In all current engines.

Firefox64+Safari16.4+Chrome71+
Opera58+Edge79+
Edge (Legacy)NoneIENone
Firefox for Android64+iOS SafariNoneChrome for Android?Android WebView71+Samsung Internet?Opera Mobile50+
MDN

Element

In all current engines.

Firefox1+Safari1+Chrome1+
Opera8+Edge79+
Edge (Legacy)12+IE4+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView37+Samsung Internet?Opera Mobile10.1+
MDN

ShadowRoot/fullscreenElement

In all current engines.

Firefox64+Safari16.4+Chrome71+
Opera?Edge79+
Edge (Legacy)?IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?
MDN

:fullscreen

Firefox64+SafariNoneChrome71+
Opera?Edge79+
Edge (Legacy)12+IENone
Firefox for Android?iOS SafariNoneChrome for Android?Android WebView71+Samsung Internet?Opera Mobile?
MDN

Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant