

The distance fraction is the greatest distance any unstable element has moved in the frame (either horizontally or vertically) divided by the viewport's largest dimension (width or height, whichever is greater). The other part of the layout shift score equation measures the distance that unstable elements have moved, relative to the viewport. The red, dotted rectangle indicates the union of the element's visible area in both frames, which, in this case, is 75% of the total viewport, so its impact fraction is 0.75.

Then, in the next frame, the element shifts down by 25% of the viewport height. In the image above there's an element that takes up half of the viewport in one frame. The union of the visible areas of all unstable elements for the previous frame and the current frame-as a fraction of the total area of the viewport-is the impact fraction for the current frame. The impact fraction measures how unstable elements impact the viewport area between two frames. layout shift score = impact fraction * distance fraction Impact fraction # The layout shift score is a product of two measures of that movement: the impact fraction and the distance fraction (both defined below). To calculate the layout shift score, the browser looks at the viewport size and the movement of unstable elements in the viewport between two rendered frames. If a new element is added to the DOM or an existing element changes size, it doesn't count as a layout shift-as long as the change doesn't cause other visible elements to change their start position. Note that layout shifts only occur when existing elements change their start position. Such elements are considered unstable elements. Layout shifts are defined by the Layout Instability API, which reports layout-shift entries any time an element that is visible within the viewport changes its start position (for example, its top and left position in the default writing mode) between two frames. To learn more about the research and methodology behind this recommendation, see: Defining the Core Web Vitals metrics thresholds Layout shifts in detail # Blue bars represent the scores of each individual layout shift. The largest burst is the session window with the maximum cumulative score of all layout shifts within that window. (See below for details on how individual layout shift scores are calculated.)Ī burst of layout shifts, known as a session window, is when one or more individual layout shifts occur in rapid succession with less than 1-second in between each shift and a maximum of 5 seconds for the total window duration. What is CLS? #ĬLS is a measure of the largest burst of layout shift scores for every unexpected layout shift that occurs during the entire lifespan of a page.Ī layout shift occurs any time a visible element changes its position from one rendered frame to the next. The Cumulative Layout Shift (CLS) metric helps you address this problem by measuring how often it's occurring for real users.

Personalized or third-party content often doesn't behave the same in development as it does in production, test images are often already in the developer's browser cache, and API calls that run locally are often so fast that the delay isn't noticeable. What makes this issue even more problematic is that how a site functions in development is often quite different from how users experience it. The culprit might be an image or video with unknown dimensions, a font that renders larger or smaller than its fallback, or a third-party ad or widget that dynamically resizes itself. Unexpected movement of page content usually happens because resources are loaded asynchronously or DOM elements get dynamically added to the page above existing content. A screencast illustrating how layout instability can negatively affect users.

Most of the time these kinds of experiences are just annoying, but in some cases, they can cause real damage. Or even worse: you're about to tap a link or a button, but in the instant before your finger lands-BOOM-the link moves, and you end up clicking something else! Have you ever been reading an article online when something suddenly changes on the page? Without warning, the text moves, and you've lost your place. Cumulative Layout Shift (CLS) is an important, user-centric metric for measuring visual stability because it helps quantify how often users experience unexpected layout shifts-a low CLS helps ensure that the page is delightful.
