Top Tips to Reduce Cumulative Layout Shift (CLS) and Enhance User Experience
Welcome to our comprehensive conversation on Cumulative Layout Shift (CLS). In this blog, you'll learn what CLS is, why it matters for your website's user experience and SEO, and how to measure and improve it effectively. We'll explore the common causes of layout shifts, such as dimensionless images, custom fonts, and embedded content, and provide practical tips and tricks to minimize these disruptions. Additionally, we'll introduce you to essential tools and resources to help you monitor and enhance your CLS score, ensuring your website delivers a smooth and stable experience for all users. Let's dive in and optimize your website for better performance and higher search engine rankings!
What is Cumulative Layout Shift (CLS)?
Have you ever been just about to click a link on a website, when everything on the page shifts and you click on an ad instead? This is called a layout shift, which occurs when an element on your page changes its position or size, affecting the content around it. Let’s delve into how these shifts impact the user experience, and how we can improve them!
The Rundown.
Cumulative Layout Shift (CLS) is a metric used to quantify how often webpage users experience layout shifts as a page loads or is interacted with. Google introduced CLS as one of the three Core Web Vitals to enhance user experiences. Layout shifts can happen for various reasons, such as asynchronous content loading or third-party widgets resizing themselves as the page loads. The lower your CLS score, the better the user experience is.
Aim for a CLS score of 0.1 or less. Scores above 0.25 are considered poor, necessitating optimization of these underperforming web pages.
For mobile users, layout shifts on smaller screens cause bigger movements. Hence, there are separate CLS scores for both mobile and desktop views to ensure both perform at high levels.
How Do We Measure CLS?
The formula for a layout shift score is:
Layout Shift Score = Impact Fraction x Distance Fraction
Instead of calculating these elements yourself, diagnose your site using Google’s Core Web Vitals report in Google Search Console. This tool allows you to see which mobile and desktop URLs need improvement or are performing well.
How Can We Improve CLS?
Now that you understand the basics of CLS, let’s explore factors that can drastically affect your score and tips to improve them.
1. Dimensionless Images
Dimensionless images have no specific width or height, so the browser does not hold any space for these images on the page. After the images load, they can disrupt the page layout, causing unwanted shifts.
Tip: Always use images with specified width and height attributes to reserve space for them on the page.
2. Fonts
Websites often use custom fonts instead of default browser fonts, which can cause significant layout shifts as the custom fonts load.
Tip: Preload your fonts to give font assets higher priority in page rendering. Hosting fonts from your own domain can also reduce delays from third-party domains. While custom fonts are essential for branding, these methods can help minimize shifts.
3. Embedded Content
Embedding content like Instagram posts or YouTube videos can cause layout shifts similar to dimensionless images and ads.
Tip: Reserve space for embedded content by inspecting it to determine its final height and width, and allocate space accordingly.
Additional Tips and Tricks.
Minimize Third-Party Scripts: Third-party scripts can introduce unexpected layout shifts. Use them sparingly and ensure they are optimized.
Avoid Late Loading Elements: Elements that load late can push existing content down. Make sure all essential content loads early.
Use Transform Properties for Animations: When animating elements, use CSS transform properties instead of changing width or height to avoid layout shifts.
Tools and Resources.
Google Search Console: Use the Core Web Vitals report to monitor CLS and other performance metrics.
Lighthouse: Google Lighthouse provides detailed insights into page performance, including CLS.
WebPageTest:
This tool allows you to test your website's performance and provides specific recommendations to improve CLS.
What Does This Mean for SEO?
CLS impacts SEO because Google prioritizes websites with good user experiences. A poor CLS score can negatively affect keyword rankings and overall SEO performance. High CLS scores are correlated with higher bounce rates and shorter session lengths, reducing the likelihood of users returning to your site.
CLS accounts for 5% of the weighted metrics in Google Lighthouse scoring. While not the most critical factor, creating pages that promote a positive, stable, and smooth user experience is essential. Keep this key metric in mind as you develop and reconfigure your website for optimal SEO performance.
Conclusion.
Improving CLS is crucial for enhancing user experience and maintaining strong SEO performance. By addressing dimensionless images, preloading fonts, reserving space for embedded content, and utilizing various tools, you can significantly reduce layout shifts and create a more stable and enjoyable browsing experience for your users.