Cumulative Layout Shift (CLS) measures how much visible content shifts position during page load. Every time something on the page jumps — an image loads and pushes text down, an ad appears mid-scroll, a banner slides in from the top — CLS goes up. The threshold for "good" is 0.1 or less; "needs improvement" is above 0.1 up to 0.25; over 0.25 is poor. Like the other Core Web Vitals, it is judged at the 75th percentile of real visits.
CLS is the most fixable Core Web Vital because the causes are mechanical and well-understood. There are about six recurring patterns that cause shifts; this guide covers each one and the specific fix.
What CLS Actually Measures
The browser tracks every layout shift during page load — defined as any element moving from one frame to the next without user input. For each shift, it computes:
- Impact fraction — what fraction of the viewport is affected by the shift.
- Distance fraction — how far the largest element moves, as a fraction of the viewport.
- Layout shift score = impact fraction × distance fraction.
Individual shifts are then grouped into session windows. A window keeps growing while shifts happen less than one second apart, up to a maximum of five seconds. The page's CLS is the total of the worst window during the visit — not the sum of every shift — so a page that stays open for an hour is not penalised for small shifts spread across it.
Key point: shifts within half a second of user input (a tap, click or key press) don't count, because the user expects the page to change. Only unexpected shifts count. Scrolling is not input for this purpose, so content that jumps as you scroll still counts.
How the CLS Score Is Calculated: A Worked Example
A cookie notice 200 pixels tall is inserted at the top of a page on a phone with an 800-pixel-high viewport, and pushes the whole visible article down by 200 pixels.
- Impact fraction: the moved content covered the viewport before the shift and still covers it afterwards, so the combined area is the whole viewport — 1.0.
- Distance fraction: it moved 200 of 800 pixels — 0.25.
- Layout shift score: 1.0 × 0.25 = 0.25.
That one banner puts the page at the boundary of "poor" on its own. The same banner shown as an overlay (position: fixed) moves nothing, and scores zero. This is why CLS is about how content appears as much as what appears.
How to Find What Is Shifting
A CLS number tells you there is a problem, not where it is. To find the elements responsible:
- Lighthouse or PageSpeed Insights. The diagnostic listing the largest layout shifts (in newer versions, "Layout shift culprits") names each shifted element and its score, and often the likely cause — an unsized image, a web font or injected content.
- Chrome DevTools. Record a page load in the Performance panel. Layout shifts appear on their own track; select one to highlight the elements that moved.
- A few lines of JavaScript, pasted into the console before reloading, to log every shift with the elements involved:
new PerformanceObserver((list) => { for (const shift of list.getEntries()) { if (shift.hadRecentInput) continue; console.log(shift.value.toFixed(4), shift.sources.map(s => s.node)); } }).observe({ type: 'layout-shift', buffered: true });
Test at mobile width. A narrow viewport means wrapped text and taller elements, and shifts that are invisible on desktop are often large on a phone.
Cause 1: Images Without Dimensions
The most common cause. An <img> tag without explicit width and height attributes (or CSS dimensions) takes up zero space until it loads — at which point the browser reflows everything below it.
The fix is to set explicit dimensions on every image:
<img src="hero.jpg" width="1200" height="630" alt="...">
Modern browsers use the width:height ratio to reserve space at the correct aspect ratio even before the image loads. As long as you set width and height (the values can be any units; browsers compute the ratio), there's no shift when the image arrives.
For responsive images:
<img src="hero.jpg" width="1200" height="630" style="width: 100%; height: auto;" alt="...">
The HTML attributes establish the aspect ratio; the CSS lets the actual display size adapt to container width.
Cause 2: Web Fonts
Custom web fonts cause "FOIT" (Flash of Invisible Text) or "FOUT" (Flash of Unstyled Text) — depending on settings, the browser either shows nothing until the font loads, or shows a fallback font that gets swapped when the custom font arrives. Both produce layout shifts as the text re-flows at different metrics.
Fixes:
- Use
font-display: swap:
Shows fallback immediately, swaps to custom when ready. Causes a shift but at least the user sees text.@font-face { font-family: 'Custom'; src: url('custom.woff2') format('woff2'); font-display: swap; } - Use
font-display: optional: Browser uses the custom font only if it's already cached or loads in the first ~100ms. Otherwise sticks with the fallback for the entire session. Eliminates the swap shift. - Match metrics with size-adjust:
Forces the fallback font to render at metrics matching the custom one, eliminating layout shift when the custom font arrives. Tools like the Font Style Matcher help you find the right values.@font-face { font-family: 'Custom'; src: url('custom.woff2') format('woff2'); size-adjust: 105%; ascent-override: 90%; descent-override: 22%; } - Preload fonts from the head:
<link rel="preload" href="custom.woff2" as="font" type="font/woff2" crossorigin> - Self-host fonts rather than loading from Google Fonts. Saves a DNS lookup and TLS handshake; fonts arrive sooner; less layout shift.
Cause 3: Ads, Embeds, Iframes Without Reserved Space
Display ads and third-party embeds load asynchronously, often hundreds of milliseconds after page render. If you don't reserve space for them, they push content down when they arrive.
The fix is to define a fixed-size container:
.ad-slot {
min-height: 250px; /* matches the ad's known height */
width: 100%;
}
For ads that come in multiple sizes, reserve space for the largest possible variant. The visible empty space before the ad loads is less painful than the layout shift after it loads.
For YouTube embeds, social media embeds, and other iframes — set explicit dimensions or aspect-ratio:
iframe {
aspect-ratio: 16 / 9;
width: 100%;
height: auto;
}
Cause 4: Dynamically Injected Content
JavaScript injects content above existing content — banner ads, "subscribe" prompts, GDPR cookie banners, sticky headers, A/B test variants. Every injection causes content below to shift.
Solutions:
- Reserve space upfront for content you'll inject. The JS knows the height of the banner; place a fixed-height placeholder in the HTML and replace it when the banner is ready.
- Don't inject above existing content. Banners and prompts can overlay (position: fixed) without pushing content. Cookie banners almost always work this way; do the same for other dynamic content.
- Show it in response to a tap or click. Layout shifts within 500 ms of a tap, click or key press don't count toward CLS. Content revealed because the user asked for it — an accordion, a "load more" button — is forgiven. Content that appears on a timer or on scroll is not.
Cause 5: Network Race Conditions
Sometimes content loads in unexpected orders. The CSS arrives, layout is computed, then a stylesheet that arrives later changes everything. Or a JS framework hydrates the page after initial render and reflows content differently.
For SPAs with hydration mismatches:
- Ensure server-rendered HTML and client-rendered HTML match exactly. React's "hydration mismatch" warning surfaces this.
- Avoid client-only rendering for above-the-fold content.
- Don't use
useEffectto set styles that affect layout — they fire after the initial render and cause shifts.
For CSS:
- Inline critical CSS in the head so the first paint has the right styles.
- Avoid late-loading stylesheets that change above-the-fold appearance.
- If you must lazy-load CSS, use
media="print"swap technique to load without blocking, but ensure the late-arriving styles don't change layout.
Cause 6: Animations and Transitions
Animations using top, left, width, height, margin, padding trigger layout reflows on every frame — and if they happen during page load, they count toward CLS.
Use only properties that don't trigger layout: transform (for position) and opacity (for visibility). Modern animations should use:
.slide-in {
transform: translateX(-100px);
transition: transform 0.3s;
}
.slide-in.active {
transform: translateX(0);
}
Not:
.slide-in {
left: -100px;
transition: left 0.3s; /* triggers layout shift */
}
Cumulative Layout Shift on Shopify
Shopify stores hit the same causes, but a few sources come up again and again:
- App embeds that inject content. Review stars, announcement bars, trust badges, upsell blocks and currency selectors are often added by apps after the page renders, pushing content down. Check each app's settings for a fixed-height option, reserve space in the theme with a
min-height, or move the block below the fold. - Product images without dimensions. Liquid's
image_tagfilter outputswidthandheightautomatically; older themes and hand-written<img>tags often don't. Galleries and sliders that size themselves with JavaScript shift when the script runs. - Announcement bars and sticky headers that are added or change height after load. Render them in the theme's HTML at their final height.
- Web fonts from the theme settings. A different fallback font with different metrics causes a shift when the custom font arrives; see Cause 2.
The Diagnostic Workflow
- Run Site Speed Check for an instant CLS measurement.
- Use the Chrome DevTools Performance panel — record a load, and the layout shifts track highlights every shift and the elements that moved.
- Lighthouse reports CLS along with diagnostics for the most impactful shifts.
- PageSpeed Insights field data shows real-user CLS — what Google actually measures for ranking.
The Production Habit
For new pages and components:
- Every
<img>has explicit width and height. - Every
<iframe>has aspect-ratio or explicit dimensions. - Every ad slot has a min-height.
- Web fonts use
font-display: swapat minimum, ideally with size-adjust. - Animations use only
transformandopacity. - Above-the-fold dynamic content is server-rendered or has placeholders.
None of these are difficult; they're disciplines applied consistently. Audit existing pages with Site Speed Check and fix the patterns that recur. Because the causes are mechanical, CLS is usually the quickest of the three Core Web Vitals to bring into the "good" range.
Why CLS Matters Beyond Rankings
CLS is annoying. Mis-clicking the wrong button because the page shifted, losing your scroll position because content was injected above, having to re-find your place in an article — these are real user frustrations. Google measuring CLS is a proxy for measuring user-experience pain. The same fixes that improve your rankings improve your conversion rate, your bounce rate, and your real users' experience.
Run any URL through Site Speed Check and the CLS number tells you in seconds what kind of user experience you're delivering. Anything over 0.1 has fixes that pay off in both rankings and visitor sanity.