Introduction

Cls Explained

View contents

CLS (Cumulative Layout Shift): Understanding Visual Stability

Introduction

Cumulative Layout Shift (CLS) is one of Google’s Core Web Vitals—a set of metrics that measure real-world user experience on your website. CLS specifically measures the visual stability of your page by quantifying how much unexpected layout movement occurs during the page’s lifetime.

Have you ever clicked a button only to have the page shift and accidentally click something else? Or started reading an article only to lose your place when an ad loaded above? That frustrating experience is exactly what CLS measures.

What is CLS?

CLS measures the sum of all individual layout shift scores that occur during a page’s lifecycle. A layout shift happens when a visible element changes its position from one rendered frame to the next without user interaction.

How CLS is Calculated

Each layout shift score is calculated as:

Layout Shift Score = Impact Fraction × Distance Fraction

Impact Fraction: Percentage of viewport affected by the shift
Distance Fraction: How far elements moved (as % of viewport)

Example:

Element covers 50% of viewport (impact fraction = 0.5)
Element moves 25% of viewport height (distance fraction = 0.25)
Layout Shift Score = 0.5 × 0.25 = 0.125

CLS Thresholds

According to Google’s web.dev documentation, CLS scores are categorized as:

✅ Good:           ≤ 0.1
⚠️ Needs Improvement: 0.1 - 0.25
❌ Poor:           > 0.25

Goal: At least 75% of page visits should have a CLS of 0.1 or less.

What Doesn’t Count as a Shift

Not all movement is bad. CLS only counts unexpected shifts. These are excluded:

  • Shifts caused by user interaction (clicking, typing)
  • Shifts within 500ms of user input
  • Animations using CSS transform property (doesn’t trigger layout)
  • Smooth scroll behavior

Why is CLS Important for SEO?

CLS directly impacts your website’s search visibility and user experience:

Key benefits of good CLS:

  • Search ranking factor: Google confirmed Core Web Vitals (including CLS) as ranking signals in the Page Experience update
  • User trust: Stable pages feel more reliable and professional
  • Reduced frustration: Users don’t accidentally click wrong elements
  • Better engagement: Users can read and interact without interruption
  • Accessibility: Stable layouts are essential for users with motor impairments or those using assistive technologies

Real-World Impact

Poor CLS can lead to:

  • Accidental clicks on ads instead of content
  • Users losing their reading position
  • Form submissions going to wrong inputs
  • Shopping cart errors (adding wrong items)
  • General distrust of the website

Common Causes of Layout Shifts

Understanding what causes layout shifts is the first step to fixing them:

1. Images Without Dimensions

When images load without specified dimensions, the browser doesn’t know how much space to reserve:

<!-- ❌ Causes layout shift -->
<img src="photo.jpg" alt="Photo">

<!-- ✅ No layout shift -->
<img src="photo.jpg" alt="Photo" width="800" height="600">

2. Ads, Embeds, and Iframes

Dynamic content that loads after the initial page render:

Page loads → User starts reading
     ↓
Ad loads above content
     ↓
Content shifts down → User loses place

3. Dynamically Injected Content

Content added by JavaScript after initial render:

// ❌ Causes shift when banner appears
document.body.insertBefore(banner, document.body.firstChild);

4. Web Fonts (FOIT/FOUT)

When custom fonts load and replace fallback fonts:

Fallback font renders → Custom font loads → Text reflows
                              ↓
                   Characters have different sizes
                              ↓
                      Layout shifts occur

5. Animations That Trigger Layout

Using properties that cause layout recalculation:

/* ❌ Causes layout shifts */
.element {
    animation: slide 1s;
}
@keyframes slide {
    from { margin-left: 0; }
    to { margin-left: 100px; }
}

/* ✅ No layout shifts */
.element {
    animation: slide 1s;
}
@keyframes slide {
    from { transform: translateX(0); }
    to { transform: translateX(100px); }
}

Basic Best Practices

1. Always Set Image Dimensions

<!-- Explicit dimensions -->
<img src="hero.jpg" width="1200" height="600" alt="Hero">

