Cumulative Layout Shift (CLS) measures how much content moves around on the page after being rendered. The lower the CLS is the better. A value of 0 means the layout is completely stable.
Layout shifts hurt user experience, as they can cause accidental clicks on the wrong element or make users lose track of where they were when reading an article.
CLS is one of the Core Web Vitals, a set of three key web performance metrics defined by Google. From 2021 it will contribute to the page experience signal that Google uses for search rankings.
This filmstrip shows an example of page content shifting around after first being rendered. When the banner loads, the heading and article below it shift downward to make space for the banner.
For this page the CLS value is 0.13.
If you look closely there are actually two layout shifts on this page. The first one occurs after 2.5s when the webfont loads, causing the title and description to re-render. After this, the description takes up a little less space, and the content below it shifts upward.
You can find the CLS metric as one of the 6 key metrics at the top of each Lighthouse report.
The filmstrip below can help identify what's causing the layout shift.
There's also a more detailed "Avoid large layout shifts" audit, which breaks down different LayoutShift
events as reported by Chrome.
CLS currently determines 5% over the overall Lighthouse Performance score.
The CLS metric should be as low as possible, ideally below 0.1. A CLS above 0.25 is considered poor.
Layout shifts during the initial page load usually happen when the initial page HTML has been returned by the server, but additional resources like JavaScript and images are still loading. When these resources do load the layout shift occurs.
A common example would be ads, which are often loaded from a different server owned by the ad network, and therefore might take an extra second or two to load.
You can prevent layout shifts if you know the size of the element that's being loaded. In that case, you can provide an empty placeholder with the appropriate height, and then fill in the contents later.
You can use the Layout Instability to detect layout shifts inside your application, and calculate the Cumulative Layout Shift on the fly.
Here's how to use a PerformanceObserver
to retrieve and monitor layout-shift
entries:
var cumulativeLayoutShift = 0;
const observer = new PerformanceObserver((list) => {
list.getEntries().forEach((entry) => {
// Don't count if the layout shift is a result of user interaction
if (!entry.hadRecentInput) {
cumulativeLayoutShift += entry.value;
}
console.log({ entry, cumulativeLayoutShift });
});
});
// `buffered: true` to report layout shifts that have already happened on the page
observer.observe({ type: "layout-shift", buffered: true });
A layout-shift
entry looks like this – each event is attributed to a set of DOM nodes.
Chrome DevTools can highlight layout shifts as part of its Animation tooling. First, click the three dots in the top right corner, then select More tools, and finally click Animations.
You can then enable highlighting for Layout Shift Regions.
Now, when content moves on the page, Chrome will show a blue highlight rectangle for the affected DOM nodes.
You can find the Cumulative Layout Shift metric in the page Overview tab, just below the filmstrip.
Different versions of Chrome measure CLS slightly differently. Google keeps track of changes to the CLS definition here.