Loadzen

← All articles

Core Web Vitals7 min readReece Crowther

How to Fix Cumulative Layout Shift (CLS): A Complete Guide

Cumulative Layout Shift causes elements to jump around as your page loads. Here is how to diagnose the exact cause and fix it for good.

What is Cumulative Layout Shift?

Cumulative Layout Shift (CLS) measures how much the visible content of a page moves unexpectedly during loading. A CLS score of 0.1 or below is considered good by Google. Anything above 0.25 is poor.

Layout shifts happen when an element that has already been painted moves because something loads after it — an image without dimensions, a late-loading font, an injected banner, or an ad slot that expands.


How to find what is causing your CLS

Before fixing anything, identify which elements are shifting.

Open Chrome DevTools, go to the Performance tab, and record a page load. Look for the pink "Layout Shift" markers in the timeline. Click one and you will see exactly which element moved, how far it moved, and what caused it.

Alternatively, run your URL in PageSpeed Insights. The Diagnostics section shows "Avoid large layout shifts" with a list of the specific elements contributing to your score.


The most common CLS causes and fixes

1. Images without width and height attributes

This is the most common cause. When the browser encounters an image without dimensions, it reserves no space for it. When the image loads, everything below it shifts down.

Fix:

```html

Hero

Hero

```

Modern CSS uses the width and height attributes to calculate the aspect ratio in advance. The browser reserves exactly the right space before the image downloads.

If you cannot set fixed dimensions, use the aspect-ratio CSS property:

```css

img {

aspect-ratio: 16 / 9;

width: 100%;

}

```

2. Ads and embeds without reserved space

Ad slots that inject content dynamically are a leading cause of CLS. The ad network does not know the ad size until it loads, so it pushes content down.

Fix:

  • Set a minimum height on every ad container that matches the largest ad format you serve.
  • Use the Cumulative Layout Shift API to detect unexpected shifts in production.
  • Consider loading ads in fixed-position overlays that do not displace content.
  • 3. Web fonts causing text reflow

    When a custom font loads after the browser has already rendered text in a fallback font, the text reflows if the two fonts have different metrics. This causes the surrounding layout to shift.

    Fix:

  • Use font-display: optional for non-critical fonts. The browser will only use the custom font if it is already cached.
  • Use font-display: swap for important fonts, and use the CSS size-adjust descriptor to match fallback and custom font metrics.
  • Preload your primary font so it arrives before first paint:
  • 4. Dynamically injected content

    Cookie banners, chat widgets, newsletter pop-ins, and promotional bars that appear above existing content cause layout shifts.

    Fix:

  • Position injected UI at the bottom of the viewport or in a fixed overlay so it does not displace content.
  • Reserve space for known elements like cookie bars using a CSS placeholder that is always rendered, even before the script loads.
  • Use position: fixed or position: sticky for persistent banners.
  • 5. Animations and transitions that affect layout

    CSS animations that change properties like top, left, width, or height trigger layout shifts. Transitions on margin or padding do the same.

    Fix:

  • Animate with transform and opacity only. These run on the compositor thread and do not cause layout shifts.
  • Use will-change: transform on elements you know will animate, so the browser creates a separate compositing layer.

  • How CLS is scored

    CLS is not just the total shift distance. It is calculated as the fraction of the viewport that shifted multiplied by the distance the element moved as a fraction of the viewport height. A large element that shifts a small distance scores the same as a small element that shifts far.

    The score accumulates across all layout shifts during the page lifetime, excluding shifts that happen within 500ms of a user interaction (taps, clicks, scrolls).


    Measuring your CLS score

    Run a free check with Loadzen to see your current CLS score alongside LCP and INP. The results show your score, the threshold you need to hit, and which specific issues are contributing.

    Google Search Console's Core Web Vitals report shows field CLS from real users — this is the data that feeds into Google's ranking signals.

    Related guide

    Core Web Vitals Fix Guide

    Keep reading

    Check your own site

    Run a free speed check with Loadzen and get a prioritized fix plan for your specific platform.

    Run free speed check