Skip to content
Web Development

How to Fix Cumulative Layout Shift on Your Website

Learn how to fix cumulative layout shift on your website: find what moves, then fix images, fonts, banners and embeds with simple HTML and CSS.

Keshur Gojiya

6 min read

How to Fix Cumulative Layout Shift on Your Website

To fix cumulative layout shift (CLS) on your website, find which elements move after the page starts loading, then reserve space for them before they load. In most business sites the culprits are images without dimensions, web fonts that swap in late, and banners, embeds or widgets injected above content. A CLS score of 0.1 or lower, measured at the 75th percentile of real visits, counts as "good" in Google's Core Web Vitals.

What is cumulative layout shift and why does it matter?

Cumulative layout shift is a score for how much visible content jumps around while a page loads. Every unexpected movement is scored by how much of the screen moved and how far. The scores add up.

For a visitor, it is the moment a button slides away just as they tap it, or the paragraph they were reading drops down because an image appeared. It is annoying, it causes mis-clicks, and CLS is one of the three Core Web Vitals Google uses as a page experience signal. It will not outrank great content on its own, but it is a cheap, concrete problem to remove.

How do I find what is causing layout shift on my site?

Check real-user data first, then reproduce the problem.

  1. PageSpeed Insights. Enter your URL and look at the field data (real visits) and the diagnostics list "Avoid large layout shifts", which names the elements that moved.
  2. Search Console. The Core Web Vitals report groups URLs with poor or "needs improvement" CLS, so you can fix a template once and cover many pages.
  3. Chrome DevTools. Open the Performance panel, record a page load, and look at the "Layout Shifts" track. Clicking a shift shows the element and its before and after position. Throttle the network to "Fast 4G" or slower, because shifts are often invisible on a fast office connection.

Test your most important templates, not just the homepage: a blog post, a service page, a product page.

Why do images cause layout shift, and how do I fix it?

Without dimensions, the browser does not know how much room an image needs until it downloads. The text below renders first and then gets pushed down.

Avoid this:

<img src="/team.jpg" alt="Our team">

Do this: give the image its intrinsic width and height. Modern browsers use them to compute the aspect ratio and reserve the space even when CSS makes the image responsive.

<img src="/team.jpg" alt="Our team" width="1200" height="800">
img {
max-width: 100%;
height: auto;
}

For containers where the image size is set by CSS, use aspect-ratio:

.hero-media {
  aspect-ratio: 16 / 9;
  width: 100%;
}

If you use Next.js, the next/image component requires width and height (or fill with a sized parent), which is one reason it helps here. In WordPress, make sure themes and page builders output width and height attributes; older themes often strip them.

How do web fonts cause layout shift?

When a custom font loads after the fallback font has already rendered, text can change size and re-wrap, shifting everything under it. The fix has three parts:

  • Use `font-display: swap` or `optional`. swap shows text immediately in a fallback and swaps later. optional only uses the web font if it arrives very quickly, which gives the least shift but sometimes means the first view uses the fallback.
  • Preload the one or two fonts used above the fold.
  • Match the fallback font's metrics so the swap barely changes the layout.
@font-face {
font-family: "Brand Sans";
src: url("/fonts/brand-sans.woff2") format("woff2");
font-display: swap;
}

@font-face {
font-family: "Brand Fallback";
src: local("Arial");
size-adjust: 105%;
ascent-override: 92%;
descent-override: 24%;
}

body {
font-family: "Brand Sans", "Brand Fallback", sans-serif;
}

The override numbers above are examples. You need to tune them to your font, and tools or your framework's font handling can calculate them. Next.js's built-in font loading does this adjustment automatically for supported fonts.

Also, self-host your fonts and ship only the weights and character sets you use. Fewer files means a shorter window for the swap to happen.

How do I stop banners, embeds and ads from pushing content down?

