How to Diagnose and Reduce Cumulative Layout Shift (CLS)

Technical illustration of browser rendering showing layout boundaries and viewport dimensions

Understanding and Diagnosing Cumulative Layout Shift (CLS)

To fix Cumulative Layout Shift, start by giving every image and video explicit width and height attributes or CSS aspect-ratio values so the browser can reserve space before assets load. Reserve minimum heights and widths for ad slots, embeds, and iframes, and preload critical web fonts while using font-display controls to prevent text reflow. Keep dynamic banners and cookie notices in pre-sized containers or overlays, and animate with transform and opacity rather than layout-triggering properties. These steps directly reduce the unexpected visual movement that CLS measures.

Cumulative Layout Shift is an official Core Web Vital metric designed to evaluate the visual stability of a webpage. When page elements move unexpectedly while an asset loads or a script executes, it creates a disruptive browsing experience. Understanding how modern browsers quantify these sudden visual movements allows you to locate the root cause and implement lasting technical fixes.

What Is Cumulative Layout Shift (CLS) and How Is It Scored?

CLS scores the largest burst of unexpected layout shifts that occur during the lifecycle of a page. Rather than summing every shift indefinitely, the browser groups consecutive movements into distinct session windows. A session window groups layout shifts that occur within 1 second of each other, up to a maximum total window duration of 5 seconds. The single worst-performing window determines the final score.

According to official standards in the web.dev visual stability guide, layout stability thresholds are defined as follows:

  • Good: 0.1 or less (evaluated at the 75th percentile of page visits across mobile and desktop devices separately).
  • Needs Improvement: Greater than 0.1 and up to 0.25.
  • Poor: Greater than 0.25.

The browser's Layout Instability API, documented in the MDN LayoutShift documentation, calculates individual layout shift scores using two core metrics:

Layout shift score = Impact fraction × Distance fraction

  • Impact Fraction: Measures the total viewport area affected by the unstable elements across two consecutive rendered frames. For example, if an element occupying 50% of the viewport shifts downward by 25% of the viewport height, the combined visual area affected is 75% of the viewport, resulting in an impact fraction of 0.75.
  • Distance Fraction: Measures the greatest vertical or horizontal distance that unstable elements moved relative to the largest viewport dimension. In the example above, if the viewport height is the largest viewport dimension, moving 25% of that height yields a distance fraction of 0.25.

Multiplying an impact fraction of 0.75 by a distance fraction of 0.25 produces a layout shift score of 0.1875 for that single movement—placing it well into the "Needs Improvement" range on its own.

Diagram illustrating impact fraction multiplied by distance fraction to calculate layout shift score

Layout shifts that occur within a 500-millisecond grace period following direct user interactions—such as tapping a button, clicking a link, or typing into a field—are marked as expected and excluded from CLS scoring. However, if a user interaction triggers an asynchronous network request that updates the screen after that 500ms window expires, any subsequent movement will be scored against CLS. Maintaining quick responsiveness alongside visual stability is also vital for related Core Web Vitals such as INP.

Why Does Cumulative Layout Shift (CLS) Differ in Lab Tools vs. Field Data?

A default Lighthouse navigation audit evaluates one simulated page load under fixed network constraints. Lighthouse user-flow and timespan testing can also capture interactions and activity beyond that initial navigation. In contrast, field data from the Chrome User Experience Report (CrUX) captures layout shifts across the entire lifecycle of real visits, including user scrolling, delayed script execution, and post-load dynamic injections.

Several factors cause field metrics to diverge from lab audits:

  • Aggregated Rolling Windows: Google Search Console and CrUX aggregate field data over a rolling 28-day window. When you deploy a code update, historical field data takes up to 28 days to fully reflect the resolution. You can track this transition by tracking real-world metrics in CrUX dashboard reports.
  • Post-Load and Scroll Triggers: A default navigation audit may not reproduce every interaction or delayed change that happens during a real visit, including behavior beyond the above-the-fold area. User-flow and timespan lab testing can investigate scrolling, lazy-loaded scripts, sticky widgets, dynamic ads, and late-rendered elements more directly.
  • Device and Network Variation: Real users browse on diverse mobile hardware and variable cellular connections. Slow network responses can cause font downloads or asynchronous scripts to resolve long after the initial paint, causing late layout shifts.

How Do You Identify the Root Causes of Visual Shifts?

To diagnose visual instability, record a performance trace in Chrome DevTools and review the current Layout Shifts track while reproducing the page behavior. DevTools marks unexpected movements along that track. Clicking a marker reveals the exact DOM elements that shifted, their shift score, and whether the movement occurred inside or outside the 500ms user input window.

The following decision table outlines the most frequent root causes of layout shifts, their symptoms, and the corresponding technical remedies:

Root Cause Diagnostic Symptom Remediation Strategy
Unsized Images & Videos Surrounding text snaps downward when media renders Add explicit width and height HTML attributes or declare CSS aspect-ratio
Dynamic Ad Containers Content jumps when ad scripts inject multi-size creatives Apply CSS min-height and min-width to wrapper elements matching top creative sizes
Web Font Swapping Text changes size or wraps differently upon custom font load (FOUT/FOIT) Preload critical typefaces and configure font-display: optional or font metric overrides
Injected Banners & Notices Cookie notices or notification bars push down the page header Reserve layout container height or render notices as non-displacing overlay layers
Client-Side Rendering Components pop into the DOM after client hydration completes Pre-allocate UI layout skeletons and stabilize client-side Rendering

