LEARNING OBJECTIVES โต
- Utilize the
:fullscreenCSS pseudo-class to style promoted elements conditionally. - Understand and override default User-Agent stylesheet constraints applied to fullscreen elements.
- Scale typography and interface density dynamically using
clamp(),vw/vh, and container queries. - Refactor multi-component layouts (e.g., sidebars, toolbars) when expanding into full-screen viewports.
- Avoid selector invalidation bugs when handling legacy vendor-prefixed pseudo-classes.
๐ The Mental Model & Story (Intuitive Foundation)
Imagine a Swiss Army knife. When folded up in your pocket (standard windowed mode), its tools are condensed, compact, and tucked away to occupy minimal space on a busy desk.
Now imagine pressing a button that instantly unfolds the knife into a full-sized workbench workstation with dual handles, high-intensity LED lamps, and dedicated tool racks.
WINDOWED MODE (Compact Card Layout)
+------------------------------------+
| [ Thumbnail ] Title |
| Short description...|
| [ Expand Button ] |
+------------------------------------+
|
| :fullscreen selector matches!
v
FULLSCREEN MODE (Cinematic Multi-Column Workstation)
+===============================================================================+
| +-------------------------------------+ +--------------------------------+ |
| | | | LIVE CHAT & METADATA | |
| | | | โข Viewer Count: 14,200 | |
| | EXPANDED VIDEO CANVAS | | โข High-DPI Fluid Typography | |
| | (16:9 Letterbox) | | โข Multi-Column Controls | |
| | | | | |
| +-------------------------------------+ +--------------------------------+ |
+===============================================================================+
The :fullscreen pseudo-class acts as the automated transformer for your CSS. Whenever an element is promoted to the Top Layer, the browser dynamically matches :fullscreen on that element, allowing your stylesheet to instantly deploy expanded grids, higher font scales, dark backgrounds, and auto-hiding toolbars without touching JavaScript classes.
Technical Deep Dive & Specifications
The :fullscreen CSS Pseudo-Class Selector
The :fullscreen pseudo-class matches any element currently in the Top Layer via requestFullscreen():
/* Styles applied to the root element when it is fullscreen */
:fullscreen {
background-color: #020617;
color: #f8fafc;
}
/* Styles applied specifically to #mediaPlayer when it is fullscreen */
#mediaPlayer:fullscreen {
width: 100vw;
height: 100vh;
display: grid;
grid-template-columns: 3fr 1fr;
}
/* Styles applied to child elements inside a fullscreen container */
:fullscreen .overlay-controls {
opacity: 1;
font-size: 1.25rem;
}
User-Agent Default Stylesheet Resets
When an element enters fullscreen mode, modern browser engines (Chromium, Gecko, WebKit) automatically apply an internal user-agent stylesheet:
/* Typical Browser User-Agent Stylesheet for :fullscreen */
:fullscreen {
position: fixed !important;
top: 0 !important;
right: 0 !important;
bottom: 0 !important;
left: 0 !important;
box-sizing: border-box !important;
min-width: 0 !important;
max-width: none !important;
min-height: 0 !important;
max-height: none !important;
width: 100% !important;
height: 100% !important;
transform: none !important;
margin: 0 !important;
overflow: auto !important;
}
Why Background Resets Matter:
By default, standard HTML <div> elements have background-color: transparent. If you promote a <div> to fullscreen without explicitly declaring a background color, it will render transparently on top of the black ::backdrop. Always declare an explicit background color when styling :fullscreen:
.card:fullscreen {
background-color: #0f172a; /* Prevents visual artifacts */
}
Fluid Typography with clamp() in Fullscreen
Standard typography sized in fixed pixels (font-size: 16px) appears tiny and unreadable when expanded to a 4K 65-inch television screen or a 32-inch desktop monitor.
Use CSS clamp() combined with viewport units (vw, vh) or Container Query units (cqw) to scale typography seamlessly:
/* Responsive font scaling specifically for fullscreen viewports */
:fullscreen h1 {
font-size: clamp(2rem, 5vw, 4.5rem);
line-height: 1.2;
}
:fullscreen p {
font-size: clamp(1rem, 1.8vw, 1.5rem);
line-height: 1.6;
}
The Vendor Selector Pitfall (Why Comma-Separation Breaks CSS)
Historically, browsers supported vendor-prefixed selectors:
- WebKit / Blink:
:-webkit-full-screen - Gecko (Firefox):
:-moz-full-screen - Trident / IE:
:-ms-fullscreen - Standard:
:fullscreen
[!CAUTION] Never Group Prefixed Pseudo-Classes with Commas!
If a CSS parser encounters an unrecognized selector in a comma-separated list (e.g. Chrome encountering:-moz-full-screen), the CSS specification mandates that the entire rule block must be dropped.
/* โ BROKEN IN ALL BROWSERS: Entire rule gets invalidated! */
:fullscreen,
:-webkit-full-screen,
:-moz-full-screen {
background: black;
}
/* โ
CORRECT: Separate into individual rule blocks (or use modern :fullscreen) */
:fullscreen {
background: black;
}
:-webkit-full-screen {
background: black;
}
:-moz-full-screen {
background: black;
}
(In modern greenfield development targeting modern browsers, standard :fullscreen is supported across 98.5%+ of all global browser traffic).
๐ป Interactive Code Playground
Starter Code
Line-by-Line Code Breakdown
- Line 83โ91 (
.slide-deck:fullscreen): When#slideDeckenters fullscreen mode, its background switches to a radial gradient, padding expands to60px, and standard rounded card borders are removed. - Line 94โ102 (
clamp()): Dynamically scales the heading between2.5remand4.5rembased on5vw, ensuring crisp legibility on 4K projectors without manual media queries. - Line 105โ108 (
grid-template-columns: repeat(4, 1fr)): Reconfigures the 2-column mobile layout into an expanded 4-column widescreen row. - Line 118โ125 (
.fullscreen-toolbar): Changes fromdisplay: nonetodisplay: flex, dynamically revealing presenter notes and an exit button exclusively when fullscreen is active.
Expected Browser Render Output
- In standard view, the slide is rendered as a clean 640px card with 2 columns of metrics.
- Clicking "Present Fullscreen" expands the slide across the entire monitor.
- The layout transforms: text expands cleanly, all four metric cards align horizontally across the bottom, and a presenter notes bar appears at the bottom.
- Pressing
Escapeor clicking "Exit Presentation" instantly collapses the card back into its compact 640px form.
๐๏ธ Hands-On Exercise
๐ฏ The Challenge: Build an Adaptive Fullscreen Presentation Slide Deck
Instructions:
- Create a media container (
#cinemaViewer) containing a video canvas area and a side-panel comment feed. - In windowed mode, layout the video canvas stacked on top of the comment feed.
- Using the
:fullscreenpseudo-class, create a cinematic 2-column widescreen layout (75%video on left,25%live chat sidebar on right). - In fullscreen mode, invert the theme: darken the canvas background, increase font sizes, and add a subtle glowing border around the video area.
๐ Starter Code Sandbox
โ ๏ธ Common Pitfalls
- Omitting an Explicit Background: Forgetting that
divhas a transparent background by default. Without a background color in:fullscreen, your text may render directly over the black backdrop or leak underlying frame colors. - Grouping Legacy Vendor Pseudo-Classes in One Rule: Writing
:fullscreen, :-webkit-full-screen { ... }will cause standard browsers to drop the entire CSS rule. Keep them strictly in separate CSS declarations. - Using Fixed Pixel Sizes: Hardcoding
width: 800px; height: 600pxinside:fullscreenwill cause your element to sit in the top-left corner with massive black letterbox bars on 4K screens.
๐ก Pro Tips
- Leverage Container Queries in Fullscreen: Combine
@container (min-width: 1200px)with:fullscreenso sub-components adapt based on available container dimensions rather than viewport width alone. - Use Custom Properties for Dynamic Theming: Define CSS variables like
--fs-padding: 16pxon:rootand override them to--fs-padding: 48pxunder:fullscreen.
๐ Key Takeaways
- The
:fullscreenpseudo-class targets any element currently promoted to the browser's Top Layer. - Browsers apply fixed positioning and dimension overrides via internal User-Agent stylesheets when elements enter fullscreen.
- Always declare an explicit
background-coloron:fullscreentargets to prevent transparent visual artifacts. - Fluid sizing using
clamp(),vw, andvhensures interfaces scale legibly from smartphones to 4K monitors. - Never combine vendor-prefixed fullscreen selectors in a single comma-separated list.
- --