Fullscreen defines the fullscreen API for the web platform.
All diagrams, examples, and notes in this specification are non-normative, as are all sections explicitly marked non-normative. Everything else in this specification is normative.
The key words "MUST", "MUST NOT", "REQUIRED", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in the normative parts of this specification are to be interpreted as described in RFC2119. For readability, these words do not appear in all uppercase letters in this specification. [RFC2119]
Most terminology used in this specification is from CSS, DOM, HTML, and Web IDL. [CSS] [DOM] [HTML] [WEBIDL]
The term context object means the object on which the method or attribute being discussed was called. When the context object is unambiguous, the term can be omitted.
A browsing context A is called a descendant browsing context of a browsing context B if and only if B is an ancestor browsing context of A.
The task source used by this specification is the user interaction task source.
All documents have an associated fullscreen enabled flag and fullscreen element stack. Unless otherwise stated the fullscreen enabled flag is unset and the fullscreen element stack is an initially empty ordered set.
HTML defines the exact conditions under which the
fullscreen enabled flag is set. A
document from a
top-level browsing context will have it set. For a
nested browsing context it is only set if the
iframe
element that is responsible for creating the
nested browsing context has its
allowfullscreen
attribute set. That attribute is
defined by HTML as well.
[HTML]
To add an element on a document's fullscreen element stack, add, or move if already present, it on top of document's browsing context's top layer, and then add, or move if already present, it on top of document's fullscreen element stack.
To remove an element from a document's fullscreen element stack, remove it from document's browsing context's top layer, and then remove it from document's fullscreen element stack.
To empty a document's fullscreen element stack, remove all the elements in it from document's browsing context's top layer, and then empty document's fullscreen element stack.
To fully exit fullscreen, run these steps:
Let doc be the top-level browsing context's document.
If doc's fullscreen element stack is empty, terminate these steps.
Remove elements from doc's fullscreen element stack until only the top element is left.
Act as if the exitFullscreen()
method was invoked on doc.
HTML invokes the fully exit fullscreen algorithm for navigation. [HTML]
Whenever the removing steps run with an oldNode, run these steps:
Let nodes be oldNode's inclusive descendants, in tree order that are also in oldNode's node document's fullscreen element stack.
For each node in nodes, run these substeps:
If node is at the top of its
node document's
fullscreen element stack, act as if the
exitFullscreen()
method was invoked on
that document and terminate
these steps.
Otherwise, remove node from its node document's fullscreen element stack.
Fullscreen is supported if there is no previously-established user preference, security risk, or platform limitation.
partial interface Element { void requestFullscreen(); }; partial interface Document { readonly attribute boolean fullscreenEnabled; readonly attribute Element? fullscreenElement; void exitFullscreen(); attribute EventHandler onfullscreenchange; attribute EventHandler onfullscreenerror; };
element . requestFullscreen()
Displays element fullscreen.
document . fullscreenEnabled
Returns true if document has the ability to display elements fullscreen and fullscreen is supported, or false otherwise.
document . fullscreenElement
Returns the element that is displayed fullscreen, or null if there is no such element.
document . exitFullscreen()
Stops any elements within document from being displayed fullscreen.
A fullscreen element ready check for an element element returns true if all of the following are true, and false otherwise:
element is in a document.
element's node document's fullscreen enabled flag is set.
element's node document's fullscreen element stack is either empty or its top element is an inclusive ancestor of element.
element has no
ancestor
element whose
local name is
iframe
and
namespace is the
HTML namespace.
element's node document's browsing context either has a browsing context container and the fullscreen element ready check returns true for element's node document's browsing context's browsing context container, or it has no browsing context container.
The requestFullscreen()
method, when invoked, must run these steps:
Let pending be the context object.
Let error be false.
If any of the following conditions are true, set error to true:
The fullscreen element ready check for pending returns false.
This algorithm is not allowed to show a popup.
Return, and run the remaining steps asynchronously.
If error is false: Resize pending's top-level browsing context's document's viewport's dimensions to match the dimensions of the screen of the output device. Optionally display a message how the end user can revert this.
As part of the next animation frame task, run these substeps:
If either error is true or the
fullscreen element ready check for pending returns false,
fire an event named
fullscreenerror
on pending's
node document and
terminate these steps.
Let fullscreenElements be an ordered set initially consisting of pending.
While the first element in fullscreenElements is in a nested browsing context, prepend its browsing context container to fullscreenElements.
Then for each element element in fullscreenElements, in order, run these subsubsteps:
Let doc be element's node document.
If element is on top of doc's fullscreen element stack, terminate these substeps.
No need to notify observers when nothing has changed.
Add element on doc's fullscreen element stack.
Fire an event named
fullscreenchange
on doc.
Animation frame task is not really defined yet, including relative order within that task, see bug 26440.
Implementations with out-of-process browsing contexts are left as an exercise to the reader. Input welcome on potential improvements.
The fullscreenEnabled
attribute's getter must return true if the context object has its
fullscreen enabled flag set and fullscreen is supported, and
false otherwise.
The fullscreenElement
attribute's getter must return the top
element of the
context object's fullscreen element stack, and null otherwise.
To collect ancestors given a document doc, run these steps:
Let docs be an ordered set consisting of doc.
While docs's last document has a browsing context container whose node document's fullscreen element stack consists of one element, append that node document to docs.
Return docs.
The
exitFullscreen()
method, when invoked, must run these steps:
Let doc be the context object.
If doc's fullscreen element stack is empty, terminate these steps.
Let resize be false.
Let docs be the result of collecting ancestors given doc.
Let topLevelDoc be doc's top-level browsing context's document.
If topLevelDoc is in docs, set resize to true.
Return, and run the remaining steps asynchronously.
If resize is true, resize topLevelDoc's viewport to its "normal" dimensions.
As part of the next animation frame task, run these substeps:
Let exitDocs be the result of collecting ancestors given doc.
If resize is true and topLevelDoc is not in exitDocs, fully exit fullscreen and terminate these steps.
If exitDocs's last document has a browsing context container, append that browsing context container's node document to exitDocs.
Let descendantDocs be an ordered set consisting of doc's descendant browsing contexts' documents with a non-empty fullscreen element stack (if any), in reverse tree order.
For each descendantDoc in descendantDocs,
empty descendantDoc's
fullscreen element stack and
fire an event named
fullscreenchange
on descendantDoc.
For each exitDoc in exitDocs,
remove the top
element from
exitDoc's fullscreen element stack and
fire an event named
fullscreenchange
on exitDoc.
The following are the event handlers (and their corresponding event handler event types) that must be supported on documents as attributes:
event handler | event handler event type |
---|---|
onfullscreenchange
| fullscreenchange
|
onfullscreenerror
| fullscreenerror
|
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.
This section is to be interpreted equivalently to the Rendering section of HTML. [HTML]
Long term CSS will define the top layer concept
and its associated ::backdrop
pseudo-element as part of CSS' stacking context model. Patching CSS as done
here is sketchy as hell.
This specification introduces a new stacking layer to the Elaborate description of Stacking Contexts of CSS 2.1. It is called the top layer, comes after step 10 in the painting order, and is therefore rendered closest to the user within a viewport. Each browsing context has one associated viewport and therefore also one top layer. [CSS]
The terminology used in this and following subsection attempts to match CSS 2.1 Appendix E.
The top layer consists of an ordered set of elements, rendered in the order they have been added to the set. The last element added is rendered closest to the user.
The z-index
property has no effect in the
top layer.
An element in a top layer has the following characteristics:
It generates a new stacking context.
Its parent stacking context is the root stacking context.
If it consists of multiple layout boxes, the first box is used.
It is rendered as an atomic unit as if it were a sibling of the root element.
Ancestor elements with overflow, opacity, masks, etc. cannot affect it.
If its position
property computes to fixed
,
its containing block is the viewport, and the initial containing block otherwise.
It is not rendered if it, or an ancestor, has the
display
property set to none
.
If its specified position
property is
static
or relative
, it computes to
absolute
.
Its outline, if any, is to be rendered before step 10 in the painting order.
Unless overridden by another specification, its static position for
left
, right
, and
top
is zero.
::backdrop
pseudo-elementEach element in a top layer has a
::backdrop
pseudo-element.
This pseudo-element is a box rendered immediately below the element (and
above the element before the element in the set, if any), within the same
top layer. This pseudo-element box has the same characteristics
as any element box in the top layer.
The ::backdrop
pseudo-element can be used
to create a backdrop that hides the underlying document for an element in a
top layer (such as an element that is displayed fullscreen).
It does not inherit from any element and is not inherited from. No restrictions are made on what properties apply to this pseudo-element either.
:fullscreen
pseudo-classThe :fullscreen
pseudo-class must match the top
element of the
document's
fullscreen element stack (if any).
@namespace "http://www.w3.org/1999/xhtml"; *|*:not(:root):fullscreen { position:fixed !important; top:0 !important; right:0 !important; bottom:0 !important; left: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; object-fit:contain !important; transform:none !important; } iframe:fullscreen { border:none !important; padding:0 !important; } *|*:fullscreen::backdrop { position:fixed; top:0; right:0; bottom:0; left:0; background:black; }
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
nested browsing context to go fullscreen,
it needs to be specifically allowed via the allowfullscreen
attribute of the HTML iframe
element. This prevents e.g.
content from third parties to go fullscreen without explicit permission.
Many thanks to Robert O'Callahan for designing the initial model and being awesome.
Thanks to Chris Pearce, Darin Fisher, Edward O'Connor, fantasai, Giuseppe Pascale, Glenn Maynard, Ian Hickson, Ignacio Solla, João Eiras, Josh Soref, Matt Falkenhagen, Mihai Balan, Øyvind Stenhaug, Pat Ladd, Philip Jägenstedt, Rafał Chłodnicki, Rune Lillesveen, Sigbjørn Vik, Simon Pieters, Tab Atkins, and Vincent Scheib for also being awesome.
This standard is written by Anne van Kesteren (Mozilla, [email protected]). Tantek Çelik (Mozilla, [email protected]) sorted out legal hassles.
Per CC0, to the extent possible under law, the editor has waived all copyright and related or neighboring rights to this work.