CSS :fullscreen Selector

Beginner
⏱️ 7 min read
📚 Updated: Jul 2026
🎯 4 Examples
Media & Display

What You’ll Learn

The :fullscreen pseudo-class styles elements when they occupy the entire screen through the Fullscreen API or native media controls.

01

Fullscreen

Full viewport.

02

API

requestFullscreen.

03

Video

Media players.

04

vw / vh

Flexible units.

05

::backdrop

Dim background.

06

Immersive

Rich experiences.

Introduction

The :fullscreen selector in CSS is used to style elements when they are in fullscreen mode.

This pseudo-class becomes active when an element is displayed using the Fullscreen API, typically triggered by the user clicking a button or through JavaScript.

It is a useful tool for enhancing the visual experience when elements are displayed fullscreen — such as videos, image galleries, presentations, or interactive sections of a webpage.

Definition and Usage

Append :fullscreen to a selector with no space before the colon: :fullscreen, video:fullscreen, or div:fullscreen. Styles apply only while the element is in fullscreen and revert when the user exits (usually by pressing Esc).

💡
Beginner Tip

CSS cannot enter fullscreen by itself. You need JavaScript element.requestFullscreen() or the browser’s native video fullscreen button. The :fullscreen selector only styles the element once it is already fullscreen.

📝 Syntax

The syntax for the :fullscreen pseudo-class is:

syntax.css
:fullscreen {
  /* CSS properties */
}

Basic Example

fullscreen-basic.css
/* Default styling */
#player {
  width: 300px;
  height: 200px;
  background: #93c5fd;
}

/* When in fullscreen mode */
:fullscreen {
  width: 100vw;
  height: 100vh;
  background: #1e3a8a;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
}
:fullscreen video:fullscreen div:fullscreen ::backdrop

JavaScript Trigger

requestFullscreen.js
const el = document.getElementById('player');

// Enter fullscreen (modern browsers)
el.requestFullscreen();

// Exit fullscreen
document.exitFullscreen();

Syntax Rules

  • Only matches elements currently in fullscreen mode.
  • Combine with element types: video:fullscreen, div:fullscreen.
  • Use vw and vh to fill the viewport reliably.
  • Pair with ::backdrop to style the area behind the element.
  • Listen for the fullscreenchange event to update UI state in JavaScript.

Related Selectors & APIs

  • ::backdrop — styles the backdrop layer behind a fullscreen element
  • :focus — style the button that triggers fullscreen
  • :hover — preview hover state on the fullscreen toggle
  • document.fullscreenElement — JavaScript property for the active fullscreen element

⚡ Quick Reference

QuestionAnswer
Selector typePseudo-class
When it appliesElement is in fullscreen mode
How to enter fullscreenelement.requestFullscreen() or native video controls
How to exitPress Esc or call document.exitFullscreen()
Common propertieswidth, height, background, display: flex
Browser supportAll modern browsers (vendor prefixes for legacy)

When to Use :fullscreen

:fullscreen helps create immersive, fullscreen experiences:

  • Video players — Enlarge background, hide chrome, center content when a video goes fullscreen.
  • Image galleries — Expand a photo to fill the screen with custom styling.
  • Presentations & slides — Style slide containers for kiosk or demo mode.
  • Games & interactive apps — Adapt layout when a canvas or game container enters fullscreen.
  • Reading mode — Expand an article section for distraction-free reading.

👀 Live Preview

Click the button below to enter fullscreen on the demo box. Press Esc to exit and see styles revert:

Click Enter Fullscreen

The box turns dark blue and fills the screen when fullscreen is active.

Examples Gallery

Practice :fullscreen with divs, videos, flexible viewport units, and backdrop styling.

📜 Core Patterns

Style elements when they enter fullscreen mode via JavaScript.

Example 1 — Div with requestFullscreen()

A clickable button promotes a div to fullscreen and applies custom styles with :fullscreen.

fullscreen-div.html
<style>
  #fullscreen-element {
    width: 300px;
    height: 200px;
    background: #93c5fd;
    text-align: center;
    line-height: 200px;
  }

  :fullscreen {
    width: 100vw;
    height: 100vh;
    background: #1e3a8a;
    color: #fff;
    font-size: 2em;
    line-height: normal;
    display: flex;
    align-items: center;
    justify-content: center;
  }
</style>

<div id="fullscreen-element">Click to Go Fullscreen</div>
<button id="fullscreen-btn">Enter Fullscreen</button>

<script>
  const el = document.getElementById('fullscreen-element');
  document.getElementById('fullscreen-btn').addEventListener('click', () => {
    el.requestFullscreen();
  });
</script>
Try It Yourself

How It Works

When the user clicks the button, JavaScript calls requestFullscreen(). The browser promotes the div to fullscreen, and the :fullscreen rules expand it to fill the viewport with a new color scheme.

Example 2 — Video fullscreen styling

Target a video element specifically with video:fullscreen for media players.

video-fullscreen.css
video {
  width: 100%;
  max-width: 640px;
  border-radius: 0.5rem;
}

video:fullscreen {
  max-width: none;
  width: 100vw;
  height: 100vh;
  object-fit: contain;
  background: #000;
  border-radius: 0;
}
Try It Yourself

How It Works

Videos can enter fullscreen via native browser controls. video:fullscreen ensures the video scales properly with object-fit: contain and a black background for letterboxing.

📄 Layout & Backdrop

