Cumulative Layout Shift (CLS) is the latest addition to the web performance metrics known as the Core Web Vital that measures the stability of a website. CLS is defined as the sum of all individual layout shift scores for every unexpected layout shift that occurs during the entire lifespan of a page.
In simpler terms, CLS is a measurement of how often users are visually disturbed by sudden shifts in page elements while they are interacting with a website.
The importance of Cumulative Layout Shifts in web performance metrics cannot be overstated. With the increasing usage of mobile devices, the need for a stable, fast, and responsive website has never been more important.
CLS is a crucial metric that measures the user experience, and a high Cumulative Layout Shift score can negatively impact user satisfaction and loyalty. A website with a high CLS score is often perceived as unreliable and untrustworthy, and users are less likely to return to such a website.
The purpose of this blog post is to provide a comprehensive overview of Cumulative Layout Shift, its cause, and the best ways to fix it. We will explore the key concepts of CLS and provide actionable tips for website owners and developers to improve the performance of their websites.
What is the Core Web Vital?
Core Web Vitals metrics are a set of metrics defined by google that measure the quality of user experience on websites. They include 3 main aspects: loading speed, interactivity, and visual stability the Core Web Vitals metrics are:
Largest Contentful Paint (LCP)
First Input Delay (FID)
Cumulative Layout Shift (CLS)
Largest Contentful Paint (LCP) is a web performance metric that measures the loading performance of a page. It specifically measures the time taken for the largest element visible within the viewport ( such as an image or text block ) to fully load and become visible to the user. LCP is one of the three Core Web Vital metrics.
First Input Delay (FID) is a critical performance metric that measures the responsiveness of a website, it is the time between when a user first interacts with a page (such as clicking a link) and when the browser is able to respond to that interaction.
CLS is a new performance metric that measures the visual stability of a website. It calculates the sum of all individual layout shifts that occur during the entire lifespan of a page. The layout shift score is calculated based on the impact fraction and distance fraction.
The layout shift score is the product of these two fractions, and the Cumulative Layout Shift score is the sum of all layout shift scores for a given page.
Impact fraction is a metric used to measure the impact of a layout shift on the user experience. It is defined as the size of the layout shift divided by the viewport size, a layout shift is considered more impactful if the impact fraction is higher.
It’s a metric used to measure the impact of a layout shift on the user experience, it is defined as the size of the layout shift divided by the viewport size. A layout shift is considered to be more impactful if the distance fraction is higher as this means that the element that shifted took up a larger portion of the viewport.
In essence, the impact fraction and the distance fraction are two different ways of measuring the same thing which is the impact of layout shift on the user experience.
The method of calculating both is the same that is by dividing the size of the layout shift by the viewport size.
Cumulative Layout Shift (CLS) is caused by an unexpected shift in page elements, such as images, videos, advertisements, and text. These shifts can occur when the website’s content is not properly sized, loaded, or managed. For example, if an image is not properly loaded and its size changes, the text below it will suddenly shift, causing a layout shift. This type of shift is unexpected and can be frustrating for users, particularly if it occurs repeatedly.
One common example of CLS is when a website loads a large advertisement or an image, causing text to suddenly shift. This shift causes users to lose their place on the page and became frustrated with the website. Another example of CLS is when a website loads a video or an image and its size changes after it has been loaded, causing the page to shift. This type of shift can be especially frustrating for users who are trying to interact with the page, such as scrolling or clicking a link.
See more: Compressing Images for the Modern Web
Cumulative Layout Shift (CLS) is measured using the chrome user experience report (CrUX) dataset, which provides real-world performance data for millions of websites. The data is collected by google chrome and aggregated to provide a CLS score for each website. The score ranges from 0 to 1, with a higher score indicating a higher degree of layout shift. A score of 0 means that there was no layout shift during the entire lifespan of the page, while a score of 1 means that there was a constant layout shift throughout the entire lifespan of the page.
A good CLS score is considered to be 0.1 or lower. A Cumulative Layout Shift score of 0.1 or lower means that the layout of a website is relatively stable, with minimal unexpected shifts as the page loads and as users interact with it.
It is important to note that achieving a CLS score of 0.1 is very difficult, as some elements of a page can be out of the control of the developer. However, keeping the CLS score as low as possible is the best practice for improving the user experience and increasing the overall quality of a website
Reducing CLS requires a combination of technical and design best practices. Some of the best practices for reducing Cumulative Layout Shift include:
By reserving the space where images and videos will appear, you can prevent unexpected layout shifts and ensure that the page remains stable.
Lazy loading images is a technique where images are only loaded when they become visible on screen, rather than being loaded all at once when the page is loaded. This reduces the amount of data that needs to be loaded and reduces the chance of unexpected layout shifts.
One of the simplest and most effective ways to reduce Cumulative Layout Shifts is to specify image dimensions on your website. When you specify the dimensions of an image, the browser knows exactly how much space the image will take up and can reserve that space ahead of time.
This prevents unexpected layout shifts caused by images loading at different times or sizes than expected.
Web Font can also cause unexpected layout shifts, especially if they take a long time to load, by using font-display: swap, you can specify how the browser should handle a custom font loading. This can help reduce or eliminate layout shifts caused by fonts, as the browser will use a fallback font until the desired font has loaded
Ads and third-party scripts can also contribute to Cumulative Layout Shifts, as they can take a long time to load and cause unexpected layout shifts. Minimizing the use of these elements, or lazy loading them, can help reduce the impact they have on CLS.
Additionally, you can use tools like ad blockers to block google ads or content delivery networks (CDNs) to optimize the performance of ads and third-party scripts on your website.
Finally, it’s important to regularly test and monitor your Cumulative Layout Shift score to ensure that it remains low. You can use tools like PageSpeed Insights. Lighthouse or WebPageTest to evaluate your website’s Cumulative Layout Shift score, you can use the techniques discussed above to continuously improve it. Regular testing and monitoring will help you stay on top of CLS and provide a better user experience for your visitors.
Font display is a CSS property that determines how the browser should handle the loading and display of web fonts. It gives you control over how the font is displayed on the web page, specifically in the event that the font file has not yet been fully loaded
There are several tools that you can use to measure your website’s Cumulative Layout Shift score and identify potential causes of layout shifts. Some of the most popular tools include:
This tool provides a detailed analysis of your website’s performance, including the CLS score.
This tool is built into the google chrome dev tool and provides a detailed analysis of your website’s performance, including the CLS score.
this tool provides a detailed analysis of your website’s performance, including its Cumulative Layout Shift score, and allows you to test your website on various devices and connection speeds.
It is a tool that helps to identify and diagnose layout shift issues on a website. It provides information about the elements on a page that are causing layout shifts and can help to pinpoint the root cause of the problem
Apart from these tools, there are various other tools like layout instability API that would allow developers to access information about the layout stability of a website, including Cumulative Layout Shift score, as well as specific details about the elements that are causing layout shifts.
Fixing CLS on your website involves following a set of steps to identify the cause of layout shifts and implement solutions to reduce or eliminate them. The steps include :
Using one of the above-mentioned tools measure the Cumulative Layout Shift score of your website and analyze the causes of layout shifts.
Analyze the results of your Cumulative Layout Shift score and identify the element on your website that are causing layout shifts. This can be images, videos, advertisements, or text.
Test your website after implementing the solutions and iterate if necessary to further improve its CLS score.
WordPress is the most popular content management system in the world, and many websites are on this platform. CLS can affect WordPress websites in the same way that it affects other websites. This is because CLS is not dependent on the platform or technology used to build a website but rather on the design and implementation of the website itself. Unexpected layout shifts can occur when images and videos are not properly loaded or managed, or when advertisements are inserted into the page.
Therefore WordPress website owners should be mindful of Cumulative Layout Shifts and take steps to reduce them, just as they would for any other type of website.
There are several plugins that can help you fix Cumulative Layout Shifts on your website. One of the best among them is RabbitLoader, one of the key features of RabbitLoader is its ability to load images and videos in a visually appealing way, with a loading animation that minimizes the impact of slow-loading content.
This helps to reduce frustration for users and improves their overall experience on your website.
In addition to its lazy loading capabilities, RabbitLoader also allows you to control the loading behavior of a specific element on your website.
For example, you can specify which images should be loaded first, which should be deferred, and which should be skipped altogether. This fine-tuned control over the loading behavior of your website’s content can help you significantly improve its CLS score.
Overall. It is a powerful and flexible plugin that can help you fix Cumulative Layout Shifts on your WordPress website. By lazy loading content and providing fine-tuned control over the loading behavior of specific elements, RabbitLoader can help you reduce or eliminate unexpected layout shifts and provide a better user experience for your visitors
WordPress is a popular website-building platform used by many to create and manage websites, one of the key features of WordPress is its ease of use. It is also highly customizable and scalable making it a good choice for making websites of any size and type.
In WordPress, a plugin is a small software that can be added to a website to add a specific feature or functionality. Plugins are designed to work seamlessly with the WordPress platform and can be easily installed and activated from the WordPress plugin repository or from other sources.
In conclusion, Cumulative Layout Shift (CLS) is an important metric for website performance and user experience. Unexpected layout shifts can be frustrating for users and can lead to a poor experience.
By understating what CLS is and how it affects your website, you can take steps to reduce or eliminate layout shifts and improve your website’s performance. By using tools to measure your CLS score like google search console, identifying the cause of Large Layout Shifts, and implementing solutions to reduce or eliminate them, you can significantly improve your website’s CLS score and provide a better experience for your visitors