Performance & SEOintermediate

Fix Cumulative Layout Shift (CLS) in WordPress: A Practical Guide

High CLS score? Fix WordPress layout shifts caused by unsized images, misconfigured lazy-load plugins, and font swaps with our step-by-step guide.

Published
Dark technical dashboard with orange layout-shift displacement arrows and a CLS metric gauge glowing against a pitch-black background.

Cumulative Layout Shift (CLS) measures how much page content moves unexpectedly while loading. A CLS score above 0.1 fails Google’s Core Web Vitals threshold and can suppress search rankings. The most common causes in WordPress are images missing explicit dimensions, above-the-fold content lazy-loaded by optimization plugins, and custom fonts swapping in after initial render.

Fixing CLS requires first identifying which elements are shifting. Guessing at causes wastes time. Start with PageSpeed Insights, then work through the specific causes it surfaces.

Measure and locate the layout shifts

Before changing anything, gather evidence:

  1. Open PageSpeed Insights and run your homepage and one representative inner page (such as a blog post or product page).
  2. Note the CLS value in the Core Web Vitals section. Values above 0.25 indicate severe shifting; 0.1 to 0.25 needs attention; below 0.1 passes.
  3. Scroll to the Diagnostics section and look for items labeled Avoid large layout shifts or Image elements do not have explicit width and height.
  4. For precise identification, open Chrome DevTools (F12), go to the Performance tab, check Screenshots, and reload the page. In the recorded timeline, look for Layout Shift markers (colored bars in the Experience row). Click one to see which elements shifted and by how much.

Record which elements are shifting before making any change—this lets you confirm each fix is working.

1. Add width and height to images

The most widespread cause of CLS in WordPress is images served without explicit width and height attributes. Without these, the browser cannot reserve the correct amount of vertical space before the image downloads, so surrounding text jumps downward once the image loads.

WordPress core behavior: Since WordPress 5.5, the block editor automatically adds width and height attributes to standard Image blocks from the media library. However, custom themes, shortcodes, and older page builder widgets often omit these attributes.

Check existing images: In Chrome DevTools, click the Elements tab and inspect any image that shifted. Look for missing or zero-value width and height attributes.

Fix images in the block editor: Select the image block and verify that its width and height are set in the block settings panel on the right.

Fix images in custom HTML or theme files: Add explicit attributes:

<img src="photo.jpg" width="800" height="450" alt="Description">

Fix via CSS for responsive images: If you cannot edit the HTML, reserve space with an aspect ratio rule. This is particularly useful for images set via CSS background or for containers that resize fluidly:

.hero-image-wrapper {
  aspect-ratio: 16 / 9;
  width: 100%;
  overflow: hidden;
}

For Elementor image widgets: Open the widget settings and confirm that the image dimensions are set explicitly. Go to Elementor → Tools → Regenerate Files & Data after updating settings to rebuild the cached CSS.

2. Fix lazy loading on above-the-fold content

Lazy loading defers the download of off-screen images until the user scrolls near them—an effective bandwidth saver for images below the fold. However, applying lazy loading to images that appear immediately on load (above the fold) causes a double shift: first the space collapses, then expands when the image arrives.

Identify the problem: PageSpeed Insights reports this as “Defer offscreen images” applied incorrectly to visible-on-load images. In DevTools, look for images with loading="lazy" that appear within the first viewport of your page.

Fix in your caching or optimization plugin: Most performance plugins (WP Rocket, LiteSpeed Cache, Autoptimize, Perfmatters) have a setting to exclude specific images from lazy loading. Exclude your:

  • Site logo and navigation images
  • Hero or banner image at the top of each page
  • First featured image on archive or blog pages

In WP Rocket: Media → LazyLoad → Excluded images or iframes — add the image filename or CSS class.

In LiteSpeed Cache: Page Optimization → Media → Lazy Load Exclude — add URI patterns.

Fix in WordPress core (if you are not using a plugin): WordPress 5.5+ applies loading="lazy" to images automatically. For images above the fold, explicitly set loading="eager" in your theme template:

echo wp_get_attachment_image( $image_id, 'full', false, array( 'loading' => 'eager' ) );

Or in HTML:

<img src="hero.jpg" width="1200" height="600" loading="eager" alt="Hero image">

3. Eliminate font-induced layout shifts

When a custom font (Google Fonts, Adobe Fonts, or a self-hosted typeface) loads after the page has rendered with a fallback system font, the text reflows as the custom font’s character dimensions differ from the placeholder font. This reflow shifts every element below the text block.

Diagnose font shifts: In the DevTools Performance timeline, font-shift events appear shortly after the page is visually stable. The shifted elements are typically headings or large body text blocks.

