Improving Cumulative Layout Shift (CLS) for Better Page Experience

Have you ever found yourself frustrated while browsing a website, where sudden layout shifts disrupted your reading or navigating experience?

MiaDecember 18, 2023 & 14:15 [IST]

Cumulative Layout Shift (CLS)

The introduction of metrics like Cumulative Layout Shift (CLS) brings hope for a more stable and predictable user experience on websites. Let's delve deeper into CLS to comprehend its significance and strategies for improvement.

What is Cumulative Layout Shift (CLS)?

CLS revolves around the stability of a webpage and how predictable it is to use. All visible elements on a webpage such as images, text, and videos - form the layout. Whenever page contents alter, say due to ad insertions or image size modifications, existing elements might shift to accommodate the changes. These shifts are known as layout shifts.


Decoding CLS Metrics

CLS is measured as the percentage of the visible parts of a page that experience these layout shifts. For instance, if an image causes text on a page to shift down by 50% of the visible area, the CLS score would be 0.5 (50%).


Key Factors Affecting CLS

There are a few important things to note about CLS:

  • There can only be one CLS score for a page. If multiple layout shifts occur, they are accumulated into a single value.

  • User interactions like tapping, clicking, or typing, are allotted a grace period of 500 milliseconds for potential layout shifts.

  • Not all user interactions cause layout shifts; scrolling or mouse movements, for instance, aren't classified as layout shifts.

  • CSS animations or transforms don't contribute to CLS as they don't impact other page elements' layout.

  • CLS only accounts for visible elements; changes to non-visible elements don't influence the score.


What is the Good CLS Score?

An ideal CLS score is 0, implying no layout shifts. Realistically, achieving this perfect score isn't always feasible due to various constraints. Aiming for 75% or more of page views with a CLS score of 0.1 or below is a commendable target. Below this threshold indicates good performance, while anything above suggests areas for enhancement.


How to Measure CLS?

Measuring CLS involves accessing field data from real users. This data can be collected through your own analytics or through the Core Web Vitals report section of the Search Console. While Chrome User Experience Report (CrUX) determines the CLS score, it might take up to a month to collect and update the field data. In the interim, tools like Lighthouse or Chrome DevTools can provide lab data, which provides an estimate of how your page will perform in terms of CLS.

To gauge CLS post-launch, JavaScript and the Performance Observer API can track individual layout shifts and calculate CLS scores per user session. Utilizing resources like WebVitals.js aids in implementing CLS measurements on websites.


Improving CLS Scores

Elevating CLS involves addressing common triggers of layout shifts:


1. Images without Inline Dimensions

One common cause of layout shifts is images that don't have inline dimensions specified. When an image without a width or height attribute is loaded, it can cause the page content to jump once the image's dimensions are determined. It is best to explicitly include the width and height attributes for images to prevent this shift. Modern browsers automatically adjust the size based on aspect ratio, allowing for responsive design while preventing layout shifts.


2. Iframes and Embeds without Inline Dimensions

Similar to images, iframes and embeds (such as ad slots or video players) can cause layout shifts if their dimensions are not explicitly specified. By setting explicit heights and widths for the parent element of iframes and embeds, you can reserve space for them and prevent layout shifts. Additionally, consider using the "overflow: hidden" CSS property to avoid unexpected overflow in the parent container.


3. Dynamically Loaded Content

If your website includes dynamically loaded content, such as infinite scrolling lists or lazy loaded images, it is essential to reserve space for this content with explicit dimensions. By setting explicit heights and widths, you can prevent layout shifts caused by the delayed loading of content.


4. Web Fonts and Icon Fonts

Web fonts and icon fonts can also contribute to layout shifts. To mitigate this, consider using SVGs instead of icon fonts, as they provide greater design flexibility and fewer compatibility issues. For web fonts, optimize their loading by preloading essential fonts and using the "font-display: optional" CSS property to prioritize rendering the fallback font if the web font takes too long to load.


Conclusion

CLS stands as a pivotal metric for assessing webpage stability and user predictability. By addressing the causes of layout shift such as images, iframes, dynamic content, and fonts, website owners can enhance CLS scores, providing users with a smoother browsing experience. Aim for a CLS score of 0.1 or less for at least 75% of page views, continually measuring and refining your approach to ensure an optimized user experience.


The introduction of metrics like Cumulative Layout Shift (CLS) brings hope for a more stable and predictable user experience on websites. Let's delve deeper into CLS to comprehend its significance and strategies for improvement.

What is Cumulative Layout Shift (CLS)?

CLS revolves around the stability of a webpage and how predictable it is to use. All visible elements on a webpage such as images, text, and videos - form the layout. Whenever page contents alter, say due to ad insertions or image size modifications, existing elements might shift to accommodate the changes. These shifts are known as layout shifts.

Decoding CLS Metrics

CLS is measured as the percentage of the visible parts of a page that experience these layout shifts. For instance, if an image causes text on a page to shift down by 50% of the visible area, the CLS score would be 0.5 (50%).

Key Factors Affecting CLS

