Loado

A Deep Dive into Cumulative Layout Shift

Post Image

June 14, 2023

Max Barinov

Introduction to Cumulative Layout Shift (CLS)

Welcome to an exciting exploration of the world of Cumulative Layout Shift (CLS), a crucial metric in the sphere of website performance optimization. As front-end developers understanding and optimizing this factor can profoundly enhance the user experience and SEO outcomes of your site.

So, what exactly is CLS? In layman's terms, it's a metric that quantifies how much a webpage's content unexpectedly shifts around as it's being loaded. CLS is one of the Core Web Vitals, which are user-centered metrics that Google uses to assess the speed, responsiveness, and visual stability of a webpage.

Let's say a user starts reading an article, and suddenly, an image or ad loads up and pushes the text down. Or consider a scenario where a user tries to click a button, but just as they're about to do so, the button moves because another element loaded above it. These are examples of layout shifts, and they can be incredibly frustrating for users.

CLS aims to provide a numeric value to these annoyances, thus providing developers a target to aim for when they're optimizing their sites. The lower the CLS score, the less your site's layout shifts during page load, which results in a more stable and enjoyable user experience.

The Impact of CLS on User Experience and SEO

User experience and SEO are two sides of the same coin, with both deeply intertwined. Google's Core Web Vitals metrics are not just abstract technical concepts but have direct implications for how users interact with your website and how your site ranks on Google's search engine.

Cumulative Layout Shift, being one of the Core Web Vitals, plays a pivotal role in this dynamic. A high CLS score, indicating more significant layout shifts, can lead to user frustration. A user who cannot read an article or click a button because the layout keeps changing is likely to leave the site and may not return, leading to higher bounce rates and lower conversion rates.

On the SEO front, Google has made it clear that it considers Core Web Vitals, including CLS, as part of its ranking algorithm. Therefore, a website with a high CLS score may suffer from lower search rankings, leading to decreased organic traffic. Thus, optimizing CLS is not just about enhancing user experience; it's also a crucial aspect of SEO strategy.

Remember, a happy user is more likely to convert, and a website that delivers an excellent user experience is more likely to rank higher on search engine results. Therefore, it's essential to understand the factors influencing CLS and how to optimize them, which we will delve into next.

Core Elements Influencing CLS

There are several elements on your website that can contribute to a high CLS score. Let's dissect them and understand why they cause layout shifts:

  1. Images and videos without dimensions: When images or videos are inserted into a webpage without specified dimensions, the browser doesn't know how much space to allocate to them until they're fully loaded. This can cause the rest of the layout to shift as these elements load.

  2. Dynamically injected content:

    Content that's added to the page after the initial load, especially if it's inserted above existing content, can cause layout shifts. This often includes ads, but can also encompass things like banners or forms.

  3. Web Fonts causing FOIT/FOUT: The Flash of Invisible Text (FOIT) or Flash of Unstyled Text (FOUT) occurs when custom fonts are loaded, causing a shift in the layout.

  4. Actions waiting for a network response before updating DOM: Elements that need to load data before they're displayed can cause layout shifts if they push down existing content when they eventually appear.

Understanding these elements is the first step towards optimizing CLS, which we'll look at in the next section.

How to Measure CLS

Before jumping into the optimization process, it's essential to measure your site's current CLS score. After all, you can't improve what you don't measure. There are several ways to monitor your CLS:

  1. Chrome User Experience Report (CrUX): This public dataset of real-world Chrome user experiences can be queried to extract the CLS score for specific web pages.

  2. PageSpeed Insights: This tool provides a snapshot of your page performance, including the CLS score, using data from CrUX and lab data.

  3. Lighthouse: An automated tool for improving the quality of web pages, which includes CLS as one of its performance metrics.

  4. Chrome DevTools: DevTools Performance panel allows you to visualize layout shifts and helps identify the elements causing them.

  5. Real-user monitoring tools like Loado: These tools collect Core Web Vitals data, including CLS, directly from users' browsers, providing an accurate representation of real-world experiences.

Remember, CLS is a field metric, meaning it captures real-world user experiences. Thus, it's crucial to use tools that capture these experiences instead of just relying on lab data.

Actionable Strategies to Optimize CLS

Now that we've established a baseline for your site's CLS score, it's time to optimize. Here are some actionable strategies:

  1. Specify size attributes for images and videos: Ensure every image or video on your site has specified dimensions (width and height). This way, the browser knows exactly how much space to allocate for them even before they're fully loaded, preventing layout shifts.

  2. Preload key assets: Preloading can help speed up the load time of important assets, such as custom web fonts, reducing layout shifts.

  3. Avoid inserting content above existing content: Unless responding to a user interaction, avoid adding content dynamically above existing content, especially if it pushes content down.

  4. Use CSS aspect ratio boxes: This recent CSS feature allows you to reserve space for an element based on an aspect ratio, preventing layout shifts as content loads.

  5. Reserve space for ads: Make sure to allocate adequate space for ads and embeds ahead of time. You can use a placeholder or fallback if the size of the ad slot is unknown.

Implementing these strategies can have a profound impact on your site's CLS score, leading to a more stable user experience and, in turn, improved SEO.

Conclusion

Optimizing CLS is more than a technical task; it's a user-centric mission aimed at creating a seamless, frustration-free browsing experience. As front-end developers and tech leaders, taking the time to understand and optimize CLS can result in happier users, higher conversion rates, and better SEO outcomes.

Remember, in the digital world, every second and every pixel count. So get started on your CLS optimization journey today and step into a world of improved performance and superior user experiences.

References

  1. Google Developers. Cumulative Layout Shift (CLS).
  2. Sullivan, D. Google May 2020 Core Update. Google Search Central Blog.
  3. Google Developers. Optimize Cumulative Layout Shift.
  4. Google Developers. Chrome User Experience Report.
  5. Google Developers. Lighthouse.
  6. Google Developers. PageSpeed Insights.
  7. Google Developers. Measure Core Web Vitals.
  8. Sarah Chambers. Cumulative Layout Shift: What It Is and How to Measure It. HubSpot Blog.

Boost Your Website Performance

Setup performance monitoring in minutes and get insights in real-time.

No credit card required. Cancel anytime.

Learn more in our blog

No data available

Product

OverviewDocumentation

Follow Us

Twitter
Loado

© 2024 Loado. All rights reserved