:fullscreen {
/* ... */
}`:fullscreen` CSS pseudo-class / notebook
`:fullscreen` CSS pseudo-class
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
<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>.element {
background-color: lightyellow;
}
.element:fullscreen {
background-color: lightpink;
}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();
});