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.
0.4 s: the page has painted
1.2 s: a banner is inserted
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#
- Open the Performance panel and record a reload of the page.
- Look at the Layout shifts track: each shift is a block. Click one to see which elements moved, with their old and new positions.
- 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#
| Cause | What you see | Fix |
|---|---|---|
| Images, video and iframes without a size | Content drops when the picture loads | Set width and height attributes, or aspect-ratio in CSS |
| Ads and embeds | A slot grows from nothing to its full height | Reserve the space with min-height on the slot |
| Content added above | A banner, notice or 'related' block pushes everything down | Keep space for it, or show it over the page instead of in the flow |
| Web fonts | Text reflows when the font arrives | Preload the font, and match the fallback's size with size-adjust and the metric overrides in @font-face |
| Animating layout | Elements slide by changing top, height or margin | Animate transform and opacity instead |
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.