In short
An element whose size the browser does not know in advance first takes up zero pixels, then pushes everything after it when it arrives. These jumps are measured by CLS (Cumulative Layout Shift). This check consists of announcing the space of every late element: width and height attributes on images, aspect-ratio on videos and iframes, a minimum height on ad slots and injected blocks. Once it is done, the page loads without anything moving under the visitor's eyes or finger.
Why it matters
When an <img> tag carries width and height, the browser derives the width-to-height ratio from them and reserves the right area before receiving a single byte of the image, even when the CSS resizes it (max-width: 100%). Without these attributes, it only knows the height when the file arrives.
The problem is the same, and more pronounced, for anything inserted afterwards:
- ads: the slot is empty until the ad network responds, and the creative served is not always the same size;
- iframes and embedded content: video, map, social media post, review widget;
- banners: consent, promotion, app install prompt, inserted at the top of the page;
- content loaded by script: recommendations, related products, forms.
CLS adds up these shifts over the whole lifetime of the page, not just during loading. Shifts that immediately follow a visitor action (a click that expands a block) are not counted.
What it improves
- CLS This is the main action on this metric. See target CLS ≤ 0.1 at the 75th percentile (opens in a new tab).
- Comfort and conversion No more missed clicks because a button moved, no more paragraphs lost mid-read.
- Ad revenue A stable slot avoids accidental clicks, which break ad networks' policies.
- Rankings Indirect effect, through Core Web Vitals.
How to check
Images without declared dimensions, in the console:
[...document.images]
.filter((img) => !img.hasAttribute('width') || !img.hasAttribute('height'))
.map((img) => img.currentSrc || img.src);
An image sized only by a CSS aspect-ratio appears in this list even though it is correct: check case by case.
Shifts actually observed, with the element responsible:
new PerformanceObserver((list) => {
list.getEntries().forEach((entry) => {
if (entry.hadRecentInput) {
return;
}
console.log('Shift:', entry.value.toFixed(4), entry.sources.map((source) => source.node));
});
}).observe({ type: 'layout-shift', buffered: true });
Paste this code, then scroll slowly through the whole page. Compliant result: no lines, or negligible values.
Other methods:
- Developer tools:
Ctrl+Shift+P, “Show Rendering”, check “Layout Shift Regions”. Reload with network throttling to see the jumps. - PageSpeed Insights: the section on layout shift culprits lists the elements responsible and the images without dimensions. See analyze PageSpeed Insights and Lighthouse (opens in a new tab).
- Real-user data: lab tests do not scroll the page and do not always receive real ads. Compare with field CLS. See analyze real-user CrUX data (opens in a new tab).
How to implement
Before you start
Images. Give the file's actual dimensions, and let the CSS adapt:
img {
max-width: 100%;
height: auto;
}
<img src="/images/atelier-800.webp" width="800" height="533" alt="Assembly station in the workshop">
With <picture> and different crops depending on the screen, each <source> carries its own dimensions:
<picture>
<source media="(max-width: 600px)" srcset="/images/hero-portrait.webp" width="600" height="800">
<img src="/images/hero-paysage.webp" width="1600" height="700" alt="Overview of the workshop">
</picture>
Videos and iframes. Reserve the aspect ratio:
.embed {
width: 100%;
height: auto;
aspect-ratio: 16 / 9;
}
<iframe class="embed" src="https://www.youtube-nocookie.com/embed/VIDEO_ID"
title="Product demo" loading="lazy" allowfullscreen></iframe>
Embedded content of variable height (social media post, review widget, third-party form): wrap it in a container whose minimum height matches the content's usual height.
Banners. Display them as overlays (position: fixed, at the bottom of the screen) rather than inserting them above the content. A banner that must stay in the flow is rendered by the server, with its height, in the initial HTML.
Content loaded by script. Put in a placeholder block of the expected height, which the content replaces without changing size. Never insert content above what the visitor is reading, except in response to their action.
Animations. Animate transform and opacity, not top, margin, height or width.
Web fonts also cause shifts: see optimize fonts (opens in a new tab).
Ad slots
Reserve the height of the most likely format for each slot and each screen width:
.ad-slot {
display: flex;
align-items: center;
justify-content: center;
min-height: 250px;
background-color: #f5f5f5;
}
.ad-slot--banner {
min-height: 100px;
}
@media (min-width: 768px) {
.ad-slot--banner {
min-height: 90px;
}
}
<div class="ad-slot ad-slot--banner">
<div id="div-gpt-ad-header"></div>
</div>
Additional rules:
- Multi-size slots: reserve the height of the creative served most often (check the ad network's reports), not that of the smallest one.
- Unfilled slot: do not collapse it if it sits in or above the visible area. Keep the container and its neutral background.
- Auto ads: they insert themselves in places you do not control. Prefer manually placed units in reserved containers.
- Anchor ads at the bottom of the screen: they overlay the content and do not shift it.
- Lazy loading of slots lower on the page: the space is reserved from the start, only the ad request waits.
WordPress
Versions WordPress 6.4 and later (up to 7.1).
WordPress adds width and height to Media Library images inserted in the content. The cases to handle by hand:
- Images hard-coded in the theme or called by an external URL: add the attributes, or use
wp_get_attachment_image(). - SVG files and logos: give explicit dimensions in the tag or in CSS.
- Embedded content (YouTube, Vimeo): declare support for responsive embeds so that the block keeps its aspect ratio.
add_action('after_setup_theme', function (): void {
add_theme_support('responsive-embeds');
});
- Ads: ad management plugins (Advanced Ads, Ad Inserter) let you wrap each unit in a container. Give it the
ad-slotclass from the example above. - Plugin banners and pop-ups (consent, newsletter, promotion bar): choose a floating position at the bottom of the screen in their settings rather than a bar inserted at the top.
- Page builders: carousels and auto-height sections jump when their script initializes. Set a minimum height on these sections.
Shopify
Versions Online Store 2.0 themes (Liquid), November 2026.
The image_tag filter writes width and height automatically from the image's dimensions. Do not remove them (height: nil) without replacing them. For a video or a 3D model, reserve the media's aspect ratio:
<div class="media" style="aspect-ratio: {{ media.aspect_ratio }};">
{{ media | media_tag }}
</div>
App blocks (reviews, recommendations, countdown timers) are inserted afterwards: place them below the first screen when possible, or in a container with a minimum height.
PrestaShop
Versions PrestaShop 8 and 9 (Classic theme and derivatives).
Image sizes are known to the template. Reuse them in the tag:
<img src="{$product.cover.bySize.home_default.url}"
width="{$product.cover.bySize.home_default.width}"
height="{$product.cover.bySize.home_default.height}"
alt="{$product.cover.legend}" loading="lazy">
Also check the module templates (slider, banners, brands) and reserve the height of blocks loaded via Ajax, such as viewed products.
Magento
Versions Magento Open Source and Adobe Commerce 2.4 (up to 2.4.9).
Thumbnail dimensions are declared in the theme's etc/view.xml file and reused by the catalog image templates. Check that your theme does not strip the attributes, and that images in CMS blocks and Page Builder carry them. The product page gallery, built in JavaScript, needs a container with a reserved height: keep the styles of the gallery-placeholder block in your theme.
Drupal
Versions Drupal 10 and 11.
Images rendered by an image style or by the Responsive Image module carry their dimensions. What remains are images inserted in the text editor without dimensions and remote media (oEmbed), to be wrapped in a container with a reserved aspect ratio in the media's Twig template.
Wix
Versions Wix (Wix Editor and Wix Studio) and Squarespace, November 2026.
Media placed in the editor have reserved space. Shifts come from embedded HTML blocks and third-party apps: give the embed element the height of its final content. The same applies to Squarespace, for code blocks and embeds.
Webflow
Versions Webflow, all plans, November 2026.
Image elements receive their dimensions. For a Code Embed element (custom code), set a height or an aspect ratio on the element in the Style panel.
Laravel
Versions Laravel 11 to 13.
Store the dimensions on upload so you can write them in every tag:
[$width, $height] = getimagesize($request->file('image')->getRealPath());
$product->update([
'image_path' => $request->file('image')->store('products', 'public'),
'image_width' => $width,
'image_height' => $height,
]);
<img src="{{ Storage::url($product->image_path) }}"
width="{{ $product->image_width }}" height="{{ $product->image_height }}"
alt="{{ $product->name }}" loading="lazy">
Symfony
Versions Symfony 6.4 and later (up to 8.1).
Same approach: read the dimensions with getimagesize() on upload, store them on the entity and write them in Twig.
<img src="{{ asset(product.imagePath) }}"
width="{{ product.imageWidth }}" height="{{ product.imageHeight }}"
alt="{{ product.name }}" loading="lazy">
Next.js
Versions Next.js 15 and 16 (App Router and Pages Router).
next/image requires the size to be known: dimensions inferred automatically for an imported image, width and height props for a remote image. With fill, the parent reserves the space:
import Image from 'next/image';
export default function Cover({ src, alt }) {
return (
<div style={{ position: 'relative', aspectRatio: '16 / 9' }}>
<Image src={src} alt={alt} fill sizes="100vw" style={{ objectFit: 'cover' }} />
</div>
);
}
For a component loaded with next/dynamic, provide a loading component of the same height as the final component.
Nuxt
Versions Nuxt 3 and 4, Nuxt Image module.
Set width and height on NuxtImg and NuxtPicture. For a component rendered only on the client side, use the fallback slot of <ClientOnly> with a block of the expected height:
<ClientOnly>
<ReviewWidget />
<template #fallback>
<div style="min-height: 320px;"></div>
</template>
</ClientOnly>
Astro
Versions Astro 5 to 7.
The Image component infers the dimensions of local images placed in src/. For a remote image or one placed in public/, specify width and height, or use inferSize. For an island hydrated only on the client (client:only), pass fallback content of the same height in the fallback slot.
Common mistakes
- Attributes present but CSS without
height: auto: the image is distorted, and the attributes then get removed instead of fixing the CSS. - Dimensions that do not match the file's ratio: the reserved space is wrong and the image still jumps.
- Reserving the desktop ad height on mobile, or the other way round.
- Collapsing empty ad slots at the top of the page.
- Lazy-loading images without dimensions: lazy loading turns each image into a shift during scrolling. See lazy-load offscreen content (opens in a new tab).
- Inserting the consent banner at the top of the flow: the whole page moves down when it appears. See test before and after cookie consent (opens in a new tab).
- Only testing in the lab: shifts caused by scrolling, real ads and scripts loaded after consent do not show up there.
Frequently asked questions
Do responsive images still need width and height?
Yes. With the width and height attributes, the browser derives the image's width-to-height ratio and reserves the right area before receiving the file, even when the CSS resizes it with max-width: 100%. Add height: auto in the CSS to avoid any distortion. Without these attributes, the height is only known when the image arrives, and the content that follows jumps.
How do I stop ads from shifting the page?
Give each slot a minimum height matching the creative served most often, for each screen width, and keep the container with a neutral background when no ad is served in the visible area. Prefer manually placed units to auto ads, which insert themselves in places you do not control. Anchor ads at the bottom of the screen overlay the content without shifting anything.
Do shifts that follow a click count towards CLS?
No. Shifts that immediately follow a visitor action, such as a click that expands a block, are not counted in CLS. However, CLS covers the whole lifetime of the page, not just loading: a lazy-loaded image without dimensions, an ad or a block injected during scrolling degrade it just as much as a jump at load time.
How do I reserve space for an embedded YouTube video?
Give the iframe a width of 100%, an automatic height and an aspect-ratio of 16 / 9 in CSS: the browser reserves the right area before the player loads. On WordPress, declare support for responsive embeds (responsive-embeds) so that YouTube and Vimeo blocks keep their aspect ratio. For embedded content of variable height, use a minimum height instead.
Resources
- web.dev: Optimize Cumulative Layout Shiftweb.dev
- web.dev: Cumulative Layout Shiftweb.dev
- MDN: aspect-ratio propertydeveloper.mozilla.org
- Google Publisher Tag: Minimize layout shiftdevelopers.google.com
- Shopify: image_tag filtershopify.dev
- Next.js: Image componentnextjs.org
- Astro: Images referencedocs.astro.build
Updated on
Topic checklist (PDF)