Sign inTry Now

What does 'Cumulative Layout Shift (CLS) Needs Improvement' mean in Site Audit?

Cumulative Layout Shift (CLS) Needs Improvement

Description

The page's Cumulative Layout Shift (CLS) score needs improvement, which may affect user experience.

How to Fix

Set size attributes for images and videos, avoid inserting content above existing content, use transform animations instead of animations that trigger layout changes.

Detailed Analysis

1. What Causes the Cumulative Layout Shift (CLS) Issue

Cumulative Layout Shift (CLS) is a metric that quantifies how much the content of a webpage unexpectedly shifts during the loading phase. This issue is primarily caused by:

  • Images without Dimensions: When images don’t have specified dimensions (width and height), the browser doesn’t know how much space to reserve for them, causing content to shift as images load.

  • Ads, Embeds, and Iframes without Dimensions: Similar to images, ads and embedded elements without defined dimensions can cause significant layout shifts when they load or resize dynamically.

  • Dynamically Injected Content: Adding content to the DOM (Document Object Model) via JavaScript or other means after the initial render can cause shifts if not handled properly.

  • Web Fonts Causing FOUT/FOIT: Flash of Unstyled Text (FOUT) or Flash of Invisible Text (FOIT) occurs when web fonts load, causing text to shift or change appearance suddenly.

  • Actions Waiting for Network Response: Elements that wait for a network response before being rendered can cause shifts if placeholders or expected dimensions aren’t set.

2. Why It's Important

Cumulative Layout Shift is a crucial metric for user experience and has been incorporated into Google's Core Web Vitals, which impact search rankings:

  • User Experience: Layout shifts can lead to poor user experience as they may cause users to lose their place on the page, click the wrong buttons, or become frustrated.

  • Accessibility: Unexpected shifts can be particularly problematic for users with disabilities, who may rely on assistive technologies to navigate content.

  • Conversion Rates: A stable and predictable layout is critical for maintaining high conversion rates on e-commerce sites or any site where user interaction is key.

3. Best Practices to Prevent CLS

To minimize CLS, consider the following best practices:

  • Set Explicit Dimensions: Always set width and height attributes for images, videos, and other media. Use aspect ratio boxes where necessary to maintain space.

  • Reserve Space for Ads: Allocate a specific area for ads, and avoid placing ads in a way that causes significant shifts. Implement placeholder elements if ads are dynamically loaded.

  • Load Fonts Early: Use the font-display CSS property to control how text is rendered while web fonts are loading. Prefer font-display: optional or font-display: swap to minimize FOIT/FOUT impacts.

  • Use CSS for Animations: Prefer CSS transform animations over animations that modify layout properties (like width or height), as these are more performant and less likely to cause shifts.

  • Avoid Inserting Content at the Top: When adding new content, do so at the end of the page or container, or ensure that space is reserved for it to prevent shifts.

4. Examples of Good and Bad Cases

Good Example:

  • Properly Sized Images: An online article includes images for each section with properly defined dimensions. As the page loads, the text and images load smoothly without shifting.

  • Reserved Ad Space: A news website reserves a 300x250 pixel space for ads, ensuring that the layout remains stable even when the ads are loaded asynchronously.

Bad Example:

  • Images Without Dimensions: A blog post with multiple images loads, and as each image loads, the text jumps around, making it difficult to read.

  • Dynamic Content Injection: A homepage dynamically loads a promotional banner above existing content, causing the entire page to shift downwards, frustrating users who are in the middle of reading or interacting with content below.

In summary, addressing CLS involves a combination of technical adjustments and strategic planning to ensure a stable and user-friendly experience, which in turn can positively influence SEO and user retention.