5 Simple Steps to Fix Layout Instability and Validate Results

Web performance engineering workflow showing DevTools performance inspection and code adjustments

Eliminating layout shifts requires a systematic approach to resource sizing, asset loading, and DOM updates. Follow these five steps to stabilize page elements and systematically improve your visual stability metrics across your website.

What Are the 5 Steps to Eliminate Layout Shifts Across Your Site?

Step 1: Specify Explicit Dimensions for All Images and Videos

Always supply numeric width and height attributes directly on img and video elements. Modern browsers calculate the aspect ratio before the asset downloads, allowing the layout engine to reserve the exact vertical space in the DOM. Pair dimension attributes with fluid CSS styling—such as setting max-width to 100% and height to auto—to ensure media remains fully responsive without collapsing.

For responsive art direction, provide appropriate dimensions for the selected image sources and keep the img element sized consistently. For custom containers, declare a CSS aspect-ratio property, such as aspect-ratio: 16 / 9, directly on the media container.

Step 2: Reserve Space for Dynamic Ads, Embeds, and Iframes

Asynchronous third-party embeds, programmatic ad units, and social media widgets often load without predefined dimensions, displacing surrounding text once they render. Prevent this movement by setting CSS min-height and min-width on the parent container wrapper based on your most frequent historical creative sizes.

Avoid collapsing empty ad containers if an ad impression goes unfilled. Collapsing the container introduces a secondary layout shift that penalizes your score just as heavily as an expanding shift.

Step 3: Prevent Font-Induced Shifts (FOUT and FOIT)

When fallback system fonts render before custom web fonts download, differences in character widths, ascent, and descent can reflow entire paragraphs—two distinct behaviors: Flash of Unstyled Text (FOUT), where fallback text is visible before the custom font loads, and Flash of Invisible Text (FOIT), where text remains invisible while the font loads.

To resolve font reflow:

  1. Preload Critical Fonts: Add a preload link directive for your primary web font file in your document head.
  2. Use Font Display Controls: Configure @font-face { font-display: optional; } in your stylesheet to tell the browser to render the fallback font permanently if the custom font does not load immediately.
  3. Apply Font Metric Overrides: Use CSS properties such as size-adjust, ascent-override, and descent-override on fallback @font-face declarations to match fallback dimensions directly to your custom typography.

Step 4: Stabilize Dynamic Notifications, Modals, and Animations

Banners, cookie consent alerts, and promotional ribbons inserted at the top of the viewport push down the entire document structure. Instead of injecting dynamic elements above rendered content:

  • Pre-allocate a fixed height container in your template for notification bars.
  • Position dynamic cookie consent dialogs and promotional notices as floating overlays using fixed or absolute positioning so they sit above page content without reflowing the DOM.
  • Build animations using GPU-accelerated CSS properties like transform (e.g., transform: translate() or transform: scale()) and opacity rather than animating layout-triggering properties such as top, left, width, or height.

Implementing stable UI components is particularly crucial for maintaining engagement on mobile devices, reinforcing responsive techniques for mobile shoppers without sudden visual disruptions during checkout flows. When managing resource-heavy media below the viewport, combine these containers with native Lazy Loading to defer offscreen assets cleanly.

Step 5: Preserve History Navigation Layout with the Back/Forward Cache

When visitors navigate between pages using browser back and forward buttons, re-executing scripts from scratch can cause elements to shift repeatedly. Ensuring your pages are eligible for the browser's Back/Forward Cache (bfcache) allows the browser to restore the rendered page snapshot instantly from memory, helping prevent unexpected layout shifts during historical navigations.

Infographic summary showing the 5 technical steps to eliminate Cumulative Layout Shift infographic

How Do You Test, Validate, and Monitor Scores Over Time?

Once you implement layout stability fixes, validate your code across multiple environments before confirming site-wide performance health:

  1. Perform Local Validation: Record a trace in the Chrome DevTools Performance panel to verify that purple layout shift markers have been eliminated across standard page interactions and scrolling.
  2. Conduct Synthetic Audits: Run a Lighthouse audit to verify that initial load dimensions, aspect ratios, and font preloads pass programmatic checks.
  3. Log Shifts Programmatically: Implement a lightweight PerformanceObserver script in staging environments to capture un-dimensioned elements before code hits production.
  4. Monitor 28-Day Field Aggregation: Monitor the Core Web Vitals report in Google Search Console over a full 28-day cycle to ensure real-user field data reflects your technical improvements.

SmallBizSEO can help prioritize CLS issues, document shifting DOM nodes, and coordinate clear handoffs with development teams. Ongoing technical checks can sit alongside content refreshes and relevant link-building work in a broader SEO program, while CLS fixes remain focused on the page templates, assets, and scripts that cause visual movement.

Achieving Predictable Visual Stability

A Cumulative Layout Shift score of 0.1 or lower is the recommended field-data target at the 75th percentile, but it does not guarantee that no visitor will ever see a layout shift. By assigning explicit HTML dimensions, reserving ad space with CSS minimum heights, matching font metrics, and animating strictly on the compositor layer, you can create a reliable, visually stable browsing experience.

For a definition of the metric, see the CLS glossary. If field reports show persistent visual instability, explore technical SEO services, SEO content services, and link-building services as part of a coordinated SEO program. To discuss priorities for your site, book a consultation.