Back to Blog

Interactive Field Guide // Web Standards

Modern Web Guidance
HTML and CSS

Build fast, accessible websites with native browser features instead of legacy JavaScript workarounds. See what dialogs, popovers, container queries, anchor positioning and modern colour can replace, check which browsers support each one today, and try them live on this page.

Guided Corpus 200+ Expert-vetted guides across HTML, CSS, JS, accessibility and performance
Widely Available Rule 30 mo Time after a feature reaches every core browser before it counts as Widely Available
Core Browser Matrix 4 Browsers Chrome, Edge, Firefox and Safari on desktop and mobile, running on 3 engines (Blink, Gecko, WebKit)
CWV Passing Threshold 75th % Real-user visits meeting LCP (≤2.5s), INP (≤200ms) and CLS (≤0.1)
01 // Core Concepts & Governance

Why coding agents need Modern Web Guidance

AI coding tools write syntax rapidly, yet they regularly generate outdated JavaScript libraries, unnecessary polyfills and fragile layout hacks. Modern Web Guidance corrects that training bias by injecting living browser standards directly into the development workflow.

The Problem // LLM Training Bias

Historical repositories skew toward legacy abstractions

Large language models learn from billions of lines of older public code. Without targeted context, an agent asked to build a modal dialog, a floating tooltip or an accordion will reach for heavy third-party packages, manual z-index stacks and getBoundingClientRect() scroll listeners. Even when a model knows a native API exists, it often lacks the density of production edge cases (such as focus restoration or reduced-motion rules) needed to ship accessible code.

The Solution // Cross-Browser Stewardship

Local search, guide retrieval and legacy scanning

Stewarded by the Google Chrome, Microsoft Edge, Mozilla Firefox and MDN teams, Modern Web Guidance works as a lightweight, offline-capable CLI and skill layer. Rather than guessing, an agent searches a curated catalogue of guides covering 269 web features: 144 in CSS and layout, 38 in HTML and the DOM, and 87 JavaScript APIs.

# 1. Search by capability (offline BM25 + local embedding model)
npx modern-web-guidance@latest search "light dismiss dialog"

# 2. Retrieve full best-practice patterns and fallback rules
npx modern-web-guidance@latest retrieve "animate-to-from-top-layer"

# 3. Scan a codebase for legacy patterns to modernise
npx modern-web-guidance@latest legacy-scan .
02 // Platform Foundations

Deep dive into Modern HTML

Modern HTML provides native top-layer overlays, semantic search landmarks, zero-flash server-rendered Web Components, smarter form validation and fine-grained resource loading without a single framework dependency.

HTML 01 // Native Overlays

The <dialog> element and the Popover API

Dialog: Widely Available
  • Native Top Layer: Calling dialog.showModal() promotes the modal above all page content automatically, eliminating z-index: 9999 escalation battles.
  • Built-in Accessibility: Modal dialogs trap keyboard focus inside themselves, make the background document inert (blocking clicks and screen-reader navigation behind the overlay), dismiss on Esc and return focus to the invoking button when closed.
  • Popover API (popover): Designed for non-modal menus, tooltips and action panels (Baseline Newly available Jan 2025). Add popover to a container and popovertarget="id" to a button for zero-JavaScript toggling and light dismissal when clicking outside.
  • Invoker Commands: Use declarative commandfor and command attributes on buttons to open or close dialogs without custom click listeners (Baseline Newly available Dec 2025).
<!-- Non-modal popover with zero JavaScript -->
<button popovertarget="help-tip">Quick Tip</button>
<div id="help-tip" popover>
  Automatically sits in the browser top layer.
</div>

<!-- Modal dialog with safe initial focus -->
<dialog id="confirm-box">
  <h4>Discard draft?</h4>
  <button autofocus onclick="this.closest('dialog').close()">
    Keep Editing
  </button>
</dialog>
HTML 02 // Semantics & Disclosures

<details>, <summary>, hidden="until-found" and <search>

