Layout shift is when content jumps while a page loads, like a button moving just as you tap it. Cumulative Layout Shift (CLS) measures it, and 0.1 or less is good. The causes are predictable and usually simple to fix once you know where to look. Here are the ones I find most often and how to solve each.
How CLS is measured
CLS adds up unexpected layout shifts that happen while the page is open, grouped into short windows, and reports the largest window. Each shift’s score depends on how much of the screen moved and how far. Shifts that happen right after a user interaction, such as opening a menu, are not counted.
Because CLS is measured during the whole visit, shifts can happen after the page seems loaded, for example when an ad or widget appears while scrolling. Field data from real users may show problems lab tests miss.
Finding what shifts
PageSpeed Insights lists the elements causing the largest layout shifts. Chrome DevTools’ Performance panel shows layout shift regions, and the Rendering panel can highlight shifts as they happen. The Web Vitals extension logs shifts in the console with the elements involved.
Test on mobile with a slow connection, which makes late-loading content more noticeable. Scroll through the whole page, since some shifts only happen further down.
- Image dimensionsWidth and height set
- Reserved spaceAds and embeds
- Overlay bannersNot pushing content
- Font metricsMatched fallbacks
- Injected contentMin-height containers
- Transform animationsNot top or margin
Images and videos without dimensions
If an image has no width and height attributes, the browser does not know how much space to reserve, so content below moves when the image loads. This is the most common cause of CLS. WordPress adds dimensions to images in content, but themes, builders and custom code sometimes omit them.
Add width and height attributes to every image, or use CSS aspect-ratio for containers. The image can still be responsive; the attributes only tell the browser the proportions. Apply the same to videos, iframes and embeds.
Ads and embeds
Ads, social embeds, maps and video embeds often load late and push content down. Reserve space for them with a fixed-height container matching the expected size. If an ad slot might be empty, keep the space or use a placeholder rather than collapsing it.
For embeds like YouTube, use a lightweight facade with the correct aspect ratio that loads the player on click. See embedding videos without slowing your page.
Cookie banners and announcement bars
Cookie consent banners and announcement bars that insert themselves at the top of the page push everything down. Display banners as overlays fixed to the bottom or top of the screen, rather than inserting them into the page flow.
If an announcement bar must be part of the layout, render it in the initial HTML rather than adding it with JavaScript after load. Many themes support this natively.
Web fonts swapping
When a web font loads and replaces a fallback font, text can change size and reflow, shifting content. Using font-display swap shows text quickly but can cause this shift if the fallback font has different metrics.
Choose a fallback font with similar proportions, and use the CSS size-adjust and related descriptors to match metrics more closely. Preload the main font so it arrives sooner. See loading web fonts without slowing your site.
Content injected by JavaScript
Elements added by JavaScript after the page loads, such as related products, review widgets, newsletter forms or personalised content, cause shifts if space is not reserved. Load them into containers with a minimum height, or place them below the visible area.
Sliders and carousels that initialise with JavaScript often shift as slides are arranged. Give the slider container a fixed aspect ratio so the first slide occupies the right space from the start.
Animations that move layout
Animations that change properties like top, margin, height or width trigger layout changes and can count as shifts. Use transform and opacity for animations instead, which do not affect the surrounding layout.
Entrance animations in page builders sometimes start with elements offset or hidden in ways that affect layout. Test them and remove unnecessary animations, especially above the fold.
Platform-specific issues
On WordPress, check page builder sections, sticky headers that change height, and plugins that insert notices or popups. On Shopify, app widgets that load late, such as reviews or upsells, are common causes. See speeding up a Shopify store.
Sticky headers that shrink on scroll should not affect the content below. Use position fixed or sticky with reserved space, and animate with transforms.
Layout shift on mobile menus and headers
Headers are a common source of shift on mobile. Logos without dimensions, menus that render differently once JavaScript loads and headers that switch between layouts at load time all move the content below. Set explicit sizes for the logo and keep the header’s height consistent from the first paint.
Test the header on a slow connection with the cache cleared. If the header jumps when fonts or scripts load, reserve its height in CSS and render the mobile menu button in the initial HTML. Small fixes here affect every page of the site, so they often improve CLS across the board.
Confirm the fix
After fixing, test the page again in PageSpeed Insights and DevTools, then wait for field data to update in Search Console over the following weeks. Use the validation button in Search Console’s Core Web Vitals report to confirm the fix.
If you would like help finding and fixing layout shift, it is part of my speed optimization service. For the other metrics, see Core Web Vitals explained.
Key takeaways
- Add width and height to every image, video and iframe.
- Reserve space for ads, embeds and late-loading widgets.
- Show cookie and announcement banners as overlays.
- Animate with transform and opacity, not layout properties.
Frequently asked questions
How can I see what shifts?
Chrome DevTools' Performance panel highlights layout shift regions, and PageSpeed Insights lists the elements.
What is a good CLS score?
0.1 or less at the 75th percentile of real visits.
Do shifts after clicking count?
Shifts within a short time after a user interaction are excluded.
Can fonts cause layout shift?
Yes, when the web font replaces a fallback with different metrics.
Why does lab CLS differ from field CLS?
Lab tests usually capture only loading. Field data includes shifts during scrolling and the whole visit.
