Karachi, Pakistan Mon–Sat: 10AM–7PM PKT
Home Services
Design & Development
UI/UX Design Web Development WordPress Development Responsive Web Design Corporate Website Landing Pages / Microsites E-Commerce Solutions Mobile App Development
Marketing & Growth
SEO Services Content Marketing Social Media Marketing PPC / Google Ads Branding & Creative Speed & Performance
Hosting & Support
Web Hosting Maintenance & Support
Portfolio
Website Design Logo & Graphics
Clients About Blog Free Tools Get a Quote
SEO & Speed Guide

How to Fix CLS (Cumulative Layout Shift): Causes and Code Fixes

How CLS is calculated, how to find the element that shifts, and code fixes for images, ads, web fonts, banners, animations and JavaScript-loaded content.

Cumulative layout shift: page layout shifting as images and ads load

Cumulative Layout Shift (CLS) measures how much the content of a page jumps around unexpectedly while it loads and while people use it. A good score is 0.1 or less for at least 75 percent of visits. The most common causes are images and videos without dimensions, ads and embeds without reserved space, web fonts swapping, and banners or cookie notices injected above content. This guide explains how CLS is calculated, how to find exactly which element is shifting, and the code fixes for each cause.

Key takeaways
  • Good CLS is 0.1 or less; above 0.25 is poor. Google measures it from real Chrome users.
  • Always give images, videos and iframes width and height attributes, or a CSS aspect-ratio.
  • Reserve space for ads, embeds, sliders and late-loading banners before they arrive.
  • Animate with transform and opacity, never with top, height or margin.

Cumulative layout shift: what CLS measures and how it is scored

Every time a visible element moves from where it was rendered in one frame to a different position in the next, without the user causing it, the browser records a layout shift. Each shift gets a score: Also, this is one of the easiest ways to fix cumulative layout shift.

layout shift score = impact fraction × distance fraction
  • Impact fraction: how much of the viewport the unstable elements cover, before and after the move combined.
  • Distance fraction: how far they moved, relative to the viewport's largest dimension.

Shifts are grouped into session windows: shifts less than one second apart, up to five seconds per window. The page's CLS is the score of the worst window, not the total over the whole visit, so long pages are not unfairly punished.

CLSRating
0 to 0.1Good
0.1 to 0.25Needs improvement
Above 0.25Poor

Shifts that happen within 500 milliseconds of a tap, click or key press are excluded, because users expect the page to change when they interact. Scrolling does not count as an input for this purpose.

Lab vs field CLS: why scores differ

Lighthouse and PageSpeed Insights' lab section only measure shifts during page load, in a single simulated visit. Field data (the Chrome UX Report shown at the top of PageSpeed Insights and in Search Console's Core Web Vitals report) includes shifts that happen later, for example when a user scrolls and lazy-loaded ads appear. That is why a page can score 0 in Lighthouse and still fail CLS in Search Console. For an overview of all three Core Web Vitals, see our speed testing guide. So keep this in mind whenever you fix cumulative layout shift.

Cumulative layout shift: how to find the element that shifts

  1. PageSpeed Insights: under Diagnostics, open "Avoid large layout shifts" to see the elements and their contribution.
  2. Chrome DevTools Performance panel: record a page load; layout shifts show as purple bars in the "Layout shifts" track. Click one to highlight the moving element.
  3. Rendering panel: in DevTools, open More tools → Rendering and enable "Layout Shift Regions" to flash shifted areas blue as you scroll.
  4. Console snippet: paste this to log every shift and the nodes involved while you scroll and click:
new PerformanceObserver((list) => {
  for (const entry of list.getEntries()) {
    if (entry.hadRecentInput) continue;
    console.log(entry.value.toFixed(4),
      entry.sources.map(s => s.node));
  }
}).observe({ type: 'layout-shift', buffered: true });

Test on a throttled mobile connection. Many shifts only appear when fonts and images load slowly.

Fix 1: Give images and videos dimensions

An image without dimensions takes up zero height until it downloads, then pushes everything below it down. Add the intrinsic width and height attributes; modern browsers use them to compute the aspect ratio before the file arrives, even when CSS makes the image responsive. In short, it is one of the simplest ways to fix cumulative layout shift.