Fix with font-display: swap and preloading: font-display: swap tells the browser to display text immediately using the fallback font and swap in the custom font when it arrives—reducing the blank period but not eliminating the shift entirely. Pairing it with a preload hint minimizes the delay and reduces the visual jump:

<link rel="preload" href="/fonts/your-font.woff2" as="font" type="font/woff2" crossorigin>

Add this to your theme’s <head> section via functions.php or a child theme:

function webfixary_preload_fonts() {
    echo '<link rel="preload" href="' . get_template_directory_uri() . '/fonts/your-font.woff2" as="font" type="font/woff2" crossorigin>';
}
add_action( 'wp_head', 'webfixary_preload_fonts' );

Host fonts locally: Serving Google Fonts from Google’s CDN introduces a DNS lookup and connection setup that delays font availability. Hosting fonts on your own server eliminates this delay. The OMGF plugin automates this for Google Fonts and adds correct font-display: swap declarations automatically.

Size-adjust descriptor (advanced): CSS size-adjust lets you scale the fallback font to match the custom font’s metrics, so the swap causes no shift at all. Browser support is good across current Chrome, Firefox, and Safari versions. This requires measuring your custom font’s metrics and writing custom @font-face declarations for the fallback.

4. Reserve space for ads, banners, and dynamic embeds

Advertisements, cookie consent banners, and social media embeds inject content asynchronously. If no space is reserved for them, they push existing content downward when they load.

Wrap ad units in a container with a fixed minimum height:

<div class="ad-slot" style="min-height: 250px;">
  <!-- Ad code here -->
</div>

Match the minimum height to the ad unit size. Standard Google AdSense display units are 250px, 600px, or 90px tall depending on the format.

Cookie consent banners: Configure your cookie notice plugin to position the banner at the bottom of the viewport (not sliding from the top, which shifts all page content). In most cookie plugins (Complianz, Cookiebot, CookieYes), the placement is controlled in Settings → Banner Position. Select Bottom or Bottom bar to avoid top-entry shifts.

Embedded iframes (YouTube, Google Maps, tweets): Reserve the iframe’s dimensions explicitly:

<div style="aspect-ratio: 16/9; width: 100%;">
  <iframe src="..." loading="lazy" width="560" height="315" title="Video title" allowfullscreen></iframe>
</div>

5. Review animation and JavaScript-injected content

CSS transitions that animate height, top, bottom, margin, or padding trigger layout recalculations and cause CLS. Transitions on transform and opacity do not trigger layout and are safe.

Review your theme’s CSS for properties that animate layout-affecting values:

/* Causes CLS — avoid */
.card:hover {
    margin-top: -8px;
}

/* Safe alternative */
.card:hover {
    transform: translateY(-8px); /* Only if AGENTS.md allows — note: WebFixary prohibits upward translate on hover */
}

Per WebFixary’s design rules, upward translateY on hover is prohibited. Hover feedback must rely on border, surface color, or text highlight changes instead of positional translation.

JavaScript that inserts content above existing page content (such as a notification bar that appears after page load) also causes layout shifts. Defer insertion until after user interaction, or reserve the banner space on page load even when the content is hidden.

6. Test after each fix

Run PageSpeed Insights again after each individual change to confirm improvement. CLS scores can fluctuate between runs because of network timing; run the test three times and average the scores to get a reliable baseline.

Also test on mobile—many CLS issues are more severe on mobile due to slower resource loading and different viewport dimensions.

Verify the recovery

  1. Run PageSpeed Insights on your homepage and at least two inner pages. Target a CLS value below 0.1 on both mobile and desktop.
  2. In Chrome DevTools Performance, confirm that no Layout Shift events appear after the first 500 ms of page load (initial render is expected; post-load shifts are the target of CLS).
  3. Check the Core Web Vitals report in Google Search Console (under Experience → Core Web Vitals) for field data from real users. Field data lags 28 days behind your fixes, so allow time for the report to reflect changes.

If CLS is part of a broader Largest Contentful Paint (LCP) problem on your WordPress site, work through our LCP improvement guide in parallel—the fixes for image loading and font delivery overlap significantly.

For pages that are not being indexed by Google despite passing Core Web Vitals, see our page not indexed guide and the crawled but not indexed guide.

Source and version notes

This guide was verified against WordPress 6.7, Google Chrome 130, and the Web.dev CLS guidance published at web.dev/articles/cls. The CLS threshold of 0.1 is the Good tier defined by Google’s Core Web Vitals initiative. PageSpeed Insights scores may differ from Chrome User Experience Report (CrUX) field data.

Tags:
  • #CLS
  • #Core Web Vitals
  • #layout shift
  • #WordPress performance
  • #PageSpeed Insights

References

  1. web.dev
  2. web.dev
  3. pagespeed.web.dev
  4. developer.chrome.com
  5. wordpress.org