Few things are as frustrating when you’re browsing a website as a page that shifts unexpectedly.
A popup appears out of nowhere. Content shifts while you’re reading. A button moves just as you’re about to click it.
Google dislikes these sudden changes too, since they hurt user experience. That’s why they introduced a metric called Cumulative Layout Shift (CLS) – it measures layout instability during the page rendering process.
What is Cumulative Layout Shift (CLS)?
CLS measures the largest burst of unexpected layout shifts over the life of a page. Shifts less than one second apart count toward the same “session window”, which can last up to five seconds. The highest total from any window is the page’s CLS.
Originally, CLS simply added up every shift. On long-lived pages, that total kept growing the longer someone stayed. That’s why Google switched to session windows in 2021.
As part of Core Web Vitals, CLS measures how visually stable a page is. To see what instability looks like, take a look at this video:
The video illustrates what an undesirable layout shift looks like. I’m sure many of you have dealt with similar situations.
The score for each shift depends on how much of the viewport it affects and how far the elements move. Because those shifts affect the user experience, CLS is one of the three Core Web Vitals, alongside:
- Largest Contentful Paint (LCP), which measures loading.
- Interaction to Next Paint (INP), which measures responsiveness and replaced FID in March 2024.
As always, it’s important to note that the goal is to achieve a good user experience, not just scores. Those scores are only indicators of actions to take or issues to address.
Expected Layout Changes vs. Unexpected Changes
Not every layout change is a problem. If something you do causes the layout to change, that’s an expected (positive) change.
For example, clicking the hamburger menu to open mobile navigation is an expected shift. So is clicking a button that reveals an accordion section and pushes content downward.
Google can tell the difference between expected and unexpected changes. If a change happens within 0.5 seconds (500ms) of your last interaction, Google doesn’t count it toward your CLS score.
Unexpected (negative) changes are another story. The video below shows what a bad layout shift looks like:
So, What’s a Good CLS Score and What Should We Aim For?
Google recommends aiming for a CLS score below 0.1. It rates anything above 0.25 as poor:
- Good – CLS less than 0.1
- Needs Improvement – CLS between 0.1 and 0.25
- Poor – CLS higher than 0.25
Note that unlike other core vitals metrics, CLS isn’t measured in time.
The formula for calculating the score is as follows:
Mobile layout changes have a bigger impact on the score due to the smaller screen area. You’ll see different CLS scores for mobile and desktop.
How to Check the CLS Score of a Specific Page?
You can measure CLS with both field data and lab data. The most common tools are PageSpeed Insights, GTmetrix, WebPageTest, and Google Search Console (look in the Core Web Vitals report).
You can also use Chrome Lighthouse or the DevTools in Chrome as lab tools.
These tools aren’t where I stop testing for layout changes. Tests in a development environment give different results from tests on the live site because the browser has already cached the live site’s assets (CSS, fonts, images).
On the live site, layout changes happen much faster, so they’re easy to miss. You might catch a few shifts and still have trouble spotting the rest.
For a closer look, I recommend two methods:
First Method – Layout Shift Regions
For this test, I deliberately slow the site down. When the page loads very slowly, you can see which elements move and count the layout shifts as they happen.
Dynamic elements load slowly too, so you can see every layout change. Here’s how to set that up in Chrome DevTools:
- On the page you want to test, press F12 to open Chrome DevTools, then go to the Network tab.
- Open the “No throttling” dropdown and choose a setting like 3G to simulate a slower internet connection.
Once you’ve slowed the connection, go to the Elements tab. Open the three-dot menu, choose “More tools” and select “Rendering.”
In the Rendering tab that opens, you’ll find “Layout shift regions.” Turn it on and reload the page. Chrome DevTools highlights the areas that shift in blue.
PageSpeed Insights also shows which elements cause layout shifts. In Lighthouse 13 and later, look for the “Layout shift culprits” insight. It replaced the older “Avoid large layout shifts” audit.
Second Method – Performance Tab
Open the Performance tab in Chrome DevTools and click “Record and reload.” Chrome DevTools refreshes the page and records a trace. Look for the clusters of purple diamonds in the “Layout shifts” track. Each diamond marks a shift.
Select a shift to see Chrome DevTools highlight the HTML element causing it on the page. The summary tells you which element moved and gives you the score for that shift. To see likely causes, such as unsized images or late-loading web fonts, check the “Layout shift culprits” insight in the sidebar.
How to Improve Your CLS Score
Now that we know how to check the CLS score and layout shifts on a website, let’s look at some common issues affecting that score and suggest solutions:
1. Loading Font Causes FOIT/FOUT
Fonts are one of the main culprits behind layout shifts that affect CLS. Most websites use at least one web font from Google Fonts or another source. When that font loads, the layout shifts because its letter spacing and size differ from those of the browser’s default font.
You can’t get rid of the problem entirely, but you can reduce its impact quite a bit. Pre-load your web fonts (rel = preload) so the browser gives them higher priority as the page loads. I also recommend that you host web fonts locally on your server, but only if your hosting is fast and reliable.
The font-display property helps reduce the effects of FOUT & FOIT on CLS. I explain how it works in my article on the font-display property. If you’re happy to show the fallback font on a slow first visit, font-display: optional avoids the re-layout altogether.
Another option is to make the fallback font take up the same space as the web font. The size-adjust, ascent-override, descent-override, and line-gap-override descriptors in @font-face let you adjust a local fallback so that hardly anything moves when the fonts swap:
@font-face {
font-family: "Inter Fallback";
src: local("Arial");
size-adjust: 107%;
ascent-override: 90%;
}
body {
font-family: "Inter", "Inter Fallback", sans-serif;
}
The exact percentages depend on which fonts you pair. Libraries like Fontaine can do the math for you.
Aggressive caching and a good CDN also help with static assets like fonts. The CDN serves those assets from the closest network location, so they load faster and you see fewer font-related layout shifts.
Remember that preloading fonts might negatively impact the Largest Contentful Paint (LCP) metric if not used carefully.
Embeds and iFrames
Embeds let you show content from other sites on your page, whether that’s a YouTube video, a map from Google Maps, an Instagram post, or something else. There are a few ways to embed that content:
- iFrame
- Embedded HTML code
- Script tag with HTML fallback
The catch is that most embeddable applications don’t give you exact dimensions up front. A tweet might contain just text, or it might include an image too. The platform can’t predict the exact height.
Since dimensions are unknown, most embed codes don’t include them. When the embedded content loads, it can cause significant layout shifts.
To improve CLS, set the dimensions up front and use a placeholder or fallback content.
You can use Chrome’s Developer Tools to check how much height the embed needs. Then set the placeholder dimensions so there’s room for the content when it loads.
Widgets and certain platforms like Google Maps allow you to set the embed dimensions in a way that won’t cause issues in this regard.
Dimensionless Images and SVGs
Images are another very common cause of layout shifts, especially dimensionless images (those without a fixed width and height).
When the browser comes across a dimensionless image, it doesn’t set aside space for it. Once the image loads, it pushes text and other content around.
Images are usually loaded after textual content, as images have larger file sizes compared to HTML and CSS.
The simplest fix is defining width and height attributes on every <img> tag. For responsive design, the modern best practice is to use the CSS aspect-ratio property:
img {
aspect-ratio: 16 / 9;
width: 100%;
height: auto;
}
That way, the browser can set aside the right amount of space before the image loads without breaking responsive layouts.
SVG images behave differently – they scale to the dimensions of their container element. Without defined dimensions, SVGs tend to load at full size, causing sudden shifts.
The fix is to define width and height directly in the SVG code. This ensures the SVG loads at the exact dimensions you want.
Here’s an example of SVG without defined dimensions. After opening the SVG in a text editor and adding the following width and height you can see the same SVG image with the dimensions we specified. Pay attention to the added width and height.
<svg xmlns="http://www.w3.org/2000/svg" width="40px" height="40px" viewBox="...
There are plenty of other methods, but this optimization should give you a good starting point. The browser will reserve space for images before they load, so they won’t push other content around.
Advertisements
Advertisements are among the biggest contributors to layout shifts. Most ad platforms use dynamic sizes instead of fixed dimensions, which leads to performance and layout issues.
Third-party servers deliver the ad content, so it loads more slowly than your own page elements. Ad platforms use dynamic sizing to maximize CTR, but the trade-off is visual stability.
The best approach is to use CSS to reserve space before the ad loads. You can set a min-height on the ad container based on the ad sizes you serve most often.
Be cautious – reserving the maximum size could leave empty space if a smaller ad loads. Also account for scenarios where no ad is served at all. My advice is to display a placeholder, since the reserved area might collapse if no content loads.
There’s no single answer for ads. The right choice depends on your ad network and what your historical data tells you about the ad sizes you serve most often.
Dynamic Content
Every website has dynamic content. Think of related posts, newsletter signup forms, or sticky bars that display a message.
The simplest way to avoid layout shifts from dynamic content is to insert it beneath existing content, not above it. The exception is when dynamic content appears above existing content in response to a user interaction.
If the dynamic content has to go above what’s already there, reserve enough space for it ahead of time.
Speed
A layout shift in response to a user interaction counts as a “good” shift, but timing matters. The response must load within 0.5 seconds of the interaction.
If your site takes longer than that to render the expected changes, they count as unexpected shifts and hurt your CLS score. That’s why overall site speed matters for CLS too.
Back/Forward Cache
When a visitor hits the back or forward button, the page appears fully loaded if the browser restores it from its back/forward cache (bfcache). Nothing shifts, and CLS resets for that visit.
Google calls bfcache eligibility a highly effective way to keep CLS low. Two common blockers are unload event listeners (use pagehide instead) and a Cache-Control: no-store header on the HTML. You can check a page in Chrome DevTools: open the Application panel, select “Back-forward cache”, and click “Run test”.
Animations
Google’s recommendation for animations is to use CSS transform properties to prevent unexpected layout shifts. Unlike properties like top, left, width, or height, CSS transforms don’t trigger layout recalculations. For more on this topic, see our guide on frontend and animation performance.
If you’re using Lottie animations, with elements sliding onto the screen from left to right in fade-in/fade-out effects, my recommendation is still to define the element’s height in a way that won’t cause poor or unexpected layout shifts.
FAQs
Here are some common questions about CLS and layout shift optimization:
font-display fallbacks, dynamically injected content (like ads and widgets), and animations that use layout-triggering CSS properties instead of transform.
width and height attributes to your <img> tags. For responsive layouts, use the CSS aspect-ratio property to let the browser reserve the correct space before the image loads. This prevents content from being pushed around when images appear.
Conclusion
CLS optimization takes ongoing work. Lighthouse increased the weight it gives CLS to 25%, and CLS is a Core Web Vitals ranking signal. So CLS already plays a direct part in how Google evaluates your site.
Rankings aside, reducing layout shifts improves the user experience. Nobody likes clicking the wrong button because the page jumped. Whether your focus is SEO or user experience, optimizing CLS is worth the effort.
