Fullscreen API

Living Standard — Last Updated

Participate:
GitHub whatwg/fullscreen(new issue,open issues)
Chat on Matrix
Commits:
GitHub whatwg/fullscreen/commits
Snapshot as of this commit
@fullscreenapi
Tests:
web-platform-tests fullscreen/(ongoing work)
Translations(non-normative):
Nhật bổn ngữ
Giản thể trung văn

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

Allelementshave an associatedfullscreen flag.Unless stated otherwise it is unset.

Alliframeelementshave an associatediframe fullscreen flag.Unless stated otherwise it is unset.

Alldocumentshave an associatedfullscreen element.Thefullscreen elementis the topmostelementin thedocument’stop layerwhosefullscreen flagis set, if any, and null otherwise.

Alldocumentshave an associatedlist of pending fullscreen events,which is anordered setof (string,element)tuples.It is initially empty.

Tofullscreen anelement:

  1. LethideUntilbe the result of runningtopmost popover ancestorgivenelement,null, and false.

  2. IfhideUntilis null, then sethideUntiltoelement’snode document.

  3. Runhide all popovers untilgivenhideUntil,false, and true.

  4. Setelement’sfullscreen flag.

  5. Remove from the top layer immediatelygivenelement.

  6. Add to the top layergivenelement.

Tounfullscreen anelement,unsetelement’sfullscreen flagandiframe fullscreen flag(if any), andremove from the top layer immediatelygivenelement.

Tounfullscreen adocument,unfullscreenallelements,withindocument’stop layer,whosefullscreen flagis set.


Tofully exit fullscreenadocumentdocument,run these steps:

  1. Ifdocument’sfullscreen elementis null, terminate these steps.

  2. Unfullscreen elementswhosefullscreen flagis set, withindocument’stop layer,except fordocument’sfullscreen element.

  3. Exit fullscreendocument.

Whenever theremoving stepsrun with aremovedNode,run these steps:

  1. LetdocumentberemovedNode’snode document.

  2. LetnodesberemovedNode’sshadow-including inclusive descendantsthat have theirfullscreen flagset, inshadow-including tree order.

  3. For eachnodeinnodes:

    1. Ifnodeisdocument’sfullscreen element,exit fullscreendocument.

    2. Otherwise,unfullscreennode.

    3. Ifdocument’stop layercontainsnode,remove from the top layer immediatelygivennode.

      Other specifications can add and remove elements fromtop layer,sonodemight not bedocument’sfullscreen element.For example,nodecould be an opendialogelement.

Whenever theunloading document cleanup stepsrun with adocument,fully exit fullscreendocument.


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


Torun the fullscreen stepsfor adocumentdocument,run these steps:

  1. LetpendingEventsbedocument’slist of pending fullscreen events.

  2. Emptydocument’slist of pending fullscreen events.

  3. For each(type,element) inpendingEvents:

    1. Lettargetbeelementifelementisconnectedand itsnode documentisdocument,and otherwise lettargetbedocument.

    2. Fire an eventnamedtype,with itsbubblesandcomposedattributes set to true, attarget.

These steps integrate with theevent loopdefined in HTML.[HTML]

3.API

enumFullscreenNavigationUI{
"auto",
"show",
"hide"
};

dictionaryFullscreenOptions{
FullscreenNavigationUInavigationUI= "auto";
};

partialinterfaceElement{
Promise<undefined>requestFullscreen(optionalFullscreenOptionsoptions= {});

attributeEventHandleronfullscreenchange;
attributeEventHandleronfullscreenerror;
};

partialinterfaceDocument{
[LegacyLenientSetter]readonlyattributebooleanfullscreenEnabled;
[LegacyLenientSetter,Unscopable]readonlyattributebooleanfullscreen;// historical

Promise<undefined>exitFullscreen();

attributeEventHandleronfullscreenchange;
attributeEventHandleronfullscreenerror;
};

partialinterfacemixinDocumentOrShadowRoot{
[LegacyLenientSetter]readonlyattributeElement?fullscreenElement;
};
promise=element.requestFullscreen([options])
Displayselementfullscreen and resolvespromisewhen done.

When supplied,options’snavigationUImember 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 ifdocumenthas the ability to displayelementsfullscreen andfullscreen is supported,or false otherwise.

promise=document.exitFullscreen()

Stopsdocument’sfullscreen elementfrom being displayed fullscreen and resolvespromisewhen done.

document.fullscreenElement

Returnsdocument’sfullscreen element.

shadowroot.fullscreenElement

Returnsshadowroot’sfullscreen element.

Afullscreen element ready checkfor anelementelementreturns true if all of the following are true, and false otherwise:

