An image causes Cumulative Layout Shift when the browser doesn't know its dimensions before the file arrives, so it renders a zero-height box, then resizes the page once the image loads. Explicit width/height attributes, or a CSS aspect-ratio, fix the shift regardless of file format or size.

Listen to this article4 min audio summary · AI voice
Read the script

This is a spoken summary of the guide on why images cause layout shift and how to stop it. The comparison tables and the full list of fixes are on the page.

The short answer. An image causes Cumulative Layout Shift when the browser doesn't know its dimensions before the file arrives. It renders a zero-height box, then resizes the page once the image loads. Explicit width and height attributes, or a C S S aspect ratio, fix the shift regardless of file format or size.

The takeaways. C L S from images is a missing-dimensions bug, not a file-size bug. A five kilobyte image with no width and height causes the identical shift a five megabyte one would. Width and height attributes still matter even when C S S controls the final display size, because they let the browser work out the aspect ratio before any stylesheet or image byte has arrived. WebP and AVIF help Largest Contentful Paint by shrinking the file so it arrives sooner, but they do nothing for C L S. Google's thresholds are under zero point one good, zero point one to zero point two five needs improvement, and above zero point two five poor, measured across the page's whole lifespan.

The mechanism. A browser lays out a page top to bottom as the HTML arrives. For most elements it can work out size immediately. An image is different, because its true size depends on a file that hasn't downloaded yet. Without a hint, the browser has two bad options: wait for the image before laying out anything below it, which is slow, or render a zero-height placeholder and resize everything once the real size is known. Browsers do the second, and that jump in text, buttons and other images is exactly what C L S measures. The fix removes the ambiguity, not the wait. Width and height, or an aspect ratio, give the browser the ratio up front so it reserves the right box on the first pass.

What fixes C L S and what doesn't. Adding width and height attributes: yes. Setting a C S S aspect ratio: yes. Switching from JPEG to WebP or AVIF: no, that is a smaller file and faster download, so it helps L C P, not C L S. Adding a srcset for responsive sizes: no, also an L C P lever. Lazy-loading below-the-fold images: indirect, since it can prevent shifts from late-arriving images if dimensions are still reserved.

The trap is fixing the wrong lever first. A site with a poor C L S score that converts every image to AVIF will see its L C P improve and its C L S stay exactly where it was. Diagnose which metric is actually failing before picking the fix.

On this site, there are no image tags at all. Every icon is inline S V G with explicit dimensions, so there is no image-loading step for the browser to guess about. That is not a universal recommendation, because a product photo or a screenshot needs a real image. It is simply the checkable reason this bug class doesn't apply here.

What is documented and what isn't. Missing width and height causing shift is documented and reproducible in any browser's performance panel. Google's thresholds are documented. That AVIF is always smaller than WebP is only inferred, true in many comparisons but the margin varies. And that switching image format improves C L S is unsupported: format affects download speed, not whether space was reserved.

On a site that does use images: set width and height on every image tag, matching the file's real aspect ratio, not the display size. Or set an aspect ratio in C S S if the display size is responsive. Reserve space for ads and embeds too, since the same mechanism hits iframes and injected widgets. And then, separately, handle format and sizing as a load-speed fix. Two related notes: an image with a width attribute and no max width made a three hundred ninety pixel page eight hundred sixteen wide in the sideways-scroll measurements, so use max width one hundred percent. And leaving lazy loading off the first image protects L C P.

Key takeaways

  • CLS from images is a missing-dimensions bug, not a file-size bug — a 5KB image with no width/height causes the identical shift a 5MB one would.
  • width and height HTML attributes still matter even when CSS controls the final display size, because they let the browser compute the intrinsic aspect ratio before any stylesheet or image byte has arrived.
  • WebP and AVIF help Largest Contentful Paint, by shrinking the file so it arrives sooner — they do nothing for CLS specifically.
  • Google's published CLS thresholds: under 0.1 is good, 0.1–0.25 needs improvement, above 0.25 is poor, measured across the page's full lifespan.
  • This site has zero <img> tags — every icon is inline SVG with explicit dimensions, which sidesteps the entire bug class by construction rather than by discipline.
Build quality · Core Web Vitals

What fixes layout shift, and what only speeds loading

2 Fixes layout shift1 Indirect2 Does not
Add width/height attributes
Layout shift: Yes
Set CSS aspect-ratio
Layout shift: Yes
Switch JPEG to WebP/AVIF
Layout shift: No
Add a srcset for responsive sizes
Layout shift: No
Lazy-load below-the-fold images
Layout shift: Indirect
What actually fixes CLS vs. what only affects load speed. Green fixes CLS; red does not.

