CSS :fullscreen Pseudo-Class

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The :fullscreen pseudo-class matches an element that is currently in fullscreen mode. Use it to change background, size, or layout only while that element fills the screen.

CSS cannot turn fullscreen on by itself. A user gesture must call element.requestFullscreen() (or native video controls). Then your :fullscreen rules apply automatically.

Limited availability.

Supported in modern Chromium, Firefox, and Safari, but MDN marks it as not fully Baseline across every widely used browser. Prefer feature detection for critical UI.

Legacy prefixes.

Old engines used :-webkit-full-screen and :-moz-full-screen. New code should use standard :fullscreen.

CSS Syntax

syntax.css
:fullscreen { /* styles */ }

Often combined with an element or class: .panel:fullscreen, video:fullscreen.

Selector Forms

:fullscreen is a state selector — it has no property values. Common patterns:

FormDescriptionTry it
:fullscreenAny element currently fullscreenTry it
.panel:fullscreenFullscreen styles for one panel classTry it
video:fullscreenStyle a video while it is fullscreenTry it
:fullscreen::backdropStyle the layer behind the fullscreen elementTry it
exit stylesNormal styles return after exitFullscreen()Try it
keyboard EscapeUsers can leave fullscreen with EscapeTry it

How to Use :fullscreen

Style the fullscreen state, then toggle it with JavaScript on a user click.

  1. Write normal styles for the element.
  2. Add a :fullscreen rule for the fullscreen look.
  3. On a button click, call element.requestFullscreen().
  4. To leave, call document.exitFullscreen() (or let the user press Escape).
  5. Optional: style ::backdrop behind the fullscreen element.
PieceRequired?Role
:fullscreen ruleFor stylingApplies only while the element is fullscreen
requestFullscreen()Yes (to enter)Promotes the element; needs a user gesture
exitFullscreen()OptionalLeaves fullscreen from script (Escape also works)
::backdropNoColors the area behind the fullscreen element

Live Preview

Simulate fullscreen styles in-page, or enter real fullscreen with a click. Real :fullscreen matching needs the Fullscreen API.

Simulation shows the look. Enter fullscreen uses requestFullscreen() so real :fullscreen styles apply.

Preview

Study panel

Styles change when this element is fullscreen.

Normal styles — not fullscreen

CSS Examples

Each snippet focuses on :fullscreen. Try-it demos include a small toggle script so you can enter and exit fullscreen.

Example 1 — Style a Fullscreen Panel

Change background and text when a div goes fullscreen.

CSS
.panel {
  background: #dbeafe;
  color: #1e3a8a;
}

.panel:fullscreen {
  background: #1e3a8a;
  color: #fff;
}
Try It Yourself

How It Works

  1. Style the default. .panel sets the normal look.
  2. Add the state. .panel:fullscreen overrides only in fullscreen.
  3. Enter with JS. A click calls panel.requestFullscreen().
  4. Leave anytime. Escape or exitFullscreen() restores normal styles.

Example 2 — Fullscreen With ::backdrop

Dim the area behind the fullscreen element.

CSS
.panel:fullscreen {
  background: #0f172a;
  color: #f8fafc;
}

.panel:fullscreen::backdrop {
  background: rgba(15, 23, 42, 0.75);
}
Try It Yourself

How It Works

  1. Style the element. :fullscreen changes the panel itself.
  2. Style the layer behind. ::backdrop paints outside that element.
  3. Keep contrast. Light text on a dark panel reads clearly.
  4. Test in a real tab. Backdrop is easiest to see in true fullscreen.

Example 3 — video:fullscreen

Videos often use native fullscreen; CSS still styles that state.

CSS
video {
  max-width: 100%;
  background: #000;
}

video:fullscreen {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
Try It Yourself

How It Works

  1. Target the media. video:fullscreen matches only while the video is fullscreen.
  2. Fill the screen. Width/height and object-fit keep the picture readable.
  3. Use native UI or JS. Either path can put the video into fullscreen.
  4. Keep accessibility. Provide captions and keyboard-friendly controls on the page.

Edge Cases & Pitfalls

Most issues are gesture requirements, iframes, or confusing CSS with the API.

api

CSS cannot enter fullscreen

:fullscreen only styles an element that is already fullscreen via the API or media controls.

gesture

User gesture required

requestFullscreen() must run from a click or similar user action, not from automatic page load.

iframe

Iframes need permission

Embedded frames often need allow="fullscreen" or fullscreen may be blocked.

legacy

Old prefix selectors

:-webkit-full-screen and :-moz-full-screen are legacy. Prefer :fullscreen for new stylesheets.

escape

Users can always exit

Escape leaves fullscreen. Design UI that still makes sense after exit.

Browser Support

:fullscreen is a browser CSS pseudo-class tied to the Fullscreen API. Node.js, Deno, and Bun do not apply it.

✓ Limited availability

:fullscreen

Supported in modern Chrome, Edge, Firefox, Safari, and Opera. Check current MDN compatibility for edge cases.

90% Modern browsers
Google Chrome 71+
Full support
Mozilla Firefox 64+
Full support
Apple Safari 16.4+
Full support
Microsoft Edge 79+
Full support
Opera 58+
Full support
Samsung Internet 10+
Full support
:fullscreen Modern support

Bottom line: Use the standard :fullscreen selector in modern apps. Feature-detect requestFullscreen for critical flows. Not a server runtime API.

Key Takeaways

  • Role: style an element only while it is fullscreen.
  • API: enter with requestFullscreen() on a user gesture.
  • Backdrop: optional ::backdrop for the layer behind.
  • Tip: Escape exits; design for both fullscreen and normal layouts.

One line: :fullscreen styles the fullscreen state; JavaScript (or media UI) enters that state.

Frequently Asked Questions

It matches an element that is currently displayed in fullscreen mode. Use it to change size, color, or layout only while that element fills the screen.
No. Entering fullscreen needs the Fullscreen API (element.requestFullscreen()) or native media controls. CSS only styles the element after it is already fullscreen.
Browsers require a user gesture (like a click). Calls from timers or page load without a gesture are blocked. Some iframes also need allow="fullscreen".
::backdrop styles the layer behind a fullscreen element. Use it to dim or color the area outside the fullscreen content.
Modern browsers support :fullscreen. Very old engines used :-webkit-full-screen or :-moz-full-screen. Prefer the standard selector for new code.
No. It is a browser CSS pseudo-class. Node.js, Deno, and Bun do not apply it.

Next: :has()

Learn how to style a parent based on its descendants.

:has() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful