WSS
Web Specification Studio Home
On this page
Studio StandardsRequiredUpdated

Zero-Layout-Shift Rendering

Strict engineering rules for reserving exact DOM space for images to guarantee a 0.0 CLS.

What is it?

An engineering mandate ensuring that the Cumulative Layout Shift (CLS) core web vital metric remains exactly 0.0 across the entire lifecycle of a page load.

Why does it matter?

Layout shift occurs when an element dynamically changes size or is injected into the DOM, pushing existing content down. This destroys user trust (e.g., clicking the wrong button because the page jumped) and is heavily penalized by Google’s search algorithms. A non-zero CLS is considered an unacceptable engineering failure in modern web development.

How to implement it

1. Explicit Image Dimensions

Every single <img>, <video>, and <iframe> must have explicit width and height attributes in the HTML. The browser uses this ratio to reserve space before the asset downloads.

<!-- Incorrect -->
<img src="hero.jpg" class="w-full h-auto" alt="Hero">

<!-- Correct -->
<img src="hero.jpg" width="1200" height="800" class="w-full h-auto" alt="Hero">

2. Aspect Ratio for Dynamic Containers

For containers loading dynamic content (like ads or client-side rendered widgets), use the CSS aspect-ratio property or a min-height to reserve the exact layout space.

.ad-slot {
  aspect-ratio: 16 / 9;
  background-color: #f3f4f6; /* Placeholder skeleton */
}

Font Swap Containment & Dynamic Banner Slot Reservation

Eliminating layout shifts across asynchronous component lifecycles requires controlling font swaps and dynamic DOM insertions:

  • Font Swap Shift Prevention (font-display: optional): While font-display: swap prevents invisible text, swapping from fallback fonts to web fonts can trigger line wrapping changes and vertical layout shifts. Using font-display: optional or CSS font metric overrides (size-adjust, ascent-override) ensures that font swaps do not alter element bounding boxes.
  • Dynamic Content & Notification Bar Reservation: Never inject notification banners, cookie consent bars, or promotional banners dynamically above existing page content without pre-allocating layout space. Dynamic insertions above the viewport push the entire DOM tree down, severely penalizing CLS scores.
  • Scrollbar Gutter Reservation (scrollbar-gutter: stable): When modal dialogs or popovers open and disable body scrolling (overflow: hidden), the browser scrollbar disappears, causing horizontal layout shifts. Apply scrollbar-gutter: stable to <html> to keep scrollbar space reserved permanently.

Verification

  • Run Chrome DevTools -> Performance tab and enable “Web Vitals”. Record a page load (with slow 3G throttling) and ensure the “Layout Shifts” track is completely empty.

Related topics