Cumulative Layout Shift
Cumulative Layout Shift (CLS) is a Core Web Vital that measures how much a page’s visible content unexpectedly moves during loading or interaction.
- Also called
- CLS
- Applies to
- web pages
- Commonly confused with
- user-initiated shifts
Key points
- CLS is one of Google's Core Web Vitals that measures visual stability.
- A good CLS score is 0.1 or less for at least 75% of page visits.
- Reserve space for images and videos using width and height attributes or CSS aspect-ratio.
- Avoid inserting ads, embeds, or pop-ups without reserving layout space.
- Check both lab and field data to accurately assess CLS performance.
How it works
CLS is calculated by summing the scores of all unexpected layout shifts that occur during a page's lifespan. Each shift score is the product of the impact fraction (how much of the viewport moved) and the distance fraction (how far the elements moved). Google defines CLS as the largest burst of shift scores, not a cumulative total.
Only shifts that are not initiated by user actions count. For example, clicking a button that expands a menu is not a layout shift, but an image loading and pushing text down unexpectedly is. The metric focuses on the final visual stability experienced by real users, so it can differ between lab tests and field data.
Improving CLS often involves ensuring all visible elements have reserved space. Images and videos should include width and height attributes, while dynamic content like ads or cookie notices need placeholder containers. Web fonts can cause shifts if fallback fonts differ in size; using font-display: optional or swapping can help. These techniques are part of broader efforts to improve user experience, such as optimizing largest contentful paint and learning how to optimize website performance.
Common mistakes
- Leaving image or video dimensions unspecified forces the browser to reflow content when the asset loads, increasing CLS.
- Inserting banners, cookie notices, or ads above existing content without reserving space causes unexpected downward shifts.
- Assuming all animations cause CLS: user-initiated changes and transform-based animations are usually excluded, but complex CSS animations may still contribute.
- Optimising only for lab tools while ignoring field data from real users leads to overlooked CLS issues from third-party scripts or slow networks.
Questions people ask
Cumulative layout shift how to improve?
To improve CLS, always set explicit width and height attributes on images and videos. Reserve space for ads and embeds using placeholder containers. Use CSS aspect-ratio boxes for responsive media. Avoid inserting dynamic content above existing page elements without allocating layout space.
What is cumulative layout shift?
Cumulative Layout Shift (CLS) is a Core Web Vital that measures visual stability by tracking unexpected movement of visible content during page load or interaction. It is calculated from the impact and distance of shift events, excluding user-initiated changes. A low CLS indicates a stable, well-behaved page.
How to avoid cumulative layout shift?
Avoid CLS by specifying dimensions for all media, using CSS aspect-ratio for flexible containers, and preloading fonts with appropriate fallback spaces. For third-party content like ads or embeds, use static placeholders with matching dimensions. Test both lab and field data to catch shifts from dynamic content.
Sources
- web.dev: Cumulative Layout Shift (CLS) Primary Google explanation of the metric and how CLS is defined.
- web.dev: Optimize Cumulative Layout Shift Google guidance on how to reduce CLS and target thresholds.
- MDN Glossary: CLS Clear glossary definition of CLS and what counts as unexpected shift.
- Google Publisher Tag: Minimize layout shift Authoritative guidance for ad-related layout shift prevention.