<search>: Widely Available (Apr 2026)
  • Accessible Accordions: Pair <details> and <summary> for native keyboard-accessible disclosure widgets. Adding a matching name="faq" attribute creates mutually exclusive accordion groups natively (Baseline Newly available Sept 2024).
  • Searchable Hidden Content: Using hidden="until-found" keeps collapsed panels visually hidden while allowing browser Find-in-Page (Ctrl/Cmd+F) and URL fragment links to reveal matching text. It has Limited availability (not yet in Safari), and unsupported browsers treat it as plain hidden, so make sure the content can still be opened another way. Where you can, prefer <details>, whose content is searchable by default.
  • The <search> Landmark: Replaces verbose <div role="search"> wrappers, giving assistive technology an unambiguous semantic landmark for site search or filter controls.
<search aria-label="Filter components">
  <label for="q">Find feature</label>
  <input id="q" type="search">
</search>

<details name="faq">
  <summary>How does native grouping work?</summary>
  <p>Sharing the same name closes sibling items automatically.</p>
</details>
HTML 03 // Encapsulated Components

Web Components and Declarative Shadow DOM

Declarative Shadow DOM: Widely Available (Aug 2026)
  • Core Primitives: Autonomous Custom Elements (customElements.define), Shadow DOM style encapsulation and <template> + <slot> content projection create reusable UI across any stack.
  • Form-Associated Elements: Setting formAssociated = true and using ElementInternals lets custom controls submit values, participate in constraint validation and expose ARIA states directly.
  • Zero-FOUC Server Rendering: Declarative Shadow DOM (<template shadowrootmode="open">) reached Baseline Widely Available in August 2026. Browsers attach the shadow root directly during HTML parsing, rendering encapsulated styles before JavaScript executes and preventing flashes of unstyled content (FOUC).
<status-badge>
  <template shadowrootmode="open">
    <style>
      :host { display: inline-block; padding: 4px 10px; }
    </style>
    <slot>Verified</slot>
  </template>
  Ready for production
</status-badge>
HTML 04 // Smarter Forms

:user-valid, :user-invalid, dirname, switch and field-sizing

:user-invalid: Widely Available (May 2026)
  • Polite Validation States: Unlike :invalid (which flags empty required fields immediately on page load), :user-valid and :user-invalid wait until the visitor has edited or blurred the control.
  • Automatic Text Direction (dirname): Adding dirname="note.dir" submits whether the user typed left-to-right (ltr) or right-to-left (rtl) alongside the input payload (Baseline Widely Available).
  • Native switch Attribute: Adding switch to <input type="checkbox"> renders a toggle switch with switch semantics. It has Limited availability (Safari only so far); other browsers show an ordinary checkbox, which is a safe fallback.
  • Auto-Growing Inputs (field-sizing: content): Lets textareas and inputs expand naturally as users type, eliminating JavaScript scrollHeight resize handlers (Baseline Newly available June 2026).
<label for="bio">Short summary</label>
<textarea id="bio" name="bio" dirname="bio.dir"
  style="field-sizing: content; min-height: 3rem;"></textarea>

<label>
  <input type="checkbox" switch checked>
  Enable reduced motion preview
</label>
HTML 05 // Performance & CWV

Resource prioritisation and fetchpriority rules

LCP Target: ≤ 2.5s (75th Percentile)
  • Boost Largest Contentful Paint (LCP): Add fetchpriority="high" to the primary above-the-fold hero <img> so the browser fetches it ahead of lower-priority resources. Use it on one or two critical images at most, and never put loading="lazy" on the LCP image.
  • Put the LCP Image in the HTML: Make sure the LCP image is in the initial HTML so the browser's preload scanner finds it straight away. An <img> element is preferred; use <link rel="preload" as="image" fetchpriority="high"> only when the image is loaded from CSS (such as a background image) or JavaScript.
  • Leave Ordinary Lazy Images Alone: For standard below-the-fold images, loading="lazy" on its own is enough. Don't add fetchpriority="low" as well, because you want them to load at normal priority once the user scrolls to them. Keep fetchpriority="low" for images that are technically on screen but not yet visible, such as hidden carousel slides or mega-menu images.
