Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Pseudo-classes

The :fullscreen pseudo-class

Reference for the CSS :fullscreen pseudo-class: style the element shown through the Fullscreen API, with a requestFullscreen example and browser notes.

The :fullscreen pseudo-class matches an element while it is displayed in fullscreen mode, which a script starts with element.requestFullscreen() and the user can leave with Esc. It lets you change the layout, sizing or colours only while the element fills the screen.

Browsers already stretch a fullscreen element to the screen and add a black backdrop. Use :fullscreen to improve on that, for example to centre an image or hide extra chrome.

CSS
.player:fullscreen {
  background: black;
  display: grid;
  place-items: center;
}

Try it

Style the fullscreen state

The preview runs in a sandboxed frame that is usually not allowed to go fullscreen, so you may see the message instead. On your own page, the same code works.

Syntax

CSS
:fullscreen { /* declarations */ }

No arguments; specificity (0,1,0).

Syntax and arguments

Part Description
:fullscreen Matches the element that is currently shown fullscreen (and, for a document, the root).
::backdrop A separate pseudo-element for the layer behind the fullscreen element.
:not(:fullscreen) Matches the normal, non-fullscreen state.

Usage notes

  • Needs a user gesture. requestFullscreen() only succeeds in response to a click, key press or similar. It also needs permission from the embedding page when used in an iframe (allow="fullscreen").
  • The element is moved to the top layer. It escapes overflow, z-index and transforms of its ancestors, so you can't clip it with a parent.
  • Resets size. Browsers apply width: 100%; height: 100% and a black background by default; override them if you want something different.
  • Fullscreen videos. <video> with built-in controls uses its own fullscreen UI. To keep custom controls, request fullscreen on a wrapper element instead and style it with :fullscreen.
  • Older Safari. Older Safari versions used :-webkit-full-screen; current ones support the standard name.

Browser support

Supported in current browsers. Very old Safari versions needed the -webkit- prefix.