<img src="team.webp" width="1200" height="800" alt="Our team"
     style="max-width:100%; height:auto">

For containers whose content arrives later, such as video embeds or background-image heroes, reserve space with aspect-ratio:

.video-wrap { aspect-ratio: 16 / 9; width: 100%; }
.video-wrap iframe { width: 100%; height: 100%; }

WordPress adds width and height to images inserted through the editor automatically. Problems usually come from page builders, sliders and custom theme code. See our image size guide for the right dimensions.

Fix 2: Reserve space for ads, embeds and dynamic content

Ads, social embeds, review widgets and "related products" blocks often load after the page and insert themselves into the flow. Give their container a minimum size based on the most common size it will receive: In fact, small steps like this are how you fix cumulative layout shift.

.ad-slot { min-height: 250px; }          /* 300×250 unit */
@media (min-width: 768px) {
  .ad-slot-top { min-height: 90px; }    /* 728×90 leaderboard */
}
  • Do not collapse the slot if no ad fills; show a placeholder instead.
  • Place dynamic blocks lower on the page where possible, because shifts near the top move more content.
  • For embeds such as Instagram posts or Google Maps, set a fixed height or aspect ratio on the wrapper.

Fix 3: Stop web fonts from shifting text

When a custom font loads, text re-renders in the new font. If the fallback font has different widths or line heights, lines rewrap and the page jumps. Fixes, in order of impact:

  • Preload the one or two font files used above the fold:
<link rel="preload" href="/fonts/inter-var.woff2"
      as="font" type="font/woff2" crossorigin>
  • Self-host fonts in WOFF2 instead of loading them from a third-party server, so they arrive sooner.
  • Match the fallback to the web font's metrics with size-adjust and override descriptors:
@font-face {
  font-family: "Inter Fallback";
  src: local("Arial");
  size-adjust: 107%;
  ascent-override: 90%;
  descent-override: 22%;
  line-gap-override: 0%;
}
body { font-family: "Inter", "Inter Fallback", sans-serif; }
  • Use font-display: optional if you prefer no swap at all on slow connections; the font is used from the next page view once cached.

Next.js (next/font) and some WordPress performance plugins generate matched fallbacks automatically.

A promotional bar or app banner inserted at the top of the page after load pushes the whole page down, which is one of the largest shifts possible. Options:

  • Render it in the HTML from the start, so it is part of the first layout.
  • Overlay it with position: fixed at the bottom of the screen instead of inserting it into the flow.
  • Reserve its height in CSS until the script decides whether to show it.

Fix 5: Use transform-based animations

Animating properties such as top, left, height, width or margin moves other elements and counts as layout shift. Animating transform and opacity does not, and it is smoother because the GPU handles it.

/* Causes layout shift */
.panel.open { height: 300px; transition: height .3s; }

/* No layout shift */
.toast { transform: translateY(100%); transition: transform .3s; }
.toast.show { transform: translateY(0); }

Fix 6: Late-loading content and skeletons

Pages that fetch content with JavaScript (product grids, price widgets, reviews) should render skeleton placeholders at the final size, then swap in the real content in place. Also check:

  • Infinite scroll and "Load more" should add content below the viewport, not above it.
  • Sliders and carousels should have a fixed height before their script initialises.
  • Pages restored from the back/forward cache (bfcache) avoid shifts entirely, so do not block bfcache with unload event handlers.

Cumulative layout shift: CLS fixes for WordPress sites

  • Check slider plugins and page builders for missing image dimensions; many lazy-load images without width and height.
  • Do not lazy-load the hero image. It should load immediately, which also helps LCP.
  • If a caching plugin offers "delay JavaScript", test it carefully; scripts that build layout (menus, sliders) can cause large shifts when delayed.
  • Preload fonts and disable Google Fonts loading from the theme if you self-host them.

Cumulative layout shift: CLS checklist

CheckFix
Images, videos, iframes without dimensionsAdd width and height, or aspect-ratio
Ads and embeds pushing contentmin-height on the slot
Text jumping when fonts loadPreload, self-host, metric-matched fallback
Top banners inserted after loadRender early, overlay, or reserve space
Animations moving other contentUse transform and opacity
JavaScript-rendered sectionsSkeletons at final size