<!-- Correct: High priority on hero LCP image -->
<img src="/assets/hero-banner.webp"
     width="1200" height="630"
     fetchpriority="high"
     alt="Platform architecture overview">

<!-- Correct: Lazy load below-the-fold without fetchpriority="low" -->
<img src="/assets/diagram-2.webp"
     width="800" height="450"
     loading="lazy"
     alt="Container layout schematic">
03 // Styling & Layout Architecture

Deep dive into Modern CSS

Modern CSS removes the need for preprocessors, floating-position JavaScript libraries and brittle layout hacks. Browsers now handle cascade layering, container-aware components, perceptual colour mixing and top-layer transitions natively.

CSS 01 // Architecture

Native Nesting & Cascade Layers (@layer)

Native CSS Nesting (Newly available Dec 2023, Widely available June 2026) lets you write nested child selectors and conditional @media or @container blocks directly in standard CSS without Sass. Pair it with Cascade Layers (@layer reset, base, components, utilities;) so layer order controls precedence cleanly instead of specificity battles or !important.

@layer base, components;
@layer components {
  .card {
    border: 1px solid var(--outline);
    &:hover { border-color: var(--primary); }
  }
}
CSS 02 // Responsive Layouts

Container Queries & CSS Subgrid

Size Container Queries (@container, Widely available Aug 2025) adapt a component based on its parent container width rather than the full viewport. Style Queries adapt visuals based on custom property values (Newly available May 2026). CSS Subgrid (Newly available Sep 2023, Widely available Mar 2026) lets nested card headers and footers snap cleanly to parent grid tracks.

.card-wrap { container-type: inline-size; }
@container (min-width: 440px) {
  .card { grid-template-columns: 160px 1fr; }
}
.card-grid-item {
  display: grid;
  grid-row: span 3;
  grid-template-rows: subgrid;
}
CSS 03 // Floating Geometry

CSS Anchor Positioning

