Cumulative Layout Shift, or CLS

Volt Studios

What Is Cumulative Layout Shift, or CLS?

Cumulative Layout Shift (CLS) is an indicator of performance that was introduced in 2020 by Lighthouse to assess the perceived stability of visuals the load on a webpage.

Simply simply put, CLS measures the sudden shifts of elements on the web during the time the page is rendered. This measurement is later interpreted by a sum of the layout changes that occur on your site.

CLS is all about detecting changes that are not expected. Scrolling shouldn’t cause content to move around when a site is designed properly as well as hovering over an image of a product to view a zoomed version, for instance, should not cause other content to move. There are, however, some exceptions, and websites need to think about how they will respond to this.

Ads Can Cause CLS

This one can be a bit difficult to tackle. One method to handle ads that can trigger CLS is to fashion the part where the ad will be displayed.

If, for instance, you design the div to have a particular height and width , then the advertisement will be limited to these.

There are two ways to solve the problem in the event of a shortage of inventory or an advertisement doesn’t appear.

Dynamically Injected Content

This is content that has been added to the page.

For instance in WordPress you can add a link to an YouTube video or tweet as well. WordPress displays the YouTube video and tweet in the form of an embeddable object.

Web-Based Fonts

The fonts downloaded from the internet can trigger what’s commonly referred to as Flash of Invisible Text (FOIT) as well as Flash of Text Unstyled (FOUT).

One way to avoid that is to make use of rel=”preload” within the URL to download that font.

Lighthouse will help you determine the root of CLS.

CLS Can Sneak in During Development

The layout shift could be a problem during the process of development. It is possible that the majority of the components required to render the page are loaded into the cache of the browser.

When the next time a developer or publishing company visits the site under construction, they won’t be able to notice any changes to the layout since the elements on the page have already been downloaded.