Skip to content

CLS Causes


Cumulative Layout Shift (CLS) is a critical Core Web Vitals metric that quantifies how much a page's layout shifts during and after load. A high CLS score indicates unstable layouts, where elements unexpectedly move as the page renders, leading to a frustrating user experience. This section explores the primary causes of CLS and its impact on user trust and business outcomes.


Common Causes of CLS

1. Dynamically Loaded Images

Images without explicit dimensions can cause layout shifts as they load. For example, an image placed in a container with no width or height will initially render as a 1x1 pixel placeholder, then expand once the image loads.

Example:

<!-- Bad: No explicit dimensions -->
<img src="example.jpg" alt="Example" />

Fix: Set width and height attributes or use CSS to define dimensions:

<!-- Good: Explicit dimensions -->
<img src="example.jpg" alt="Example" width="300" height="200" />

2. Font Loading

Fonts not specified with a fallback can cause text to reflow when they load. For instance, using a custom font without a font-display directive may result in a layout shift as the font renders.

Example:

/* Bad: No font-display */
@import url('https://example.com/roboto.woff2');
body {
  font-family: 'Roboto', sans-serif;
}

Fix: Use font-display: swap to show a fallback font immediately:

/* Good: font-display: swap */
@import url('https://example.com/roboto.woff2') format('woff2');
body {
  font-family: 'Roboto', sans-serif;
  font-display: swap;
}

3. Third-Party Tags

Scripts from third-party services (e.g., analytics, ads) often load asynchronously and inject elements into the DOM. These elements may have unpredictable sizes or be inserted after the initial layout, causing shifts.

Example:

<!-- Bad: Async script inserts elements -->
<script async src="https://third-party.com/analytics.js"></script>

Fix: Use defer for non-critical scripts or load third-party tags after the main content:

<!-- Good: Defer non-critical scripts -->
<script defer src="https://third-party.com/analytics.js"></script>

4. Unexpected Content Insertion

Dynamic content (e.g., ads, social media widgets) added after the initial load can shift existing elements. For example, a widget inserted into a sidebar may push content below it downward.

Example:

// Bad: Dynamically inserting content
document.body.innerHTML += '<div id="ad">Ad content</div>';

Fix: Reserve space for dynamic content in the initial layout or use placeholders:

<!-- Good: Reserve space with placeholder -->
<div id="ad-placeholder" style="height: 50px;"></div>


Impact on User Trust

High CLS scores correlate with reduced user trust and engagement. When layouts shift unpredictably, users may: - Struggle to interact with buttons or links (e.g., clicking a "Buy Now" button that moves after the click). - Perceive the site as unprofessional or unreliable. - Experience cognitive load from reorienting themselves on the page.

Studies show that pages with poor CLS scores have 30% higher bounce rates and 20% lower conversion rates compared to pages with optimal CLS, according to Google's research and Lighthouse reports. This directly impacts business metrics like revenue and user retention.


Key takeaways

  • CLS is a critical indicator of layout stability, driven by dynamic content, fonts, and third-party scripts.
  • Explicit dimensions for images and font-display directives prevent unnecessary shifts.
  • Third-party tags should be deferred or loaded after the main content to avoid layout disruptions.
  • Poor CLS erodes user trust, leading to higher bounce rates and lower conversions.
  • Proactive optimization (e.g., reserving space for dynamic content) ensures a seamless user experience.