Replaces Popper.js and Floating UI by tethering tooltips, menus and callouts directly to a target element using anchor-name, position-anchor and the anchor() function. This eliminates forced synchronous layout recalculations from getBoundingClientRect() inside scroll listeners. It still has Limited availability (Firefox doesn't support it yet), so wrap it in @supports (anchor-name: --a) and keep a simple fallback position.

#trigger { anchor-name: --menu-btn; }
.tooltip {
  position: absolute;
  position-anchor: --menu-btn;
  top: anchor(bottom);
  left: anchor(center);
}
CSS 04 // Perceptual Colour

oklch() and color-mix()

Unlike RGB or HSL (where yellow looks much brighter than blue at identical lightness numbers), oklch(L C H) models human perception uniformly across Lightness, Chroma and Hue. Combined with color-mix(), design systems generate hover shades and subtle tints dynamically in pure CSS. Both have been Baseline Widely available since November 2025.

:root {
  --brand: oklch(68% 0.17 245);
  --brand-tint: color-mix(in oklch, var(--brand) 16%, transparent);
}
CSS 05 // Discrete Transitions

@starting-style & allow-discrete

Previously, animating an element from display: none required JavaScript timers and forced reflows. Now transition-behavior: allow-discrete keeps top-layer dialogs and popovers visible while animating out, while @starting-style defines their initial entry frame declaratively. Both have been Baseline Newly available since August 2024.

dialog {
  opacity: 0;
  transition: opacity 0.25s, display 0.25s allow-discrete;
}
dialog[open] { opacity: 1; }
@starting-style { dialog[open] { opacity: 0; } }
CSS 06 // Selectors & Math

:has(), sibling-count(), shape() & :paused

The :has() relational selector (Newly available Dec 2023, Widely available June 2026) styles parents based on child states. sibling-index() and sibling-count() (Newly available Aug 2026) expose integers for proportional calc() widths or staggered delays. shape() (Newly available Feb 2026) builds responsive clip-path vectors, and :paused, one of the media element pseudo-classes, styles paused <audio> and <video> elements (Newly available Nov 2026).

.item {
  width: calc(100% / sibling-count());
  transition-delay: calc((sibling-index() - 1) * 50ms);
}
video:paused { outline: 2px solid var(--warning); }
CSS 07 // Typography & Visual Polish

text-wrap, text-box and native scrollbar stability

Visual Stability & CLS ≤ 0.1
  • text-wrap: balance & text-wrap: pretty: Apply balance to multi-line headings so lines share even lengths (Widely available Nov 2026), and apply pretty to body paragraphs to prevent lonely single-word final lines (Limited availability: not yet in Firefox, which simply wraps normally).
  • text-box Metric Trimming: Properties such as text-box: trim-both cap alphabetic trim invisible vertical font padding, centring labels optically inside tight buttons and badges (Limited availability: not yet in Firefox).
  • scrollbar-color & scrollbar-gutter: stable: Theme scrollbars declaratively without non-standard vendor prefixes, while reserving gutter space so pages never jump sideways when a modal or scrollbar toggles (Newly available Dec 2025 and Dec 2024).
h1, h2 { text-wrap: balance; }
p { text-wrap: pretty; }
.badge-pill { text-box: trim-both cap alphabetic; }
html {
  scrollbar-color: var(--outline) var(--background);
  scrollbar-gutter: stable;
}
04 // Interactive Code & Concept Comparator

Legacy JavaScript approach vs Modern Platform approach

Select a common UI engineering task below to inspect what legacy codebases relied on and how native HTML and CSS eliminate dependencies while improving accessibility and Core Web Vitals.

05 // Interoperability Database

Interactive Baseline Status Explorer

Filter key HTML and CSS capabilities from the Modern Web Guidance and WebDX corpus to see when each feature became available in all the core browsers and whether you still need a fallback. Dates come from the web-features data set behind Baseline.

Feature Domain Baseline Tier Interoperable Date Practical Guidance
06 // Live Interactive Component Sandbox

Test native browser primitives in real time

Switch between four live laboratories to experience native top-layer dialogs, container-query responsiveness, anchor positioning geometry and dynamic perceptual colour mixing directly in your browser.

Native Top Layer // Zero z-index hacks

Trigger the real HTML <dialog> modal below to observe background inertness, automatic focus trapping and Esc dismissal. Or click the popovertarget button to open a light-dismissable non-modal popover.

Status: Ready
Live <details name="sandbox-acc"> Item 1 (Mutually Exclusive)

Opening Item 2 below automatically closes this disclosure when supported by your browser, with zero JavaScript event handlers.

Live <details name="sandbox-acc"> Item 2 (Mutually Exclusive)

Built-in keyboard navigation and accessible expanded state come completely free with semantic HTML.

07 // Reinforce Your Understanding

Beginner self-test quiz & Project Readiness Checklist

Test your grasp of Modern Web Guidance, Baseline interoperability and native HTML/CSS patterns. Your answers and checklist are saved in this browser and restored when you come back.

Question 1 of 8 Score: 0 / 8

Loading question...

Project Audit // Readiness 0 / 8 Checked

Tick off each Modern Web Guidance rule as you review a page or AI-generated pull request.

Sources & Attribution

Adapted from Google's Modern Web Guidance (Chrome for Developers) and its GitHub repository, including the Optimize image priority guide; Baseline statuses and dates from the W3C WebDX Community Group's web-features data, also shown on webstatus.dev; the Lighthouse Baseline Features audit; Core Web Vitals guidance on web.dev; Section508.gov USWDS accessibility guidance and GOV.UK Design System community principles.

Native Top Layer Modal

Focused & Inert by Default

While this <dialog> is open via showModal(), the background page is automatically inert. Press Esc or click the button below to dismiss and return focus to the trigger.

Popover API

This non-modal overlay opened without JavaScript using popovertarget. Click anywhere outside or press Esc to light-dismiss it.