`:fullscreen` CSS pseudo-class
Baseline Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
The :fullscreen CSS pseudo-class matches every element that is currently in fullscreen mode. If multiple elements have been put into fullscreen mode, this selects them all.
Syntax
:fullscreen {
/* ... */
}
Usage notes
The :fullscreen pseudo-class lets you configure your stylesheets to automatically adjust the size, style, or layout of content when elements switch back and forth between fullscreen and traditional presentations.
Examples
Styling a fullscreen element
This example applies a different background color to a <div> element, depending on whether or not it is in fullscreen mode. It includes a <button> to toggle fullscreen on and off.
<div class="element">
<h1><code>:fullscreen</code> pseudo-class demo</h1>
<p>
This demo uses the <code>:fullscreen</code> pseudo-class to automatically
change the background color of the <code>.element</code> div.
</p>
<p>
Normally, the background is light yellow. In fullscreen mode, the background
is light pink.
</p>
<button class="toggle">Toggle Fullscreen</button>
</div>
The :fullscreen pseudo-class is used to override the background-color of the <div> when it is in fullscreen mode.
.element {
background-color: lightyellow;
}
.element:fullscreen {
background-color: lightpink;
}
The following JavaScript provides an event handler function that toggles fullscreen when the <button> is clicked.
document.querySelector(".toggle").addEventListener("click", (event) => {
if (document.fullscreenElement) {
// If there is a fullscreen element, exit full screen.
document.exitFullscreen();
return;
}
// Make the .element div fullscreen.
document.querySelector(".element").requestFullscreen();
});
.element {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-family: sans-serif;
padding: 1.2em;
}
Specifications
Browser compatibility
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on iOS | Samsung Internet | WebView Android | WebView on iOS | |
fullscreen |
71
15
|
12 |
64
9
|
58
15
|
16.4
6
|
71
18
|
64
9
|
50
14
|
16.4Only 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. |
10.0
1.0
|
71
37
|
16.4Only 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. |
all_elements |
No |
12–79 |
43 |
No |
No |
No |
43 |
No |
No |
No |
No |
No |
See also
::backdrop:xr-overlay- CSS selectors module
- Guide to the Fullscreen API
- Fullscreen API
- DOM API:
Element.requestFullscreen(),Document.exitFullscreen(),Document.fullscreenElement -
allowfullscreenattribute
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Selectors/:fullscreen