Center content and style the backdrop layer behind fullscreen elements.

Example 3 — Centered fullscreen content with flexbox

Use flexbox inside :fullscreen to center text, images, or controls on large screens.

fullscreen-flex.css
.slide:fullscreen {
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e3a8a, #312e81);
  color: #fff;
  font-size: clamp(1.5rem, 4vw, 3rem);
}
Try It Yourself

How It Works

Flexbox with align-items and justify-content centers content regardless of screen size. clamp() keeps text readable on both small and large displays.

Example 4 — Styling the ::backdrop

Dim or color the area behind a fullscreen element using the ::backdrop pseudo-element.

fullscreen-backdrop.css
#gallery:fullscreen {
  background: #fff;
  padding: 2rem;
}

#gallery:fullscreen::backdrop {
  background: rgba(15, 23, 42, 0.9);
}
Try It Yourself

How It Works

The ::backdrop pseudo-element covers everything behind the fullscreen element. A semi-transparent dark backdrop creates a modal-like, focused viewing experience.

💬 Usage Tips

  • Combine :fullscreen with specific elements (video:fullscreen, div:fullscreen) for precise targeting.
  • Use flexible units like vw and vh so designs adapt to any screen size in fullscreen.
  • Provide a visible button to enter and exit fullscreen — do not rely on hidden gestures alone.
  • Listen for fullscreenchange to toggle icons (expand/compress) in your UI.
  • Test on mobile — some browsers handle fullscreen differently on iOS Safari.

⚠️ Common Pitfalls

  • Requires Fullscreen API:fullscreen only works after requestFullscreen() or native media controls — CSS alone cannot trigger it.
  • Element limitations — Not all elements support fullscreen in every browser (e.g., some iframe restrictions).
  • Vendor prefixes — Older browsers used :-webkit-full-screen and :-moz-full-screen; modern browsers support standard :fullscreen.
  • Forgetting exit path — Always let users exit with Esc or an explicit exit button.
  • Fixed positioning confusionposition: fixed is not the same as fullscreen; only the Fullscreen API triggers :fullscreen.

🧠 How :fullscreen Works

1

User triggers fullscreen

Click a button or use native video controls. JavaScript calls requestFullscreen().

Trigger
2

Browser promotes element

The element expands to fill the screen. The browser fires a fullscreenchange event.

Promote
3

:fullscreen styles apply

CSS rules for :fullscreen and ::backdrop take effect.

Style
=

Immersive experience

Content fills the screen with your custom fullscreen design.

🖥 Browser Compatibility

The standard :fullscreen pseudo-class is supported in all modern browsers. Legacy browsers used vendor-prefixed variants.

Baseline · Modern browsers

Fullscreen styling everywhere

:fullscreen works in Chrome, Firefox, Safari, Edge, and Opera. Use vendor prefixes only if you must support very old browsers.

96% Modern support
Google Chrome 71+ · Standard :fullscreen
Full support
Mozilla Firefox 64+ · Standard :fullscreen
Full support
Apple Safari 16.4+ · Standard :fullscreen
Full support
Microsoft Edge 79+ · Standard :fullscreen
Full support
Opera 58+ · Standard :fullscreen
Full support
:fullscreen pseudo-class 96% supported

Bottom line: Use standard :fullscreen for all current projects. Add :-webkit-full-screen only if you need legacy Safari support.

🎉 Conclusion

The :fullscreen selector is a powerful way to adapt your design to fullscreen mode. By applying custom styles when elements enter fullscreen, you can create immersive user experiences for media-rich content like videos, games, galleries, and interactive websites.

Pair it with the Fullscreen API, flexible viewport units, and ::backdrop styling to deliver polished, professional fullscreen interfaces.

💡 Best Practices

✅ Do

  • Use vw and vh for fullscreen layouts
  • Provide clear enter/exit fullscreen controls
  • Style ::backdrop for a polished look
  • Listen for fullscreenchange events
  • Test keyboard exit with Esc

❌ Don’t

  • Expect CSS alone to enter fullscreen
  • Trap users without an exit path
  • Assume all elements support fullscreen
  • Confuse fullscreen with position: fixed
  • Forget mobile browser differences

Key Takeaways

Knowledge Unlocked

Five things to remember about :fullscreen

Use these points when building immersive fullscreen experiences.

5
Core concepts
JS 02

Fullscreen API

JS required.

Trigger
vw 03

Viewport units

100vw / 100vh.

Layout
:: 04

::backdrop

Dim background.

Polish
🌐 05

96% support

Modern browsers.

Compat

❓ Frequently Asked Questions

The :fullscreen pseudo-class matches an element that is currently displayed in fullscreen mode — filling the entire screen — after being promoted via the Fullscreen API or native browser controls.
JavaScript calls element.requestFullscreen() (or vendor-prefixed variants). Users can also trigger fullscreen on videos through the browser's native video controls.
The CSS selector only applies when an element is in fullscreen. Entering fullscreen requires the Fullscreen API or native media controls — CSS alone cannot toggle fullscreen.
::backdrop is a pseudo-element that styles the layer behind a fullscreen element. Use it to dim or color the area outside the fullscreen content.
All modern browsers support the standard :fullscreen pseudo-class. Older browsers used vendor prefixes like :-webkit-full-screen and :-moz-full-screen.

Practice in the Live Editor

Open the HTML editor and experiment with :fullscreen, the Fullscreen API, and backdrop styling.

HTML Editor →

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