Cumulative Layout Shift is the Core Web Vital that most often looks fine on your machine and fails in the field. Your fonts are cached, your images are warm, your connection is fast, so nothing moves. On a cold visit over a mid-range phone connection, everything moves.
The cause is always the same. Content arrived and the browser had not reserved space for it. Every fix below is a different costume for reserving that space in advance.
Find the shifts first
CLS is a sum, and usually one or two shifts dominate while the rest are noise. Harden everything and you will spend a day for a rounding error.
In DevTools, record a page load in the Performance panel and look at the Experience track. Each shift is a marker, and selecting one names the element that moved and what it contributed.
For real sessions, the Layout Instability API reports the same thing from the field:
new PerformanceObserver((list) => {
for (const entry of list.getEntries()) {
if (entry.hadRecentInput) continue; // user-initiated shifts don't count
console.log(entry.value, entry.sources.map((s) => s.node));
}
}).observe({ type: "layout-shift", buffered: true });The sources array is the useful part. It points at the nodes that moved, which in my experience is frequently not the element anyone suspected.
Images without dimensions
An image with no dimensions occupies zero height until it loads, then suddenly occupies several hundred pixels and shoves everything below it down the page.
With a static import, next/image reads the intrinsic size at build time and reserves the space for you:
import Image from "next/image";
import cover from "../public/cover.webp";
<Image src={cover} alt="…" className="w-full" /> // dimensions known, space reservedWith a remote source nothing is known at build time, so you supply it:
<Image src={url} alt="…" width={1200} height={630} className="h-auto w-full" />Those numbers are an aspect ratio, not a display size. CSS still controls how large it renders. Their only job is to let the browser compute the right height before a single byte arrives.
For images of unknown ratio, reserve the box yourself and crop into it:
<div className="relative aspect-[16/9] w-full">
<Image src={url} alt="…" fill className="object-cover" />
</div>fill needs a positioned parent with its own dimensions. Without one you are back to reserving nothing, which is a mistake that looks like it works until it is on a phone.
Fonts that re-flow the page
A web font loading after first paint re-flows every line of text it touches. How bad it is depends on how far the fallback's metrics are from the real font: if the fallback is narrower, lines re-wrap and everything below them moves.
next/font does the hard part. It self-hosts, preloads, and generates a size-adjusted fallback whose metrics are matched to the real font, so the swap is close to invisible.
import { Inter } from "next/font/google";
const inter = Inter({ subsets: ["latin"], display: "swap", variable: "--font-inter" });Two things to check afterwards. Load only the weights and subsets you use, since each one is a download competing with first paint. And confirm no @import from a font CDN survived in your CSS, because that quietly reintroduces the exact round trip next/font removed. I hit that one myself, and wrote it up in how I cut First Contentful Paint.
The client-only shift, which is self-inflicted
This is the Next.js-specific one, and it is in almost every codebase I have looked at.
A component that renders nothing on the server and real content after mount produces a shift on every single load:
// ❌ renders null on the server, content after hydration — a shift on every load
"use client";
export function ThemeToggle() {
const [mounted, setMounted] = useState(false);
useEffect(() => setMounted(true), []);
if (!mounted) return null;
return <button>…</button>;
}The motivation is avoiding a hydration mismatch, which is reasonable, because the server genuinely cannot know the user's theme or locale or viewport. The fix is not to render nothing. It is to render something of the same size.
// ✅ occupies its final size from the first paint
if (!mounted) return <span className="block size-11" aria-hidden />;Better still, avoid the mismatch. For a theme toggle, render both icons and let CSS choose, so server and client markup are identical and nothing waits for mount:
<svg className="dark:hidden" />
<svg className="hidden dark:block" />The same applies to next/dynamic with ssr: false. Give it a loading placeholder sized like the real component, not null.
Everything else that arrives late
Ads and embeds want their slot reserved at its known size. A collapsed slot that expands when the ad fills is pure CLS and it is the most common failure on content sites by a distance.
Banners and notices inserted at the top of the document push the whole page down. Overlay them, or render them in the initial HTML so they are part of the first layout rather than an edit to it.
Icon fonts shift inline text when they swap in late. Inline SVG does not, which is most of the argument for inline SVG.
And if you hand-roll @font-face rather than using next/font, the metric matching is now your job, size-adjust included.
CLS counts the whole visit
Not just load. A shift triggered by something loading five seconds in still counts, which is why lazy content below the fold matters even though nobody has scrolled to it yet.
Test on a throttled connection with an empty cache, because a warm cache hides nearly every shift on this page. Then read Search Console's 75th percentile and treat that as the verdict over any lab score.
One instruction, several costumes
Images get dimensions or an aspect-ratio box. Fonts get a metric-matched fallback. Client-only components get a placeholder the size of the real thing. Ads and banners get their slot in the initial layout.
All of it is the same instruction: reserve the space before the content arrives.
Do it consistently and CLS stops being a score you chase after each report and becomes a property the layout has by construction, which is a much cheaper place to be.