--- url: "https://web.dev/articles/fullscreen" titulek: "Making Fullscreen Experiences | Articles | web.dev" h1: "Making Fullscreen Experiences Stay organized with collections Save and categorize content based on your preferences." popis: "Going fullscreen." jazyk: "en" kanonicka: "https://web.dev/articles/fullscreen" drobecky: ["Articles", "Making Fullscreen Experiences"] zdroj: "live" wayback_snapshot: "" stazeno: "2026-09-14 03:31:27" znaku: 17251 slov: 2722 kodovani: "iso-8859-2" sha256: "8be4369325079175a4f2bb84f8a5e75e4f8d52116efb46a1037119f1dcf9a151" --- Making Fullscreen Experiences Stay organized with collections Save and categorize content based on your preferences. We have the ability to easily make immersive fullscreen websites and applications, but like anything on the web there are a couple of ways to do it. This is especially important now that more browsers are supporting an "installed web app" experience which launch fullscreen. Getting your app or site fullscreen There are several ways that a user or developer can get a web app fullscreen. Request the browser go fullscreen in response to a user gesture. Install the app to the home screen. Fake it: auto-hide the address bar. Request the browser go fullscreen in response to a user gesture [Not all platforms are equal](http://caniuse.com/#feat=fullscreen). iOS Safari doesn't have a fullscreen API, but we do on Chrome on Android, Firefox, and IE 11+. Most applications you build will use a combination of the JS API and the CSS selectors provided by the fullscreen specification. The main JS API's that you need to care about when building a fullscreen experience are: `element.requestFullscreen()` (currently prefixed in Chrome, Firefox, and IE) displays the element in fullscreen mode. `document.exitFullscreen()` (currently prefixed in Chrome, Firefox and IE. Firefox uses `cancelFullScreen()` instead) cancels fullscreen mode. `document.fullscreenElement` (currently prefixed in Chrome, Firefox, and IE) returns true if any of the elements are in fullscreen mode. When your app is fullscreen you no longer have the browser's UI controls available to you. This changes the way that users interact with your experience. They don't have the standard navigation controls such as Forwards and Backwards; they don't have their escape hatch that is the Refresh button. It's important to cater for this scenario. You can use some CSS selectors to help you change the style and presentation of your site when the browser enters fullscreen mode. ` ` The above example is a little contrived; I've hidden all the complexity around the use of vendor prefixes. The actual code is a lot more complex. [Mozilla has created](https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Using_full_screen_mode) a very useful script that you can use to toggle fullscreen. As you can see, the vendor prefix situation it is complex and cumbersome compared to the specified API. Even with the slightly simplified code below, it is still complex. `function toggleFullScreen() { var doc = window.document; var docEl = doc.documentElement; var requestFullScreen = docEl.requestFullscreen || docEl.mozRequestFullScreen || docEl.webkitRequestFullScreen || docEl.msRequestFullscreen; var cancelFullScreen = doc.exitFullscreen || doc.mozCancelFullScreen || doc.webkitExitFullscreen || doc.msExitFullscreen; if ( !doc.fullscreenElement && !doc.mozFullScreenElement && !doc.webkitFullscreenElement && !doc.msFullscreenElement ) { requestFullScreen.call(docEl); } else { cancelFullScreen.call(doc); } }` We web developers hate complexity. A nice high-level abstract API you can use is Sindre Sorhus' [Screenfull.js](https://github.com/sindresorhus/screenfull.js) module which unifies the two slightly different JS API's and vendor prefixes into one consistent API. Fullscreen API Tips Making the document fullscreen Figure 1: Fullscreen on the body element. It is natural to think that you take the body element fullscreen, but if you are on a WebKit or Blink based rendering engine you will see it has an odd effect of shrinking the body width to the smallest possible size that will contain all the content. (Mozilla Gecko is fine.) Figure 2: Fullscreen on the document element. To fix this, use the document element instead of the body element: `document.documentElement.requestFullscreen();` Making a video element fullscreen To make a video element fullscreen is exactly the same as making any other element fullscreen. You call the `requestFullscreen` method on the video element. ` ` If your `