How to fix layout shift and bring CLS under 0.1

Most layout shift comes from images without dimensions, web fonts, and banners or embeds that load late. How to find what moves and fix each cause.

By Sohail Hussain21 November 20265 min read

To fix layout shift, find the elements that move, then give everything that loads late a reserved space: width and height on images and videos, a fixed size or aspect ratio on embeds and ad slots, a size-matched fallback for web fonts, and overlays instead of inserted banners. Cumulative Layout Shift (CLS) is good at 0.1 or less and poor above 0.25, measured at the 75th percentile of real visits. Almost every CLS problem we see comes from one of four causes, covered below.

The thresholds and definitions come from Google's CLS documentation on web.dev.

How do you find what is shifting?

CLS scores how far visible content moves without the visitor causing it. Shifts that happen within half a second of a tap or key press are excluded, and shifts are grouped into short windows, with the worst window becoming the page's score. So a single large jump during load usually matters more than many small ones later.

Use three tools in this order:

  1. Search Console's Core Web Vitals report shows which groups of URLs fail CLS, on mobile or desktop. Field data includes shifts that happen while visitors scroll, which lab tests miss.
  2. PageSpeed Insights names the elements behind the largest shifts in its diagnostics.
  3. Chrome DevTools. Record in the Performance panel while the page loads and while you scroll to the bottom; each layout shift appears on the timeline with the elements that moved. In the Rendering panel, "Layout shift regions" flashes shifting areas as they happen.

For shifts that only real visitors see, the web-vitals library's attribution build reports the element behind the largest shift:

js
import { onCLS } from "web-vitals/attribution";

onCLS(({ value, attribution }) => {
  // Send to your analytics instead of logging
  console.log(value, attribution.largestShiftTarget);
});

Log your current number in our Core Web Vitals checker so you can compare after the fix. If the shifts come from a theme or page builder you cannot easily change, that is the kind of problem our technical SEO and performance work takes on.

Are images and embeds missing their dimensions?

This is the most common cause. An <img> without width and height takes up no space until the file arrives, then pushes everything below it down. Add both attributes with the image's real pixel size and set the displayed size in CSS:

html
<img src="/team.webp" width="1200" height="800" alt="The engineering team at the Pune workshop" style="width: 100%; height: auto;" />

The browser uses the two attributes to calculate the aspect ratio and reserve the right height before the image loads. In Next.js, next/image does this automatically, because width and height are required unless the image is statically imported or uses fill inside a sized parent. Next.js image optimisation covers the details.

Iframes need the same treatment. A YouTube or map embed should sit in a box with a fixed aspect ratio:

css
.embed {
  aspect-ratio: 16 / 9;
  width: 100%;
}
.embed iframe {
  width: 100%;
  height: 100%;
  border: 0;
}

Our aspect ratio calculator gives the CSS value for any size. Ad slots are harder because the ad size varies; reserve space with a min-height equal to the most common ad size, and accept a little empty space when a smaller ad fills it.

Are web fonts changing the text size?

When a web font loads, text first rendered in a fallback font is redrawn in the real one. If the two fonts have different widths or line heights, paragraphs rewrap and everything below moves.

The fix is a fallback font adjusted to match the web font's metrics, using the size-adjust, ascent-override and descent-override descriptors in @font-face. Working out the values by hand is fiddly. next/font calculates and applies them automatically: its adjustFontFallback option is on by default for Google fonts and uses Arial as the adjusted fallback for local fonts. It also self-hosts and preloads the files, so the swap happens sooner.

On other platforms, three habits reduce font shift:

  • Self-host fonts instead of loading them from a third-party CSS file, so they arrive earlier.
  • Preload only the one or two files used above the fold.
  • Use font-display: optional for body text if you would rather keep the fallback than shift. The web font is then used from the second page view onwards.

Is content being inserted above what the visitor is reading?

Anything that appears after the first render and pushes existing content down counts as a shift:

  • Cookie and promotion banners inserted at the top of the page. Show them as overlays fixed to the bottom of the viewport instead. Cookie consent: what you actually need covers the rest of that decision.
  • Late-loading widgets: reviews carousels, chat buttons that expand, "related products" blocks. Reserve their height, or place them below the fold.
  • Client-only content. In React and Next.js, a component that renders nothing on the server and appears after hydration, for example something that reads localStorage, shifts the page. Render a placeholder of the same height on the server.
  • Loading skeletons that are the wrong size. A Next.js loading.tsx or Suspense fallback should match the height of the content that replaces it. A one-line spinner replaced by a 600-pixel product grid is a shift.

Are animations moving the layout?

Animating properties that affect layout, such as top, left, margin, height or width, moves other content and can count as layout shift. Animate transform and opacity instead. A slide-in effect done with transform: translateY() moves only the element itself on its own layer, which does not count as a layout shift and is also smoother.

The same applies to accordions and "read more" panels. Those are usually opened by a click, so the shift falls inside the half-second window after input and is excluded. Panels that open on their own, or on hover, are not excluded.

How do you confirm the fix worked?

Check in DevTools that the shifts are gone during load and while scrolling. Then wait for field data: it is a 28-day rolling window, so the improvement shows fully about four weeks after deployment. Start "Validate fix" in Search Console's Core Web Vitals report once the change is live.

CLS is usually the easiest of the three Core Web Vitals to fix, because the causes are visible and the fixes are small. Core Web Vitals explained puts it alongside the other two metrics, and how to fix INP covers the one that is usually hardest. Frameworks that reserve image space and adjust font fallbacks by default make CLS a non-issue on new builds, which is part of the case in why we build company websites with Next.js.

Was this guide useful?

Questions

Frequently asked.

Does a cookie banner cause layout shift?

Only if it pushes content. A banner inserted at the top of the page, above the header, moves everything down and counts towards CLS. A banner that overlays the page with fixed positioning at the bottom moves nothing and does not count. Most consent tools offer the overlay style.

Why is my CLS poor in Search Console but zero in Lighthouse?

Lighthouse measures only the initial load, without scrolling or interacting. Real visitors scroll, which triggers lazy-loaded images, ads and embeds further down the page, and field CLS includes those shifts. Scroll through the page with the DevTools Performance panel recording to find them.

Sohail Hussain

Founder, MSH Technologies

Sohail has designed and built websites, web apps and AI products for over 12 years, for clients from Singapore-based industrial groups to early-stage SaaS startups. He writes about what actually worked.

Keep reading

Related guides.

All posts

Your next move

Like what you see? Tell us about it.

A process that takes too long, a website that undersells you, or an idea ready to take shape. Tell us where you are and we will suggest a useful next step.

India · Working with clients worldwide

Sohail, Founder, replies within 1 working day (Mon–Sat, IST). Free and no obligation.