📐CLS Deep Dive: Eliminating Cumulative Layout Shift
Why your layout shifts, how to measure CLS using DevTools and field data, and the specific code patterns that cause — and fix — layout instability.
Cumulative Layout Shift (CLS) measures the visual stability of your page — how much page elements unexpectedly move during load. A high CLS score means users are clicking the wrong things because buttons and text jump around. Google began using CLS as a ranking factor in 2021.
Cumulative Layout Shift (CLS) (score)
Top Causes of CLS
- Images without explicit width/height attributes (browser doesn't reserve space)
- Ads, embeds, or iframes without reserved dimensions
- Dynamically injected content above existing content (cookie banners, banners)
- Web fonts causing FOUT (Flash of Unstyled Text) that shifts surrounding text
- Animations that alter layout properties (width, height, top, left, margin, padding)
Fix 1: Always Specify Image Dimensions
<!-- Bad: browser doesn't know how tall this will be -->
<img src="photo.jpg" alt="Description">
<!-- Good: browser reserves 600×400 space before image loads -->
<img src="photo.jpg" alt="Description" width="600" height="400">Fix 2: Reserve Space for Ads and Embeds
.ad-container {
min-height: 250px; /* Reserve the standard ad unit height */
width: 100%;
}Fix 3: Use CSS Transform for Animations
Layout properties (width, height, margin, padding, top, left) trigger layout recalculation and contribute to CLS. Use transform and opacity instead — they run on the compositor thread and don't cause layout shifts.
/* Bad: triggers layout shift */
.element { margin-top: 0; transition: margin-top 0.3s; }
.element:hover { margin-top: -10px; }
/* Good: compositor-only, no layout shift */
.element { transform: translateY(0); transition: transform 0.3s; }
.element:hover { transform: translateY(-10px); }Use Chrome DevTools Performance panel → enable "Layout Shift Regions" to see purple rectangles highlighting where shifts occur. Google Search Console's CWV report shows real-user CLS data by URL.