The Cumulative Layout Shift (CLS) metric measures the largest burst of layout shift scores for every unexpected layout shift that occurs during the entire lifecycle of a page.
CLS is essentially composed of:
- impact fraction of the total area of the viewport
- distance fraction of the viewport's largest dimension
| CLS | Mobile/Desktop |
|---|---|
| Good | < 0.1 |
| Needs Improvement | 0.1-0.25 |
| Poor | > 0.25 |
- Position of DOM elements is changed
- Dimension of DOM elements is changed
- DOM elements are inserted or removed
- CSS animations that trigger layout are running on the page
- CSS
positionof a DOM element - Images, ads or social embeds are loaded without proper space being reserved
- Async content is rendering without proper space being reserved
- Use of custom fonts with no proper fallback
- Loading async content that causes the scrollbar to appear lazily
- Cookie consent banners injected at the top of the page pushing all content down
For step-by-step fixes with code examples and anti-patterns, see the use-case runbooks: layout stability, images and fonts.
- Insert/re-order/remove DOM elements before the page is made visible to the user
- Set proper
heightandwidthproperties for images, ads or social embeds before they are loaded, or set theaspect-ratioCSS property - Animate using the CSS
transformproperty rather than direct CSS position and size properties- Check which CSS properties trigger layout vs. paint vs. composite in the MDN animation-type data before animating them
- Use the View Transitions API to animate content changes: shifts that happen inside a view transition are visually smooth and don't count as unexpected layout shifts
- Reserve space for content that loads asynchronously and use properly sized placeholders (leverage static
height/min-height, or position itabsolute/fixed) - Optimize your fallback fonts and
size-adjustthem to your custom font- https://web.dev/articles/css-size-adjust
- https://www.debugbear.com/blog/web-font-layout-shift#adjusting-font-metrics
- https://www.aem.live/developer/font-fallback
- Tools like Capsize or fallback font generators can compute the
size-adjust/ascent-override/descent-overridemetrics for you - Consider
font-display: optionalfor non-essential fonts: it eliminates font-driven shifts entirely
- Avoid inserting new content without a clear user interaction (like a "load more" button on an infinite list, or toggling an accordion panel)
- Leverage the
scrollbar-gutter: stableCSS property
new PerformanceObserver((entryList) => {
for (const entry of entryList.getEntries()) {
console.log('Layout shift:', entry);
}
}).observe({ type: 'layout-shift', buffered: true });import { onCLS } from 'web-vitals/attribution';
// Measure and log CLS in all situations where it needs to be reported,
// including the largest shifted element.
onCLS(({ value, attribution }) => {
console.log('CLS:', value, attribution.largestShiftTarget, attribution);
});Follow the steps in one of:
- CLS in our performance audit article
- the Layout Shift event in the Chrome DevTools performance audit panel, or the Layout shift culprits insight in the Performance panel sidebar which points at the shifting elements and their likely cause
- the live metrics view of the Performance panel, which accumulates CLS as you interact with the page
- the Cumulative Layout Shift metric in the WebPageTest site performance audit
- https://web.dev/articles/cls
- https://web.dev/articles/optimize-cls
- https://web.dev/articles/debug-layout-shifts
- https://www.debugbear.com/docs/metrics/cumulative-layout-shift
- https://www.debugbear.com/blog/devtools-layout-shift
- https://www.woorank.com/en/core-web-vitals/improving-cumulative-layout-shift
- https://culture-tecture.adobe.com/en/publish/2024/08/26/aem-blog-cumulative-layout-shift-cls-a-developer-s-nightmare
- https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_animated_properties
- https://richstyle.org/?documentation/css-will-change-property-en