Cumulative layout shift: frequently asked questions

Cumulative layout shift: does CLS affect Google rankings?

CLS is one of the three Core Web Vitals used in Google's page experience signals. It is a small factor compared with content relevance, but it directly affects how usable the page feels, especially on phones.

Why does Search Console show poor CLS when Lighthouse shows zero?

Search Console uses real-user field data that includes shifts after load, such as when people scroll. Lighthouse only measures the initial load in a lab.

How long until Search Console shows the improvement?

Field data is a rolling 28-day average, so expect about four weeks after the fix. Use "Validate fix" in the Core Web Vitals report to track it.

Do lazy-loaded images cause CLS?

Only if they have no dimensions. Lazy-loaded images with width and height reserve their space and do not shift.

Related guides: 404 Error, 403 Forbidden Error and ERR_TOO_MANY_REDIRECTS.

For official guidance, see web.dev by Google.

Want your Core Web Vitals fixed?

Our speed and performance optimization service finds and fixes CLS, LCP and INP problems on WordPress and custom sites. Also read our guides to good page load times and speeding up WordPress, or contact us.

Written by the ItsWebExpert team, a web design and development company in Karachi building websites, online stores and apps for businesses across Pakistan.

Ask a Question on WhatsApp

Let's Build Your
Next Website

Tell us what you need and we will reply within 24 hours with honest advice and a fixed quote.

Trusted by our clients, rated 5.0 on Google

5.0 11 Google reviews Read all →
I had a great experience working with Waqas and his team. We got some website development and SEO work done, and I'm quite satisfied with the overall results. They understood our requirements, suggested improvements, and handled the work professionally. What I appreciated most was their communication, attention to detail, and willingness to make changes whenever needed. Waqas is very cooperative, and the team knows what they're doing. Definitely a good choice for anyone looking for reliable web development and digital marketing services.
HUHafiz Ubaid Google review · Nov 2026
I was referred to their company by someone, and I'm really glad I connected with them. Waqas, the CEO, is a very humble and professional person who leads his team exceptionally well. Their expertise in digital marketing, web development, and custom development services is impressive. The team is skilled, responsive, and committed to delivering quality work. Had a really positive experience working with them. Highly recommended!
MRMuhammad Rafeeq Google review · Nov 2026
I had hired them for my client's task of Custom Wordpress plugin development. and many other tasks later on.. Waqas is super fast and sharp.. I know him since 2019.. I really really appreciate his work. Highly recommended..
RFRaheela Farooqui Google review · Nov 2026
I had a positive experience working with Waqas and his team. They provided excellent support with graphic design and social media management. The team was professional, responsive, and attentive to our needs. They understood our vision and delivered quality work on time. Highly recommended for anyone looking for creative and reliable digital services.
URUsman Rock Google review · Nov 2026
I really appreciate their dedication and professionalism. They have a good understanding of SEO, social media marketing, and online brand growth. Communication is smooth, and the quality of work is impressive. Definitely a great team to work with!
SSSameer Sarafaraz Google review · Nov 2026
I've had a great experience working with their team. They understand digital marketing very well and know how to improve online visibility through effective SEO and marketing strategies. Professional, responsive, and reliable. Highly recommended! 🙌❤️
MNMohammad naveed Google review · Nov 2026
I had a really good experience with web Experts. Everything was easy to understand, well-organized, and user-friendly. I appreciate the effort and attention to detail that has gone into creating this platform. It was a smooth and pleasant experience, and I would definitely recommend it to others. Keep up the great work!
SSShazia shaikh Google review · Nov 2026
Extremely professional and committed I am Extremely happy to work with them I wish them best of luck Best Regards M. Salman Farooqui
SFSalman Farooqui Google review · Nov 2026
Outstanding experience! Quality, professionalism, and customer service are all excellent. Keep up the great work!
ARabdul rehman Google review · Nov 2026
Excellent service and a great experience. The team is professional, helpful, and dedicated. Highly recommended!
MEmustafa emb Google review · Nov 2026