<!-- Or use aspect-ratio CSS -->
<style>
img {
    aspect-ratio: 16 / 9;
    width: 100%;
    height: auto;
}
</style>

2. Reserve Space for Dynamic Content

/* Reserve space for ad slot */
.ad-container {
    min-height: 250px;
    background: #f0f0f0;
}

3. Use CSS Transform for Animations

/* Use transform instead of layout properties */
.animate {
    transform: translateY(20px);
    opacity: 0;
    transition: transform 0.3s, opacity 0.3s;
}
.animate.visible {
    transform: translateY(0);
    opacity: 1;
}

4. Preload Fonts and Use font-display

<link rel="preload" href="/fonts/main.woff2" as="font" type="font/woff2" crossorigin>

<style>
@font-face {
    font-family: 'CustomFont';
    src: url('/fonts/main.woff2') format('woff2');
    font-display: optional; /* Prevents FOUT/FOIT shifts */
}
</style>

Practical Example

Here’s a before/after comparison:

<!-- ❌ BEFORE: Multiple CLS issues -->
<header>
    <div class="banner"></div> <!-- Loads dynamically -->
    <nav>Navigation</nav>
</header>
<main>
    <img src="hero.jpg" alt="Hero"> <!-- No dimensions -->
    <div class="ad-slot"></div> <!-- No reserved space -->
    <article>Content...</article>
</main>

<!-- ✅ AFTER: CLS optimized -->
<header>
    <div class="banner" style="min-height: 60px;"></div>
    <nav>Navigation</nav>
</header>
<main>
    <img src="hero.jpg" alt="Hero" width="1200" height="600">
    <div class="ad-slot" style="min-height: 250px;"></div>
    <article>Content...</article>
</main>

How to Check with UXR SEO Analyzer

The UXR SEO Analyzer extension helps you monitor CLS:

  1. Install the UXR SEO Analyzer extension in Chrome
  2. Navigate to any page on your website
  3. Open the extension
  4. Go to the “Performance” tab
  5. Check the “CLS” evaluator

The extension will show:

  • Current CLS score
  • Whether it meets the 0.1 threshold
  • Elements that caused layout shifts
  • Suggestions for improvement

Next Steps

Want to master all advanced CLS optimization techniques? Read our complete CLS optimization guide where we cover:

  • Debugging layout shifts with Chrome DevTools
  • Handling third-party embeds and ads
  • Advanced font loading strategies
  • Skeleton screens and placeholder patterns
  • Monitoring CLS in production

References

This article cites the following authoritative sources:

[1] web.dev: Cumulative Layout Shift (CLS) https://web.dev/articles/cls Official Google documentation defining the CLS metric. Explains how layout shifts are measured using impact and distance fractions, the 0.1 threshold for good visual stability, and why CLS is critical for user experience.

[2] Google Search Central: Page Experience Documentation https://developers.google.com/search/docs/appearance/page-experience Official Google Search documentation confirming Core Web Vitals as ranking signals. Explains how CLS, along with LCP and INP, contribute to page experience assessment and search rankings.

[3] Chrome Developers: Chrome User Experience Report (CrUX) https://developer.chrome.com/docs/crux/methodology/metrics Technical documentation on how CLS is measured in real-world Chrome user data. Covers the CrUX dataset methodology, metric collection, and how field data captures actual user-experienced layout shifts.

Additional Resources


Note: This article is part of our SEO analysis series. Explore all articles in the Performance SEO Hub.


Sources: web.dev (CLS), Google Search Central (Page Experience), Chrome Developers (CrUX)

Related articles

Related version

Detailed guide

Cls Optimization Guide

Cumulative Layout Shift (CLS) measures the visual stability of your page

Category hub

Hub

Performance Seo Hub

Performance is a critical ranking factor and directly impacts user experience

In the same category

Introduction

Lcp Explained

Largest Contentful Paint (LCP) is one of Google's Core Web Vitals—a set of metrics that measure real-world user experience on your website

Introduction

Inp Explained

Interaction to Next Paint (INP) is one of Google's Core Web Vitals—a set of metrics that measure real-world user experience on your website