← CodeClarityLab Home
Browse by Category
+ added · updated 7d
← Back to glossary

Cumulative Layout Shift (CLS)

performance Intermediate

Also Known As

CLS layout shift visual stability content jump page jump layout instability

TL;DR

A Core Web Vital that measures unexpected visual movement of page elements during load — caused by images without dimensions, late-injected content, and font swaps. Target: under 0.1.

Explanation

CLS quantifies how much page content unexpectedly moves during the loading phase, frustrating users who click on the wrong element as the page shifts. The score is calculated as the sum of impact fraction × distance fraction for each unexpected layout shift. Target: under 0.1 (Good), 0.1-0.25 (Needs Improvement), over 0.25 (Poor). Common causes: images and iframes without explicit width and height attributes (browser can't reserve space); ads, cookie banners, or embeds injected above existing content after load; web fonts that swap and cause text reflow; animations that use top/left instead of transform (which is GPU-composited and doesn't cause layout recalculation). CLS only counts unexpected shifts — layout shifts caused by user interaction (clicking a button that expands content) within 500ms of the interaction are excluded from the score.

Common Misconception

CLS only matters if images are loading slowly — layout shift happens even on fast connections when content is injected dynamically or images lack dimensions; a fast connection just means the shift happens faster, not that it doesn't happen.

Why It Matters

A user reading an article on a mobile phone clicks what they believe is a link — but an ad loads above it at that exact moment, shifting the content down, and they click the ad instead. This is the exact user experience CLS measures and penalises.

Common Mistakes

  • Images without explicit width and height attributes — browser cannot reserve space, images shift content when loaded.
  • Ads, analytics, or cookie consent banners injected above existing content after load — always inject into reserved space.
  • Web font swap causing text reflow — use font-display: optional to prevent FOUT that shifts layout.
  • CSS animations using top/left/margin instead of transform — property changes that trigger layout recalculation cause CLS; transform does not.
  • Dynamic content insertion above the fold without reserved height — reserve minimum height with CSS before content loads.

Avoid When

  • Do not animate layout properties (margin, padding, top, left, width, height) — use transform and opacity instead, which are GPU-composited and do not trigger CLS.

When To Use

  • Measure CLS in field data (CrUX) not just Lighthouse — real user device and connection conditions reveal shifts that lab tests miss.
  • Use Chrome DevTools Performance panel with Layout Shift Regions overlay to visually identify what is shifting.

Code Examples

✗ Vulnerable
/* CLS from images without dimensions */
<img src="banner.jpg" alt="Banner"><!-- no width/height -->

/* CLS from late-injected banner */
<script>
  // Runs after page load — pushes content down
  document.body.prepend(cookieBanner);
</script>

/* CLS from CSS animation */
.slide-in { animation: slide 0.3s; }
@keyframes slide { from { margin-top: -100px; } to { margin-top: 0; } }
✓ Fixed
<!-- Images with explicit dimensions — browser reserves space -->
<img src="banner.jpg" alt="Banner" width="1200" height="400">

<!-- Reserved space for cookie banner -->
<div style="min-height: 60px" id="cookie-banner-slot">
  <!-- Banner injects here without shifting content -->
</div>

/* Use transform instead of layout properties for animation */
.slide-in { animation: slide 0.3s; }
@keyframes slide { from { transform: translateY(-100px); } to { transform: translateY(0); } }

Added 6 Apr 2026
Views 13
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings W 0 pings T 0 pings F 0 pings S 1 ping S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 0 pings S 1 ping S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 1 ping T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T
No pings yet today
No pings yesterday
Google 2 ChatGPT 1 Perplexity 1 Ahrefs 1
crawler 4 crawler_json 1
DEV INTEL Tools & Severity
🟠 High ⚙ Fix effort: Low
⚡ Quick Fix
Add explicit width and height to every img and iframe; reserve space for ads and injected content; use transform for CSS animations instead of top/left/margin
📦 Applies To
html web
🔍 Detection Hints
img without width and height; content injected above existing DOM nodes; CSS animation using margin/top/left
Auto-detectable: ✓ Yes lighthouse pagespeed-insights chrome-devtools-performance crux
⚠ Related Problems
🤖 AI Agent
Confidence: Medium False Positives: Medium ✗ Manual fix Fix: Medium Context: File

✓ schema.org compliant