Cumulative Layout Shift (CLS) is one of Google's Core Web Vitals metrics, measuring visual stability during page loading. This comprehensive guide covers everything developers need to understand, measure, and fix CLS issues.
Unlike other performance metrics that focus on loading speed, CLS measures whether content moves unexpectedly while users are trying to interact with the page--a critical factor for user experience and SEO rankings. Our team of web development experts regularly audits client sites for these stability issues as part of comprehensive performance optimization services.
CLS Score Benchmarks
0.1
Good CLS Score (or less)
0.25+
Poor CLS Score threshold
75th
Percentile measured
What Is Cumulative Layout Shift?
Cumulative Layout Shift is a metric that quantifies how often users experience sudden shifts in page content. When elements on a page move unexpectedly after rendering, users can lose their place, click the wrong link or button, or become disoriented. Google includes CLS as a ranking factor because poor visual stability directly impacts user experience across all types of websites.
Why CLS Matters for Your Website
Layout shifts create frustrating experiences that undermine trust and engagement:
- Misclicks: When a button moves after a user clicks, unwanted actions trigger
- Lost context: Text reflow causes readers to lose their place
- Cart abandonment: E-commerce layouts shift during checkout flow
- Reduced engagement: Unstable pages feel unprofessional and broken
The Evolution of CLS: Session Windows
Google updated the CLS calculation methodology to use session windows instead of a total sum approach:
- Session window: Bursts of activity where shifts occur within 1 second of each other
- Maximum duration: 5 seconds per session
- Worst session: The final CLS score is the worst-performing session
This change better reflects real user experience by preventing late-loading elements from disproportionately affecting the overall score.
How CLS Is Calculated
The layout shift score formula is:
layout shift score = impact fraction × distance fraction
Impact Fraction
Impact fraction measures how much of the viewport is affected by unstable elements. When an element changes position between frames, the browser calculates the combined visible area of that element in both its old and new positions, then divides by the total viewport area.
Distance Fraction
Distance fraction measures how far an element moved relative to the viewport. The browser takes the maximum distance moved horizontally or vertically and divides by the viewport's larger dimension (width or height).
Example Calculation
Consider an image occupying 50% of the viewport that shifts down by 25% of the viewport height:
- Impact fraction: 0.75 (combining old and new positions)
- Distance fraction: 0.25
- Layout shift score: 0.75 × 0.25 = 0.1875
Common Causes of Cumulative Layout Shift
Understanding the root causes of layout shifts is essential for effective optimization.
Images Without Explicit Dimensions
Images without width and height attributes cause the most frequent layout shifts. When a browser encounters an image tag without dimensions, it renders a zero-height element until the image loads.
The Fix: Always include width and height attributes on image elements:
<img src="product.jpg" width="800" height="600" alt="Product">
For responsive images, combine these attributes with CSS aspect-ratio:
<img src="hero.jpg" style="width: 100%; aspect-ratio: 16/9;" alt="Hero">
Lazy Loading Above-the-Fold Content
Applying loading="lazy" to images appearing above the fold guarantees layout shifts. Lazy loading defers image requests until scrolling brings elements into viewport.
The Fix: Remove lazy loading from any image appearing in the initial viewport. Add fetchpriority="high" to critical images:
<!-- Hero image - no lazy loading -->
<img src="hero.jpg" fetchpriority="high" alt="Hero">
Web Fonts and Text Reflow
Web fonts cause layout shifts when fallback fonts differ significantly in size from the loaded font.
The Fix: Use font-display: optional to prevent layout shifts:
@font-face {
font-family: 'CustomFont';
src: url('/fonts/custom.woff2') format('woff2');
font-display: optional;
}
Dynamically Injected Content
Content injected via JavaScript after the initial render pushes existing elements downward. Common sources include promotional banners, notification toasts, and live chat widgets.
The Fix: Always reserve space for known-dimension content:
.banner {
min-height: 100px;
}
Third-Party Widgets and Embeds
Third-party scripts often load content after page completion, causing shifts when containers resize.
The Fix: Request dimensions from providers and apply explicit sizing:
<div class="youtube-embed" style="aspect-ratio: 16/9;">
<iframe src="..." loading="lazy"></iframe>
</div>
CSS Animations and Layout Changes
CSS animations that change layout properties (width, height, margin) trigger reflows and repaints.
The Fix: Use transform and opacity properties which the browser handles on the compositor thread:
/* Good - uses transform */
.fade-in {
opacity: 0;
transform: translateY(20px);
transition: opacity 0.3s, transform 0.3s;
}
Ad Containers Without Reserved Space
Advertising networks deliver variable-sized creatives into fixed containers, making prediction difficult.
The Fix: Configure ad units with minimum heights:
.ad-container {
min-height: 250px;
background: #f0f0f0;
}
Tools for Measuring and Debugging CLS
Lighthouse and PageSpeed Insights
Lighthouse provides CLS measurement through Chrome DevTools and PageSpeed Insights. The "Avoid large layout shifts" audit identifies specific elements contributing to poor scores.
Chrome DevTools Performance Panel
The Performance panel records layout shifts during page load, displaying each shift on the timeline with affected elements highlighted. Use the Layout Shift Regions feature to visualize shifting areas in real-time.
Core Web Vitals Extension
Chrome extensions like Web Vitals provide real-user CLS measurements based on actual browsing sessions. These tools collect field data similar to what Google uses for ranking.
DebugBear and Similar Monitoring Platforms
Services like DebugBear combine synthetic testing with real-user monitoring (RUM) to track CLS over time. Integration with CrUX data enables benchmarking against competitors.
To get a comprehensive view of your website's performance, consider partnering with web development specialists who can conduct thorough audits and implement optimizations across all Core Web Vitals metrics.
Step-by-Step CLS Audit Process
1. Establish Baseline
Run Lighthouse or PageSpeed Insights to establish current CLS scores. Note which specific audits fail and which elements the tool identifies as shifting.
2. Identify Shifting Elements
Use Chrome DevTools Performance panel to record a page load. Look for layout shift entries in the Summary tab. The affected elements are typically not the cause but the victims--look for what loaded before them.
3. Categorize the Cause
Match observed shifts to common cause categories:
- Missing image dimensions
- Lazy loading above fold
- Late-loading scripts
- Font changes
- Dynamic content injection
4. Implement Targeted Fixes
Apply appropriate fixes based on categorization:
| Cause | Fix |
|---|---|
| Images without dimensions | Add width/height attributes |
| Above-fold lazy loading | Remove lazy attribute |
| Font loading | Use font-display: optional |
| Dynamic content | Reserve minimum space |
| Third-party embeds | Apply explicit dimensions |
5. Validate and Monitor
Re-run tests to confirm improvements. Check CLS scores across device types and network conditions. Implement ongoing monitoring with RUM tools.
Use this checklist to ensure your pages deliver stable visual experiences
Image Dimensions
Always specify width and height attributes on image elements
Responsive Aspect Ratio
Use CSS aspect-ratio for responsive images
Critical Images
Never apply loading=lazy to above-the-fold images
Fetch Priority
Add fetchpriority=high to hero and critical images
Font Display
Use font-display: optional for text content
Font Preloading
Preload critical fonts in document head
Reserved Space
Reserve minimum space for dynamic content
Animation Properties
Use transform and opacity for all animations
Third-Party Scripts
Load third-party scripts asynchronously with defer or async
RUM Monitoring
Implement real-user monitoring for ongoing tracking
Code Examples
Responsive Image with Aspect Ratio
<picture>
<source media="(min-width: 800px)" srcset="large.jpg">
<source media="(min-width: 400px)" srcset="medium.jpg">
<img
src="small.jpg"
alt="Responsive image"
style="width: 100%; height: auto; aspect-ratio: 16/9;"
>
</picture>
Font Loading with No Layout Shift
<head>
<link rel="preload" href="/fonts/heading.woff2" as="font" type="font/woff2" crossorigin>
</head>
<style>
h1, h2, h3 {
font-family: 'HeadingFont', system-ui, sans-serif;
font-display: optional;
}
</style>
Reserved Space for Dynamic Banner
<style>
.promo-banner {
min-height: 80px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
display: flex;
align-items: center;
justify-content: center;
color: white;
}
</style>
Animation Without Layout Impact
.card {
opacity: 0;
transform: translateY(30px) scale(0.95);
transition: opacity 0.4s ease-out, transform 0.4s ease-out;
will-change: opacity, transform;
}
.card.visible {
opacity: 1;
transform: translateY(0) scale(1);
}
Frequently Asked Questions
What is a good CLS score?
A good CLS score is 0.1 or less, measured at the 75th percentile. This means 75% of your users experience layout shifts at or below this threshold. Scores between 0.1 and 0.25 need improvement, while anything above 0.25 is considered poor.
Does CLS affect SEO rankings?
Yes, CLS is one of Google's Core Web Vitals and is used as a ranking signal. Pages with good CLS scores may see ranking benefits compared to pages with poor scores, especially on mobile search results.
Why did my CLS score change recently?
Google updated the CLS calculation methodology to use session windows instead of total sum. This change provides a more accurate representation of user experience and may result in different scores for the same pages.
How do I find which elements are causing layout shifts?
Use Chrome DevTools Performance panel to record a page load. Look for layout shift entries in the summary, or enable Layout Shift Regions in the Rendering tab to see shifting areas highlighted in real-time.
Can animations cause layout shifts?
CSS animations that change layout-triggering properties (width, height, margin, padding, top, left) can cause layout shifts. Use transform and opacity properties instead, which the browser can animate without affecting layout.
Should I lazy load all my images?
No, never lazy load images that appear above the fold. Lazy loading is appropriate for images below the viewport that users may never scroll to. Critical images should load immediately with high fetch priority.
Conclusion
Cumulative Layout Shift represents a fundamental aspect of user experience that many development teams overlook. Unlike loading speed metrics, CLS measures whether users can reliably interact with page content without unexpected movement.
The good news is that CLS issues are entirely preventable with proper development practices:
- Reserve space for dynamic content
- Specify dimensions for all images
- Manage font loading carefully
- Use CSS animations that don't trigger layout changes
By following these practices, developers can achieve CLS scores well below the 0.1 threshold, delivering stable experiences that build user trust and improve search visibility.
The key insight is that preventing layout shifts requires thinking about space reservation from the start of development, not treating it as an optimization to address after the fact. For businesses looking to ensure their websites meet Google's Core Web Vitals standards, our web development services team can audit existing sites and implement comprehensive performance optimizations.
Sources
- web.dev - Cumulative Layout Shift (CLS) - Google's official documentation on CLS
- web.dev - Optimize Cumulative Layout Shift - Google's official optimization guide
- BrowserStack - Understanding Cumulative Layout Shift - Practical guide with measurement tools
- DebugBear - How To Avoid Large Layout Shifts - Real-world case studies
- MDN - Layout Instability API - Browser API documentation