In recent years, user experience has become increasingly important for search engine optimization (SEO). One aspect of user experience that has gained attention is Cumulative Layout Shift (CLS). In this blog post, we will explore what CLS is, why it matters for SEO, and how to optimize your website to minimize CLS.
Table of Contents
What is Cumulative Layout Shift (CLS)?
Cumulative Layout Shift (CLS) is a metric used to measure the stability of a webpage’s visual layout. CLS occurs when the content of a webpage shifts unexpectedly as it loads. This can happen when a page’s content is loaded asynchronously or when the size of elements on the page changes as they load. CLS is measured by calculating the sum of all layout shift scores that occur during the loading of a webpage.
Why does CLS matter for SEO?
Google has announced that it will begin using Core Web Vitals, including CLS, as a ranking factor starting in May 2021. This means that websites with high CLS scores may see their search engine rankings drop. In addition to the impact on SEO, CLS can also have a negative impact on user experience. When content on a page shifts unexpectedly, it can be difficult for users to navigate and interact with the page.
The Top Causes of a Poor Cumulative Layout Shift (CLS) Score
- Images and Videos without Dimensions: One of the most common causes of a poor CLS score is images and videos without specified dimensions. This causes the browser to allocate space for the content only after it has loaded, leading to unexpected shifts in the layout.
- Ads and Pop-ups: Ads and pop-ups that load after the content of the webpage can cause unexpected shifts in the layout. It is recommended to avoid using ads that dynamically inject content.
- Third-Party Scripts and Iframes: Third-party scripts and iframes can also cause unexpected shifts in the layout. It is important to ensure that all resources on the page are loaded asynchronously and use a Content Delivery Network (CDN) to speed up content delivery.
- Font Loading: The delay in loading custom fonts can cause a layout shift when the browser switches to a fallback font. It is recommended to use the “swap” value for the CSS font-display property to prevent this.
- Lazy Loading: Lazy loading of images can also cause unexpected shifts in the layout. It is recommended to use the “loading” attribute for images to prevent layout shifts.
- Images and Videos without Dimensions
- Ads and Pop-ups
- Third-Party Scripts and Iframes
- Font Loading
- Lazy Loading
How to optimize your website for CLS ?
Here are some tips for optimizing your website to minimize CLS:
- Use size attributes for images and videos: By specifying the size of images and videos, the browser can reserve the necessary space for them, preventing unexpected shifts as they load.
- Avoid using ad slots that dynamically inject content: This type of content can cause unexpected shifts on the page, so it is best to avoid using them.
- Load web fonts using the “swap” value for the CSS font-display property: This will ensure that text remains visible while the font loads, preventing unexpected shifts.
- Ensure that all resources on the page are loaded asynchronously: This will prevent the page from loading content out of order, which can cause unexpected shifts.
- Use a Content Delivery Network (CDN): A CDN can speed up the delivery of content, reducing the likelihood of unexpected shifts as content loads.
- Use size attributes for images and videos
- Avoid using ad slots that dynamically inject content
- Load web fonts using the “swap” value for the CSS font-display property
- Ensure that all resources on the page are loaded asynchronously
- Use a Content Delivery Network (CDN)
In conclusion, Cumulative Layout Shift (CLS) is an important metric for both SEO and user experience. By optimizing your website to minimize CLS, you can improve both the search engine rankings and the user experience of your website.