The actual mechanism

A browser lays out a page top to bottom as HTML arrives, and for most elements it can compute size immediately from CSS or content. An <img> tag is different: its true size depends on a file that hasn't downloaded yet. Without a hint, the browser has two bad options — wait for the image before laying out anything below it (slow), or render a zero-height placeholder and resize everything once the real dimensions are known (the layout shift). Modern browsers do the second, and that resize — text, buttons and other images jumping position — is exactly what Cumulative Layout Shift measures.

The fix removes the ambiguity, not the wait. width and height attributes (or a CSS aspect-ratio) give the browser the image's aspect ratio before the file itself has to answer that question, so it can reserve the correct box on the very first layout pass. The image still takes the same time to download; it just never has to un-announce a wrong guess about its own size.

What actually fixes CLS vs. what only affects load speed.
Change Fixes layout shift? What it actually does
Add width/height attributesYesLets the browser reserve the correct box before the file loads
Set CSS aspect-ratioYesSame effect as width/height, set in CSS instead of HTML
Switch JPEG to WebP/AVIFNoSmaller file, faster download — helps LCP, not CLS
Add a srcset for responsive sizesNoServes an appropriately-sized file per viewport — also an LCP lever, not CLS
Lazy-load below-the-fold imagesIndirectCan prevent shift caused by late-arriving images pushing visible content, if dimensions are still reserved
The trap: fixing the wrong lever first. A site with a poor CLS score that responds by converting every image to AVIF will see its LCP improve and its CLS stay exactly where it was — because AVIF conversion never touched the actual cause. Diagnose which metric is actually failing before picking the fix; they share the word "image" but not the mechanism.

This site's own approach, checked not claimed

This site ships zero <img> tags — every icon across every page is inline SVG with explicit width and height attributes set directly on the <svg> element, so there is no image-loading step for the browser to guess about in the first place. That isn't offered here as a universal recommendation — a hosting-comparison screenshot or a product photo genuinely needs a raster image, and inline SVG doesn't substitute for one. It's included because it's the actual, checkable reason this particular build-quality bug class doesn't apply to this site's own pages, rather than leaving that unstated.

Documented vs. inferred vs. unsupported

What's actually established about image formats and layout shift.
Claim Status Basis
Missing width/height on an image can cause layout shift Documented Directly reproducible in any browser's Core Web Vitals / Performance panel
Google's CLS thresholds: good under 0.1, poor above 0.25 Documented Published directly in Google's Core Web Vitals documentation
AVIF is always smaller than WebP at equivalent visual quality Inferred True in many published comparisons, but the exact margin varies by image content and encoder settings — treated as a rule of thumb, not a fixed percentage
Switching image format improves CLS score Unsupported Format affects download speed (LCP), not whether the browser reserved layout space (CLS) — a common conflation in generic "image optimization" advice

Fixing it on a site that does use images

  1. Set width and height on every <img> tag, matching the file's real intrinsic aspect ratio — not the display size, the source file's actual ratio.
  2. Or set aspect-ratio in CSS if the display size is controlled responsively and a single HTML attribute pair can't cover every breakpoint.
  3. Reserve space for ads and embeds too — the same missing-dimensions mechanism causes CLS for iframes and injected third-party widgets, not just <img> tags.
  4. Then, separately, address format and sizing for load speed — AVIF/WebP and a responsive srcset — as an LCP optimization, not a CLS fix.
Curious what else on this site is measurably real vs. just claimed? The CSP hash worked example and the font-loading comparison do the same thing — check the site's own code, don't just assert it.
Images cause sideways scrolling too. An image with a width attribute and no max-width made a 390px page 816px wide in the sideways-scroll measurements. Dimensions fix the shift; max-width: 100% fixes the overflow. The other image rule is in lazy-loading your hero image: dimensions fix the shift, and leaving loading="lazy" off the first image protects LCP. The same Core Web Vitals appear in two reports that can disagree: PageSpeed green, Search Console red.

Sources and further reading

Primary documentation for the topics in this guide:

Badri Dutta

Software engineer · 20 years building for the web

20 years building for the web. This piece exists because "switch to WebP" gets repeated as CLS advice constantly, and it fixes a different metric entirely — worth separating the two clearly instead of letting the confusion persist.

Full background →