This feature is not Baseline because it does not work in some of the most widely-used browsers.
The Element.requestFullscreen() method issues an asynchronous request to make the element be displayed in fullscreen mode.
It's not guaranteed that the element will be put into full screen mode. If permission to enter full screen mode is granted, the returned Promise will resolve and the element will receive a fullscreenchange event to let it know that it's now in full screen mode. If permission is denied, the promise is rejected and the element receives a fullscreenerror event instead. If the element has been detached from the original document, then the document receives these events instead.
requestFullscreen() requestFullscreen(options)
options OptionalAn object that controls the behavior of the transition to fullscreen mode. The available options are:
Controls whether or not to show navigation UI while the element is in fullscreen mode. The default value is "auto", which indicates that the browser should decide what to do.
"hide"The browser's navigation interface will be hidden and the entire dimensions of the screen will be allocated to the display of the element.
"show"The browser will present page navigation controls and possibly other user interface; the dimensions of the element (and the perceived size of the screen) will be clamped to leave room for this user interface.
"auto"The browser will choose which of the above settings to apply. This is the default value.
screen Optional Experimental Specifies on which screen you want to put the element in fullscreen mode. This takes a ScreenDetailed object as a value, representing the chosen screen.
A Promise which is resolved with a value of undefined when the transition to full screen is complete.
Rather than throw a traditional exception, the requestFullscreen() procedure announces error conditions by rejecting the Promise it has returned. The rejection handler receives one of the following exception values:
TypeErrorThe TypeError exception may be delivered in any of the following situations:
fullscreen feature, either because of Permissions Policy configuration or other access control features.HTMLElement.showPopover().Transient user activation is required. The user has to interact with the page or a UI element in order for this feature to work.
An element that you wish to place into fullscreen mode has to meet a small number of simple requirements:
<svg> or <math>.<dialog> element.<iframe> which has the allowfullscreen attribute applied to it.Additionally, any set Permissions Policies must allow the use of this feature.
You can determine whether or not your attempt to switch to fullscreen mode is successful by using the Promise returned by requestFullscreen(), as seen in the examples below.
To learn when other code has toggled fullscreen mode on and off, you should establish listeners for the fullscreenchange event on the Document. It's also important to listen for fullscreenchange to be aware when, for example, the user manually toggles fullscreen mode, or when the user switches applications, causing your application to temporarily exit fullscreen mode.
This example toggles the <video> element in and out of fullscreen mode when the Enter or Shift + F keys are pressed. The script checks whether the document is currently in fullscreen using document.fullscreenElement. If the document is in fullscreen, it calls document.exitFullscreen() to exit. Otherwise, it calls requestFullscreen() on the <video> element:
const video = document.querySelector("video");
document.addEventListener("keydown", (event) => {
// Note that "F" is case-sensitive (uppercase):
if (event.key === "Enter" || event.key === "F") {
// Check if we're in fullscreen mode
if (document.fullscreenElement) {
document.exitFullscreen();
return;
}
// Otherwise enter fullscreen mode
video.requestFullscreen().catch((err) => {
console.error(`Error enabling fullscreen: ${err.message}`);
});
}
});
<p>
The video element below shows a time-lapse of a flower blooming. You can
toggle fullscreen on and off using <kbd>Enter</kbd> or <kbd>Shift</kbd> +
<kbd>F</kbd> (uppercase "F"). The embedded document needs to have
<a
href="https://developer.mozilla.org/en-US/docs/Web/API/Element/focus_event">
focus
</a>
for the example to work.
</p>
<video controls loop src="/shared-assets/videos/flower.mp4" width="420"></video>
In this example, the entire document is placed into fullscreen mode by calling requestFullscreen() on the document's Document.documentElement, which is the document's root <html> element.
let elem = document.documentElement;
elem
.requestFullscreen({ navigationUI: "show" })
.then(() => {})
.catch((err) => {
alert(
`An error occurred while trying to switch into fullscreen mode: ${err.message} (${err.name})`,
);
});
The promise's resolve handler does nothing, but if the promise is rejected, an error message is displayed by calling alert().
If you wanted to make the element fullscreen on the primary OS screen, you could use code like the following:
try {
const primaryScreen = (await getScreenDetails()).screens.find(
(screen) => screen.isPrimary,
);
await document.body.requestFullscreen({ screen: primaryScreen });
} catch (err) {
console.error(err.name, err.message);
}
The Window.getScreenDetails() method is used to retrieve the ScreenDetails object for the current device, which contains ScreenDetailed objects representing the different available screens.
| Specification |
|---|
| Fullscreen API> # ref-for-dom-element-requestfullscreen①> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
requestFullscreen |
7115 | 791212–14 | 649Before Firefox 44, Firefox incorrectly allowed elements inside a<frame> or <object> element to request, and to be granted, fullscreen. In Firefox 44 and onwards this has been fixed: only elements in the top-level document or in an <iframe> element with the allowfullscreen attribute can be displayed fullscreen. |
581512.1–15 | 16.45.1 | 7118 | 649Before Firefox for Android 44, Firefox for Android incorrectly allowed elements inside a<frame> or <object> element to request, and to be granted, fullscreen. In Firefox for Android 44 and onwards this has been fixed: only elements in the top-level document or in an <iframe> element with the allowfullscreen attribute can be displayed fullscreen. |
501412.1–14 |
16.4["Only available on iPad, not on iPhone.", "Shows an overlay button which can not be disabled. Swiping down exits fullscreen mode, making it unsuitable for some use cases like games."]12Only available on iPad, not on iPhone. Shows an overlay button which can not be disabled. |
10.01.0 | 714.4 | No |
options_navigationUI_parameter |
71 | 79 | No | 58 | 16.4 | 71 | No | 50 | No | 10.0 | 71 | No |
options_screen_parameter |
100 | 100 | No | 86 | No | No | No | No | No | No | No | No |
returns_promise |
71 | 79 | 64 | 58 | 16.4 | 71 | 64 | 50 | 16.4 | 10.0 | 71 | No |
Document.exitFullscreen()Document.fullscreenDocument.fullscreenElement:fullscreenallowfullscreen
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Element/requestFullscreen