Anything inserted above existing content after load causes a shift. Common examples are cookie banners, promo bars, chat widgets, video embeds and ad slots.

  • Reserve the space in CSS. Give embeds and ad slots a fixed min-height or aspect-ratio that matches the final size.
  • Overlay instead of insert. A cookie banner fixed to the bottom of the viewport does not move content at all.
  • Never inject above the fold. If a promo bar must appear, render it on the server so it is in the first paint, not added by JavaScript later.
.video-embed {
  aspect-ratio: 16 / 9;
  width: 100%;
}

.ad-slot {
  min-height: 250px;
}

If an ad slot may stay empty, a reserved block of blank space is better than a jump, though you should weigh it against how odd the gap looks.

Do animations and dynamic content affect CLS?

Layout shifts that happen within a short time after a user interaction (a tap or click) are excluded from the score. Shifts you did not trigger are not. For your own animations, animate transform and opacity rather than top, height or margin, because transforms do not move other elements. Also avoid loading content such as "related posts" at the top of the page by JavaScript after the initial render.

How often should I check CLS after fixing it?

Field data in Search Console is based on a rolling window of real visits, so improvements take a few weeks to fully show. Re-check after any theme update, new plugin, new ad or marketing script, or redesign, since those are what usually bring layout shift back. A short monthly check is part of the maintenance routine I recommend for most small business sites, and it is something I cover in website redesign and maintenance work.

FAQ

What is a good CLS score?

A CLS of 0.1 or less is "good", between 0.1 and 0.25 "needs improvement", and above 0.25 is "poor". Google assesses it at the 75th percentile of real page loads.

Why is my CLS fine in a lab test but poor in Search Console?

Lab tests load one page on one device and connection. Real visitors have slower networks, different screen sizes, cookie banners and cached or uncached resources, so shifts appear that your test never shows. Trust field data, and use DevTools throttling to reproduce it.

Does layout shift hurt SEO?

CLS is part of the Core Web Vitals page experience signals, so a poor score can be a small disadvantage, but relevance and content quality matter far more. The bigger cost is usually lost conversions from frustrated visitors.

Can I fix layout shift without a developer?

Often partly. Compressing images and removing unneeded plugins or widgets helps, and many page builders let you set image dimensions. Font metric tuning and template-level changes usually need someone comfortable with CSS.

Key takeaways

  • Fix cumulative layout shift by reserving space for anything that loads late.
  • Always set image width and height, or use aspect-ratio, and size embeds and ad slots in advance.
  • Use font-display and a metric-matched fallback so font swaps do not reflow text.
  • Measure with field data, then re-check after every plugin, theme or script change.

Tags

  • Web Performance
  • SEO
  • CSS
  • Best Practices

About Keshur Gojiya

Web developer and HTML email specialist with 6+ years of experience, building websites and emails for businesses, startups and agencies.

Get to know me
Keep Reading
View All Articles
  • Web Development

    7 min read

    WordPress to Next.js Migration Checklist: 6 Stages in Order

    A WordPress to Next.js migration checklist in six stages: audit, build, redirects, staging QA, launch day and the first weeks, so nothing gets lost.

    • WordPress Migration
    • Next.js
    Keshur Gojiya
  • Web Development

    6 min read

    How to Hire a Next.js Developer: What to Check and Ask

    How to hire a Next.js developer: what to check in their work, questions to ask before you sign, red flags, freelancer vs agency, and how to write a clear brief.

    • Next.js
    • Best Practices
    Keshur Gojiya
  • Web Development

    7 min read

    Is a Headless CMS Good for SEO? What to Set Up

    Is a headless CMS good for SEO? Yes, if the site is built right. The checklist: rendering, SEO fields, URLs, sitemaps, redirects, images and page speed.

    • SEO
    • Sanity CMS
    Keshur Gojiya

Need help with an email or website?

If an email is breaking in Outlook or dark mode, or you have a design that needs building, tell me about it and I’ll reply with next steps.

Email me