There are a few important things to note about CLS:

  • There can only be one CLS score for a page. If multiple layout shifts occur, they are accumulated into a single value.

  • User interactions like tapping, clicking, or typing, are allotted a grace period of 500 milliseconds for potential layout shifts.

  • Not all user interactions cause layout shifts; scrolling or mouse movements, for instance, aren't classified as layout shifts.

  • CSS animations or transforms don't contribute to CLS as they don't impact other page elements' layout.

  • CLS only accounts for visible elements; changes to non-visible elements don't influence the score.

What is the Good CLS Score?

An ideal CLS score is 0, implying no layout shifts. Realistically, achieving this perfect score isn't always feasible due to various constraints. Aiming for 75% or more of page views with a CLS score of 0.1 or below is a commendable target. Below this threshold indicates good performance, while anything above suggests areas for enhancement.

How to Measure CLS?

Measuring CLS involves accessing field data from real users. This data can be collected through your own analytics or through the Core Web Vitals report section of the Search Console. While Chrome User Experience Report (CrUX) determines the CLS score, it might take up to a month to collect and update the field data. In the interim, tools like Lighthouse or Chrome DevTools can provide lab data, which provides an estimate of how your page will perform in terms of CLS.

To gauge CLS post-launch, JavaScript and the Performance Observer API can track individual layout shifts and calculate CLS scores per user session. Utilizing resources like WebVitals.js aids in implementing CLS measurements on websites.

Improving CLS Scores

Elevating CLS involves addressing common triggers of layout shifts:

1. Images without Inline Dimensions

One common cause of layout shifts is images that don't have inline dimensions specified. When an image without a width or height attribute is loaded, it can cause the page content to jump once the image's dimensions are determined. It is best to explicitly include the width and height attributes for images to prevent this shift. Modern browsers automatically adjust the size based on aspect ratio, allowing for responsive design while preventing layout shifts.

2. Iframes and Embeds without Inline Dimensions

Similar to images, iframes and embeds (such as ad slots or video players) can cause layout shifts if their dimensions are not explicitly specified. By setting explicit heights and widths for the parent element of iframes and embeds, you can reserve space for them and prevent layout shifts. Additionally, consider using the "overflow: hidden" CSS property to avoid unexpected overflow in the parent container.

3. Dynamically Loaded Content

If your website includes dynamically loaded content, such as infinite scrolling lists or lazy loaded images, it is essential to reserve space for this content with explicit dimensions. By setting explicit heights and widths, you can prevent layout shifts caused by the delayed loading of content.

4. Web Fonts and Icon Fonts

Web fonts and icon fonts can also contribute to layout shifts. To mitigate this, consider using SVGs instead of icon fonts, as they provide greater design flexibility and fewer compatibility issues. For web fonts, optimize their loading by preloading essential fonts and using the "font-display: optional" CSS property to prioritize rendering the fallback font if the web font takes too long to load.

Conclusion

CLS stands as a pivotal metric for assessing webpage stability and user predictability. By addressing the causes of layout shift such as images, iframes, dynamic content, and fonts, website owners can enhance CLS scores, providing users with a smoother browsing experience. Aim for a CLS score of 0.1 or less for at least 75% of page views, continually measuring and refining your approach to ensure an optimized user experience.

LATEST POSTSView All
First Input Delay (FID)

Technical SEO

Improving First Input Delay (FID) for Better Page Experience

First impressions matter, especially when it comes to browsing websites or using apps. Delays in page responsiveness can be frustrating and hinder user experience.

Kathy December 19, 2023 & 14:10 [IST]

What is Largest Contentful Paint (LCP)

Technical SEO

Improving Largest Contentful Paint (LCP) for Better Page Experience

In today\'s digital realm, crafting an optimized web page is paramount for ensuring an excellent user experience. Among the critical factors influencing user satisfaction, page load time stands out prominently.

Mia December 15, 2023 & 17:55 [IST]

How to Drive Traffic in Google Discover

Technical SEO

Unlocking the Potential of Google Discover: Tips for Optimizing Your Website

Google Discover has emerged as a game-changer in the online sphere. Understanding its nuances is now pivotal to not just boosting your website\'s visibility but also driving higher traffic.

Kathy December 13, 2023 & 13:30 [IST]

How to Use Google Lighthouse for SEO and User Experience?

Technical SEO

How to Use Google Lighthouse for SEO and User Experience?

Online marketing requires two critical factors to stand out: Search Engine Optimization (SEO) and User Experience (UX). A website that ranks well on the search engines and offers an exceptional user experience is more likely to succeed.

Muthulakshmi Aruchamy November 24, 2023 & 13:00 [IST]

Everything You Need to Know About Core Web Vitals

Technical SEO

Everything You Need to Know About Core Web Vitals

Core Web Vitals is an important metric to focus when focusing on search engine ranking and traffic rate. In this article, we are about to discuss in detail about core web and its integrated data. It helps you to analyze how your website URL is and where it needs improvement.

Riya March 30, 2023 & 22:00 [IST]

Sitemap XML

Technical SEO

Sitemap XML: Everything You Need to Know

Sitemap act as a bridge to connect our web pages to Google. In general, search engines find websites in web browser through sitemap and get indexed with it to deliver at the time of user’s query. Though it seems simple, the work and efficiency of sitemap is important all the time. It maybe a new or long-running website, the continuous optimization is mandatory in this case.

Sophiya March 15, 2023 & 18:00 [IST]