Cumulative Layout Shift (CLS)

Eliminating unexpected visual jumps caused by unsized images, late-loading webfonts, and dynamically injected banners.

What CLS Measures

Cumulative Layout Shift (CLS) quantifies how much visible page content shifts unexpectedly during the entire lifespan of a page session. A good CLS score is 0.1 or lower.

Layout shifts are calculated as impact fraction × distance fraction for any movement not triggered within 500ms of a user interaction.

Common Causes & Deterministic Fixes

1. Images, Videos, and Embeds Without Dimensions

Always include width and height attributes on <img> and <video> elements so browsers compute the exact aspect ratio before the file downloads:

img, video {
  max-width: 100%;
  height: auto;
}

For responsive iframes, ad slots, or dynamic widgets, reserve space with CSS aspect-ratio or min-height:

.embedSlot {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: var(--code-bg);
}

2. Webfont Swap Reflows

When a fallback system font (Arial or Georgia) swaps to a webfont with different glyph widths, paragraphs reflow and push content downward. Adjust fallback font metrics using @font-face descriptors (size-adjust, ascent-override, descent-override):

@font-face {
  font-family: 'Inter Fallback';
  src: local('Arial');
  size-adjust: 107%;
  ascent-override: 90%;
  descent-override: 22%;
  line-gap-override: 0%;
}

3. Animate with Composited Properties Only

Never animate top, left, width, height, or margin for drawers, toasts, or accordions. Use transform: translate3d(...) and opacity, which run on the GPU compositor without triggering layout shifts.