TherequestFullscreen(options)method steps are:

  1. LetpendingDocbethis’snode document.

  2. Letpromisebe a new promise.

  3. IfpendingDocis notfully active,then rejectpromisewith aTypeErrorexception and returnpromise.

  4. Leterrorbe false.

  5. If any of the following conditions are false, then seterrorto true:

  6. Iferroris false, thenconsume user activationgivenpendingDoc’srelevant global object.

  7. Returnpromise,and run the remaining stepsin parallel.

  8. Iferroris false, then resizependingDoc’snode navigable’stop-level traversable’sactive document’s viewport’s dimensions, optionally taking into accountoptions[ "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 seterrorto true:

  10. Iferroris true:

    1. Append(fullscreenerror,this) topendingDoc’slist of pending fullscreen events.

    2. Rejectpromisewith aTypeErrorexception and terminate these steps.

  11. LetfullscreenElementsbe anordered setinitially consisting ofthis.

  12. While true:

    1. Letlastbe the lastitemoffullscreenElements.

    2. Letcontainerbelast’snode navigable’scontainer.

    3. Ifcontaineris null, thenbreak.

    4. AppendcontainertofullscreenElements.

  13. For eachelementinfullscreenElements:

    1. Letdocbeelement’snode document.

    2. Ifelementisdoc’sfullscreen element,continue.

      No need to notify observers when nothing has changed.

    3. Ifelementisthisandthisis aniframeelement,then setelement’siframe fullscreen flag.

    4. Fullscreenelementwithindoc.

    5. Append(fullscreenchange,element) todoc’slist of pending fullscreen events.

    The order in which elements arefullscreenedis not observable, becauserun the fullscreen stepsis invoked intree order.

  14. Resolvepromisewith undefined.

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

ThefullscreenEnabledgetter steps are to return true ifthisisallowed to usethe "fullscreen"feature andfullscreen is supported,and false otherwise.

Thefullscreengetter steps are to return false ifthis’sfullscreen elementis null, and true otherwise.

Use thefullscreenElementattribute instead.

ThefullscreenElementgetter steps are:

  1. Ifthisis ashadow rootand itshostis notconnected,then return null.

  2. Letcandidatebe the result ofretargetingfullscreen elementagainstthis.

  3. Ifcandidateandthisare in the sametree,then returncandidate.

  4. Return null.

Adocumentis said to be asimple fullscreen documentif there is exactly oneelementin itstop layerthat has itsfullscreen flagset.

Adocumentwith twoelementsin itstop layercan be asimple fullscreen document.For example, in addition to thefullscreen elementthere could be an opendialogelement.

Tocollect documents to unfullscreengivendoc,run these steps:

  1. Letdocsbe anordered setconsisting ofdoc.

  2. Whiletrue:

    1. LetlastDocbedocs’s lastdocument.

    2. Assert:lastDoc’sfullscreen elementis not null.

    3. IflastDocis not asimple fullscreen document,break.

    4. LetcontainerbelastDoc’snode navigable’scontainer.

    5. Ifcontaineris null, thenbreak.

    6. Ifcontainer’siframe fullscreen flagis set,break.

    7. Appendcontainer’snode documenttodocs.

  3. Returndocs.

    This is the set of documents for which thefullscreen elementwill beunfullscreened,but the last document indocsmight have more than oneelementin itstop layerwith thefullscreen flagset, in which case that document will still remain in fullscreen.

Toexit fullscreenadocumentdoc,run these steps:

  1. Letpromisebe a new promise.

  2. Ifdocis notfully activeordoc’sfullscreen elementis null, then rejectpromisewith aTypeErrorexception and returnpromise.

  3. Letresizebe false.

  4. Letdocsbe the result ofcollecting documents to unfullscreengivendoc.

  5. LettopLevelDocbedoc’snode navigable’stop-level traversable’sactive document.

  6. IftopLevelDocis indocs,and it is asimple fullscreen document,then setdoctotopLevelDocandresizeto true.

  7. Ifdoc’sfullscreen elementis notconnected:

    1. Append(fullscreenchange,doc’sfullscreen element) todoc’slist of pending fullscreen events.

  8. Returnpromise,and run the remaining stepsin parallel.

  9. Run thefully unlock the screen orientation stepswithdoc.

  10. Ifresizeis true, resizedoc’s viewport to its "normal" dimensions.

  11. Ifdoc’sfullscreen elementis null, then resolvepromisewith undefined and terminate these steps.

  12. LetexitDocsbe the result ofcollecting documents to unfullscreengivendoc.

  13. LetdescendantDocsbe anordered setconsisting ofdoc’sdescendant navigables'active documentswhosefullscreen elementis non-null, if any, intree order.

  14. For eachexitDocinexitDocs:

    1. Append(fullscreenchange,exitDoc’sfullscreen element) toexitDoc’slist of pending fullscreen events.

    2. Ifresizeis true,unfullscreenexitDoc.

    3. Otherwise,unfullscreenexitDoc’sfullscreen element.

  15. For eachdescendantDocindescendantDocs:

    1. Append(fullscreenchange,descendantDoc’sfullscreen element) todescendantDoc’slist of pending fullscreen events.

    2. UnfullscreendescendantDoc.

    The order in which documents areunfullscreenedis not observable, becauserun the fullscreen stepsis invoked intree order.

  16. Resolvepromisewith undefined.

TheexitFullscreen()method steps are to return the result of runningexit fullscreenonthis.


The following are theevent handlers(and their correspondingevent handler event types) that must be supported byElementandDocumentobjects asevent handler IDL attributes:

event handler event handler event type
onfullscreenchange fullscreenchange
onfullscreenerror fullscreenerror

These are not supported byShadowRootorWindowobjects, and there are no correspondingevent handler content attributesforElementobjects in any namespace.

4.UI

User agents are encouraged to implement native media fullscreen controls in terms ofrequestFullscreen()andexitFullscreen().

If the end user instructs the user agent to end a fullscreen session initiated viarequestFullscreen(),fully exit fullscreengiven thetop-level traversable’sactive document.

The user agent may end any fullscreen session without instruction from the end user or call toexitFullscreen()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.:fullscreenpseudo-class

The:fullscreenpseudo-class must match anyelementelementfor which one of the following conditions is true:

This makes it different from thefullscreenElementAPI, which returns the topmostfullscreen 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 apolicy-controlled featureidentified by the string "fullscreen".Itsdefault allowlistis'self'.

Adocument’spermissions policydetermines whether any content in that document is allowed to go fullscreen. If disabled in any document, no content in the document will beallowed to usefullscreen.

Theallowfullscreenattribute of the HTMLiframeelement affects thecontainer policyfor any document nested in that iframe. Unless overridden by theallowattribute, settingallowfullscreenon an iframe is equivalent to<iframe allow= "fullscreen *" >,as described inPermissions 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 ofrequestFullscreen().

To enable content in achild navigableto go fullscreen, it needs to be specifically allowed via permissions policy, either through theallowfullscreenattribute of the HTMLiframeelement, or an appropriate declaration in theallowattribute of the HTMLiframeelement, or through a `Permissions-Policy` HTTP header delivered with thedocumentthrough 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::backdropand the concept of the document’stop 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 byPhilip Jägenstedt(Google,[email protected]). It was originally written byAnne 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 aCreative 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 theBSD 3-Clause Licenseinstead.

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

Index

Terms defined by this specification

Terms defined by reference

References

Normative References

[CSS]
Bert Bos; et al.Cascading Style Sheets Level 2 Revision 1 (CSS 2.1) Specification.URL:https://drafts.csswg.org/css2/
[CSS-POSITION-4]
CSS Positioned Layout Module Level 4.Editor's Draft. URL: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.HTML Standard.Living Standard. URL: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.Mathematical Markup Language (MathML™) 1.01 Specification.7 March 2023. REC. URL:https://www.w3.org/TR/REC-MathML/
[PERMISSIONS-POLICY-1]
Ian Clelland.Permissions Policy.URL:https://w3c.github.io/webappsec-permissions-policy/
[SCREEN-ORIENTATION]
Marcos Caceres.Screen Orientation.URL:https://w3c.github.io/screen-orientation/
[SVG]
Erik Dahlström; et al.Scalable Vector Graphics (SVG) 1.1 (Second Edition).16 August 2011. REC. URL:https://www.w3.org/TR/SVG11/
[WEBIDL]
Edgar Chen; Timothy Gu.Web IDL Standard.Living Standard. URL:https://webidl.spec.whatwg.org/

IDL Index

enumFullscreenNavigationUI{
"auto",
"show",
"hide"
};

dictionaryFullscreenOptions{
FullscreenNavigationUInavigationUI= "auto";
};

partialinterfaceElement{
Promise<undefined>requestFullscreen(optionalFullscreenOptionsoptions= {});

attributeEventHandleronfullscreenchange;
attributeEventHandleronfullscreenerror;
};

partialinterfaceDocument{
[LegacyLenientSetter]readonlyattributebooleanfullscreenEnabled;
[LegacyLenientSetter,Unscopable]readonlyattributebooleanfullscreen;// historical

Promise<undefined>exitFullscreen();

attributeEventHandleronfullscreenchange;
attributeEventHandleronfullscreenerror;
};

partialinterfacemixinDocumentOrShadowRoot{
[LegacyLenientSetter]readonlyattributeElement?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

Headers/Feature-Policy/fullscreen

In only one current engine.

FirefoxNoneSafariNoneChrome62+
Opera?Edge79+
Edge (Legacy)?IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?

Headers/Permissions-Policy/fullscreen

In only one current engine.

FirefoxNoneSafariNoneChrome88+
Opera?Edge88+
Edge (Legacy)?IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?