How to find what is causing a layout shift (CLS)

Your page jumps and Core Web Vitals flags CLS, but the element it names is not the culprit. How to trace a shift to its real cause, the five usual suspects, and how to fix each one.

By Swapnil Gupta · · 7 min read

You go to tap a link and the page jumps, so you tap an ad instead. That is a layout shift, and Cumulative Layout Shift (CLS) is the Core Web Vitals score that adds them up. A good score is 0.1 or less. The frustrating part of fixing it is that the tools usually point at the wrong element.

The element that moved is not the cause#

A layout shift is recorded against the elements that moved. But elements rarely move by themselves: something else changed size or appeared, and pushed them. Fix the element that was flagged and nothing improves, because the culprit is usually above it.

A banner is added above the article 1.2 seconds in, with no space kept for it. The article moves down 64 pixels and is the element reported. The banner is the cause.

So for every shift, ask two questions: what moved, and what changed just above or around it at that moment?

Finding shifts in Chrome DevTools#

  1. Open the Performance panel and record a reload of the page.
  2. Look at the Layout shifts track: each shift is a block. Click one to see which elements moved, with their old and new positions.
  3. Open the Layout shift culprits insight in the sidebar. Chrome names a likely cause when it can, such as an image without dimensions or a late web font.

For shifts that only happen for real visitors, or later than a reload, log them as they happen. Paste this into the Console, then use the page:

new PerformanceObserver((list) => {
  for (const entry of list.getEntries()) {
    if (entry.hadRecentInput) continue; // shifts right after a click or key do not count
    for (const s of entry.sources) {
      console.log(entry.value.toFixed(4), s.node, s.previousRect, s.currentRect);
    }
  }
}).observe({ type: "layout-shift", buffered: true });

Each line is a shift's score and an element that moved, with where it was and where it went. Compare the rectangles: whatever grew or appeared in the gap is your suspect.

Seeing every shift on the page#

Nitpique's Layout shifts list, in the Design tab, shows each shift with where the element was, where it went and the likely cause, and the page's CLS beside Largest Contentful Paint and INP. Hover a shift to see it on the page, press replay to watch it happen again, and click to select what moved, so you can look at what sits above it.

The five usual suspects, and their fixes#

CauseWhat you seeFix
Images, video and iframes without a sizeContent drops when the picture loadsSet width and height attributes, or aspect-ratio in CSS
Ads and embedsA slot grows from nothing to its full heightReserve the space with min-height on the slot
Content added aboveA banner, notice or 'related' block pushes everything downKeep space for it, or show it over the page instead of in the flow
Web fontsText reflows when the font arrivesPreload the font, and match the fallback's size with size-adjust and the metric overrides in @font-face
Animating layoutElements slide by changing top, height or marginAnimate transform and opacity instead
Shifts within half a second of a click, tap or key press are not counted: the page is allowed to change in answer to the visitor. A menu that opens when tapped is fine; a menu that opens by itself is not.

Checking the fix#

  • Reload with a slow network and CPU (throttling in the Performance panel), where late content is easiest to see.
  • Check a phone width too: shifts are often bigger where columns stack.
  • Confirm with field data. Lab tools measure one load; the CLS that counts for search is measured on real visits, which you can see in PageSpeed Insights once the page has enough traffic.

Read next