Detect high CLS elements of a Web (Core Web Vitals)

The CLS Cumulative Layout Shift, or unexpected content movement, is a user-centric metric for measuring visual stability, and helps to see how many users experience changes in web layout unexpectedly.

The CLS Cumulative Layout Shift is a user-centric metric for measuring visual stability, and helps to see how many users experience changes in web layout unexpectedly.

Within Web Development, CLS is a measure that gives us Google Page Speed and should be less than 0.1. The lower it is, the more stable the loading will be.

.

medicion google cls

But since this blog is development. Let’s see, because there are times when Page Speed, points us to a total measurement, but we want to detect where this problem is caused. Many times, it is not as intuitive as we usually put in many examples.

If we use Google Chrome, in the console, we can activate the option
Layout Shift Regions, which colors the rendering and shows us the points on the web that cause a larger CLS.

  1. Three dots
  2. Run Command > Show Rendering
  3. Enable Layout Shift Regions
.
cls capture render

And to have even more information, in the console tab, we can implement this code, which will give us exact values of the elements causing such problems.

let cls = 0;

new PerformanceObserver((entryList) => {
  for (const entry of entryList.getEntries()) {
    if (!entry.hadRecentInput) {
      cls += entry.value;
      console.log('Current CLS value:', cls, entry);
    }
  }
}).observe({type: 'layout-shift', buffered: true});

Once you run that routine, it will give you the different HTML elements that cause the problem.

values cls console

Normally this is solved with CSS on the elements that create such a problem.

Leave a Comment

ÚLTIMOS ARTÍCULOS

Cierre Ventana

A great year on the WordPress plugin team

It’s been a great year for the WordPress Plugins Team. You can see the numbers in a summary…

Cierre Ventana

Develop more secure WordPress Plugins

Introduction Plugin Check Plugin is the new tool available to everyone that allows you to do automatic reviews…

Cierre Ventana

Create your own WordPress plugin, from scratch or already knowing some

Speakers: Francisco Torres, Paco Marchante and myself, David Pérez. We had the opportunity to be at WordCamp Madrid…

Logo David
Privacy Resume

Esta web utiliza cookies para que podamos ofrecerte la mejor experiencia de usuario posible. La información de las cookies se almacena en tu navegador y realiza funciones tales como reconocerte cuando vuelves a nuestra web o ayudar a nuestro equipo a comprender qué secciones de la web encuentras más interesantes y útiles.Para más información consulta nuestra <a href="/politica-privacidad/">Política de Privacidad</a>