๐Ÿ–ฅ๏ธ Chapter 54: The Fullscreen API

Styling Fullscreen with the :fullscreen Pseudo-Class

Master fullscreen CSS styling, User-Agent resets, responsive fluid typography, layout transformations, and selector rules.

LEARNING OBJECTIVES โŒต
  • Utilize the :fullscreen CSS 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.
๐ŸŽฌ INTERACTIVE VISUAL PIPELINE Core Architecture Simulation
๐ŸŒ
1. Input
Directives & Tags
โš™๏ธ
2. Parse
Tokenizer & AST
๐ŸŒณ
3. Layout
Box Model & Flow
๐ŸŽจ
4. Render
GPU Paint & Composite
PHASE 1: INPUT & DIRECTIVES
Browser receives declarative markup stream, parsing tag tokens and initializing component state.

๐Ÿ“– 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 #slideDeck enters fullscreen mode, its background switches to a radial gradient, padding expands to 60px, and standard rounded card borders are removed.
  • Line 94โ€“102 (clamp()): Dynamically scales the heading between 2.5rem and 4.5rem based on 5vw, 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 from display: none to display: flex, dynamically revealing presenter notes and an exit button exclusively when fullscreen is active.

Expected Browser Render Output

  1. In standard view, the slide is rendered as a clean 640px card with 2 columns of metrics.
  2. Clicking "Present Fullscreen" expands the slide across the entire monitor.
  3. The layout transforms: text expands cleanly, all four metric cards align horizontally across the bottom, and a presenter notes bar appears at the bottom.
  4. Pressing Escape or clicking "Exit Presentation" instantly collapses the card back into its compact 640px form.

SYS: ACTIVE
HULL: 98%
CORE: STABLE
NET: ONLINE
HTML STARSHIP CODE TERMINAL playground.html
LIVE RENDER & DIAGNOSTICS CORE TEMP: 45ยฐC
INSPECTING DOM: VALID
TAGS: SCANNING...

๐Ÿ‹๏ธ Hands-On Exercise

๐ŸŽฏ The Challenge: Build an Adaptive Fullscreen Presentation Slide Deck

Instructions:

  1. Create a media container (#cinemaViewer) containing a video canvas area and a side-panel comment feed.
  2. In windowed mode, layout the video canvas stacked on top of the comment feed.
  3. Using the :fullscreen pseudo-class, create a cinematic 2-column widescreen layout (75% video on left, 25% live chat sidebar on right).
  4. 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

SYS: ACTIVE
HULL: 98%
CORE: STABLE
NET: ONLINE
STARTER CODE SANDBOX exercise.html
LIVE RENDER & DIAGNOSTICS CORE TEMP: 45ยฐC
INSPECTING DOM: VALID
TAGS: SCANNING...

โš ๏ธ Common Pitfalls

  1. Omitting an Explicit Background: Forgetting that div has 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.
  2. 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.
  3. Using Fixed Pixel Sizes: Hardcoding width: 800px; height: 600px inside :fullscreen will cause your element to sit in the top-left corner with massive black letterbox bars on 4K screens.

๐Ÿ’ก Pro Tips

  1. Leverage Container Queries in Fullscreen: Combine @container (min-width: 1200px) with :fullscreen so sub-components adapt based on available container dimensions rather than viewport width alone.
  2. Use Custom Properties for Dynamic Theming: Define CSS variables like --fs-padding: 16px on :root and override them to --fs-padding: 48px under :fullscreen.

๐Ÿ“Œ Key Takeaways

  • The :fullscreen pseudo-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-color on :fullscreen targets to prevent transparent visual artifacts.
  • Fluid sizing using clamp(), vw, and vh ensures interfaces scale legibly from smartphones to 4K monitors.
  • Never combine vendor-prefixed fullscreen selectors in a single comma-separated list.
  • --
โญ LEARN: HTML ๐ŸŒŸ โš”๏ธ QUIZ BATTLE ARENA // ACTIVE
3x
STREAK!
BONUS ACTIVE
COMBO
? Question 1 / 3

Why does writing :fullscreen, :-webkit-full-screen { background: red; } fail in modern Firefox or Safari?

Question 1 / 3 Topic: HTML Fundamentals
00:45 REMAINING
XP REWARD
+250 XP
3x
STREAK!
BONUS ACTIVE
COMBO
? Question 2 / 3

What is the default background color of a standard <div> when promoted into fullscreen if no CSS background is declared?

Question 2 / 3 Topic: HTML Fundamentals
00:45 REMAINING
XP REWARD
+250 XP
3x
STREAK!
BONUS ACTIVE
COMBO
? Question 3 / 3

How can you select a specific child button inside an active fullscreen container using CSS?

Question 3 / 3 Topic: HTML Fundamentals
00:45 REMAINING
XP REWARD
+250 XP