Articles

Cumulative Layout Shift (CLS) Explained and How to Fix It

Cumulative Layout Shift measures how much visible content unexpectedly moves while a page loads. How CLS is scored, what causes it, and how to fix it.

Takina Takina · · 5 min read
Performance metrics displayed on a screen

Cumulative Layout Shift (CLS) is the Core Web Vital that measures visual stability: how much visible content on a page moves around unexpectedly while a user is looking at it. A button that jumps down just as you tap it, or a paragraph that slides out of view because an ad loaded above it, both register as layout shifts. A good CLS score is 0.1 or less; anything above 0.25 is considered poor.

Where CLS fits among the Core Web Vitals

Google’s Core Web Vitals measure three aspects of user experience: loading (Largest Contentful Paint), responsiveness (Interaction to Next Paint), and visual stability (CLS). Our Core Web Vitals guide covers all three. CLS is the odd one out because it isn’t measured in time — it’s a unitless score based on how far elements move and how much of the screen they affect.

How a layout shift is scored

The browser’s Layout Instability API reports a layout shift whenever a visible element changes its start position between two rendered frames. Each individual shift gets a score:

layout shift score = impact fraction × distance fraction
  • Impact fraction is the share of the viewport affected by unstable elements — the combined area they occupied before and after moving.
  • Distance fraction is the greatest distance any unstable element moved, divided by the viewport’s largest dimension.

Suppose an element covering half the viewport moves down by a quarter of the viewport’s height. Its before-and-after area together covers 75% of the screen, so the impact fraction is 0.75. The distance fraction is 0.25. The shift scores 0.75 × 0.25 ≈ 0.19 — already well past the “good” threshold from a single event.

Session windows

Early versions of CLS simply summed every shift for the page’s entire lifetime, which unfairly punished long-lived single-page apps. The current definition groups shifts into session windows: a burst of shifts with less than one second between them, capped at five seconds total. A page’s CLS is the score of its worst session window.

Two important exclusions keep the metric fair:

  • Shifts right after user input don’t count. Any shift within 500 milliseconds of a tap, click, or keypress is flagged with hadRecentInput and excluded, because the user expected something to change. Scrolling doesn’t count as input for this purpose.
  • Transform animations don’t count. Moving an element with CSS transform doesn’t change its layout position, so it isn’t a layout shift.

The common causes of CLS

Almost every layout shift comes from the browser not knowing how much space something needs until it arrives.

Images and videos without dimensions. If an <img> has no width and height attributes, the browser reserves zero height for it and shoves everything below it down when the image loads. This is the single most common cause.

Ads, embeds, and iframes. Third-party slots often inject content of unknown size after the surrounding page has rendered.

Dynamically injected content. Cookie banners, newsletter prompts, and “related posts” widgets inserted above existing content push it down.

Web fonts. When a fallback font is swapped for a web font with different metrics, text reflows and lines can wrap differently, shifting everything below.

Late-loading CSS or client-side rendering. Content that renders unstyled first and then restyles, or a skeleton that doesn’t match the final layout, causes shifts when the real content appears.

How to fix it

Always size media. Give images and videos explicit width and height attributes. Modern browsers use them to compute an aspect ratio and reserve the correct space even when CSS makes the image responsive:

<img src="/hero.jpg" width="1200" height="630" alt="..." style="width:100%;height:auto">

For elements without intrinsic dimensions, the CSS aspect-ratio property does the same job. Lazy-loaded images need dimensions just as much as eager ones.

Reserve space for ads and embeds. Give ad slots and iframe containers a min-height matching the most likely size. If the slot sometimes stays empty, a placeholder of the right size is still better than collapsing and expanding.

Insert new content below the fold or in reserved space. Place banners in a fixed or sticky position overlaying the page rather than pushing it, or reserve their space from the first render.

Tame font swaps. Preload critical fonts and use the CSS size-adjust, ascent-override, and descent-override descriptors on a fallback @font-face so its metrics closely match the web font. The trade-offs between font-display values are covered in our web font loading explainer.

Animate with transforms. Animate transform and opacity rather than top, left, width, or height. Besides avoiding layout shifts, it avoids expensive reflows.

Make skeletons match reality. Loading placeholders should have the same dimensions as the content they stand in for.

Measuring CLS

CLS needs to be measured in both lab and field conditions, because lab tools only see the initial load while real users scroll, interact, and stay on pages for minutes.

In the browser you can observe shifts directly:

new PerformanceObserver((list) => {
  for (const entry of list.getEntries()) {
    if (!entry.hadRecentInput) {
      console.log(entry.value, entry.sources);
    }
  }
}).observe({ type: "layout-shift", buffered: true });

The sources array identifies which DOM nodes moved, which is usually the fastest way to find the culprit. Browser developer tools can also highlight layout shift regions during a performance recording. For field data, real-user monitoring libraries implement the session-window logic for you.

One subtle source of field-only CLS is navigating back to a page that has to be re-rendered from scratch. Pages restored from the back/forward cache come back exactly as they were, avoiding a fresh round of shifts.

The takeaway

CLS scores how much visible content unexpectedly moves, using the worst burst of shifts on the page; aim for 0.1 or lower. Nearly every shift comes from content whose size the browser didn’t know in advance, so the fix is almost always to reserve space: dimensions on images, minimum heights on ad and embed slots, matched fallback fonts, and transform-based animation. Measure with a PerformanceObserver and real-user data, not just a single lab run.