Core Web Vitals CLS: How Much Do width and height on img Reduce Layout Shift?
Adding width and height attributes to <img> reserves the space before the image arrives, so the text no longer shifts when the image loads. On the page I tested, at a phone-sized screen (412px wide) with one 16:9 image, Core Web Vitals CLS (Cumulative Layout Shift) went from 0.1289 to 0. With three images, it went from 0.3143 to 0. These numbers give a rough idea of how much this helps on blog photos or e-commerce product images, where the text moves down while loading and PageSpeed Insights or Search Console report CLS as "needs improvement."
The test environment was Ubuntu 24.04, Node.js 22, web-vitals 5.3.0, and Lighthouse 13.6.0. The browser was Chrome for Testing 158, bundled with Playwright 1.63.0. The test page was served from a small server (localhost:8080), and only the images were delayed by 1 second. I measured CLS with web-vitals onCLS by opening the page in Playwright with a 412×823px screen and waiting 1.5 seconds after all images had loaded. I ran the same measurement three times and got the same value each time. I did not test real user data (PageSpeed Insights field data or Search Console), browsers other than Chrome, or images with loading="lazy".
- 1. The page used for the test
- 2. One 16:9 image: CLS went from 0.1289 to 0
- 3. The reduction is larger for tall images and pages with more images
- 4. At desktop width, the values were smaller
- 5. The Lighthouse performance score went from 96 to 100
- 6. If the aspect ratio in the attributes differs from the image, a small shift remains
The page used for the test
It is an article page with a heading, a paragraph, an image, and then more paragraphs. In CSS, I added max-width: 100% so that images do not overflow the phone screen. The original <img> has neither width nor height.
<style>
body { margin: 0; font-family: sans-serif; line-height: 1.7; color: #1f2a30; }
header { height: 56px; padding: 0 16px; display: flex; align-items: center; background: #eefafd; font-weight: bold; }
main { padding: 0 16px; max-width: 720px; margin: 0 auto; }
img { max-width: 100%; }
</style>
…
<h1>今日の記事</h1>
<p>本文の段落です(1)。…</p>
<img src="/photo-16x9.png?delay=1000" alt="検証用の画像1">
<p>本文の段落です(2)。…</p>
…(段落は全部で8つ)
In the fixed version, I set the image's original size (1200×675) on <img> and added height: auto to the CSS.
<style>
img { max-width: 100%; height: auto; }
</style>
…
<img src="/photo-16x9.png?delay=1000" alt="検証用の画像1" width="1200" height="675">
One 16:9 image: CLS went from 0.1289 to 0
At a 412px screen width, the image is displayed at 380×214. On the page without attributes, one layout shift was recorded about 1 second after the page opened, when the image arrived, and CLS was 0.1289. The web-vitals rating was needs-improvement. web.dev's CLS guide says that 0.1 or lower is "good" and above 0.25 is "poor." One image alone exceeded the "good" range.
The following is part of the output from running the measurement script (measure.cjs), showing the pages without attributes (none) and with attributes (attrs).
$ node measure.cjs none,attrs,attrs-no-auto,none-4x3,attrs-4x3,none-3x4,attrs-3x4,none-x3,attrs-x3,none-x3-stagger,wrong-ratio
none (412x823)
img (幅x高さ@上端): 380x214@278
layout-shift: 1018ms 0.1289
web-vitals onCLS: 0.1289 rating=needs-improvement
attrs (412x823)
img (幅x高さ@上端): 380x214@278
layout-shift: なし
web-vitals onCLS: 0.0000 rating=good
On the page with width and height, no layout shift was recorded and CLS was 0. Measuring the top edge of paragraph (2), below the image: on the page without attributes, it was at 321px before the image arrived and 517px after, so it moved down 196px. On the page with attributes, it was at 517px from the start.

As the MDN img element reference explains, when both width and height are given, the browser calculates the aspect ratio before the image loads and reserves the space needed for display using that ratio. Even when max-width: 100% shrinks the width to 380px, the height is fixed at 214px by the ratio, so the text below does not move later.
The reduction is larger for tall images and pages with more images
I changed the image's aspect ratio and the number of images, and measured in the same way. On every page, adding the attributes made CLS 0.
| Image | Displayed size | No attributes | With attributes |
|---|---|---|---|
| 16:9, 1 image | 380×214 | 0.1289 (needs-improvement) | 0 |
| 4:3, 1 image | 380×285 | 0.1702 (needs-improvement) | 0 |
| 3:4 (portrait), 1 image | 380×507 | 0.2982 (poor) | 0 |
| 16:9, 3 images | 380×214 each | 0.3143 (poor) | 0 |

The taller the image, the higher the value, because of how layout shift scores are calculated. According to web.dev's CLS guide, the score for one shift is the "impact fraction" (the fraction of the screen that the moving element covers before and after it moves) multiplied by the "distance fraction" (how far it moves, as a fraction of the screen). A taller image means the text below it moves a longer distance, which raises the score.
On the three-image page, I made the three images arrive at the same time. In this case, the shift was recorded as one event, and CLS was 0.3143.
When the load times differ, shifts are not grouped together
I also tested a page where the three images arrived at 1 second, 2.5 seconds, and 4 seconds.
none-x3-stagger (412x823)
img (幅x高さ@上端): 380x214@278 380x214@641 380x214@1003
layout-shift: 1017ms 0.1090, 2517ms 0.0289
web-vitals onCLS: 0.1090 rating=needs-improvement
The shift was recorded twice, and CLS was 0.1090, the larger of the two rather than their sum. The web.dev guide explains that CLS groups shifts that occur less than 1 second apart into one session window, up to 5 seconds long, and uses the largest such group. My two shifts were 1.5 seconds apart, so they were counted as separate groups. The third image, which arrived at 4 seconds, has its top edge at 1003px, which is outside the 823px-tall screen. Movement of elements outside the screen did not record a layout shift.
At desktop width, the values were smaller
I also measured the same pages on a 1350×940px screen. Because the text width stops at max-width: 720px, a 16:9 image is displayed at 720×405.
| Image | No attributes | With attributes |
|---|---|---|
| 16:9, 1 image | 0.0884 (good) | 0 |
| 3:4 (portrait), 1 image | 0.1503 (needs-improvement) | 0 |
| 16:9, 3 images | 0.1932 (needs-improvement) | 0 |
On the same page, a single 16:9 image fell in the "good" range on the desktop screen. The value (0.0884) is smaller than on the phone screen (0.1289). The CLS shift score is determined by proportions relative to the screen size, so the same page gets different values depending on screen size. With the attributes, the result was 0 at both sizes.
The Lighthouse performance score went from 96 to 100
When I ran Lighthouse from the command line with its default settings (mobile, 412×823), I got nearly the same values. I used the Playwright Chrome for Lighthouse through the CHROME_PATH environment variable. I added --quiet so that Lighthouse itself prints nothing. The exit: line is the exit code. The lines below it show the performance score, CLS, and warnings about images without width and height (unsized-images), extracted from the result JSON by a small script.
$ npx lighthouse http://localhost:8080/none.html --only-categories=performance --output=json --output-path=./out/none.json --chrome-flags="--headless=new --no-sandbox" --quiet
exit: 0
lighthouseVersion: 13.6.0
requestedUrl: http://localhost:8080/none.html
formFactor: mobile screen: 412x823
performance score: 96
CLS: 0.1282 displayValue=0.128 (score 0.82)
unsized-images: score=0.5 items=1
unsized-images with items=1 means one image was flagged. On the three-image page, it was items=3, and with attributes it was 0. Here are the results for the four pages:
| Page | CLS | Performance score |
|---|---|---|
| 16:9 ×1, no attributes | 0.128 | 96 |
| 16:9 ×1, with attributes | 0 | 100 |
| 16:9 ×3, no attributes | 0.312 | 84 |
| 16:9 ×3, with attributes | 0 | 100 |
On this page, nothing other than the images lowered the score, so when CLS went to 0, the score went to 100.
If the aspect ratio in the attributes differs from the image, a small shift remains
width and height should be the image's original dimensions. On a page where a 16:9 image had 4:3 numbers (width="1200" height="900"), CLS was 0.0298.
wrong-ratio (412x823)
img (幅x高さ@上端): 380x214@278
layout-shift: 1016ms 0.0298
web-vitals onCLS: 0.0298 rating=good
Comparing before and after the image arrived, <img> shrank from 380×285 (the 4:3 ratio) to 380×214, and the top of paragraph (2) moved up 71px, from 587px to 516px. web.dev's guide on improving CLS also says that if the attributes don't match the image's size, a small shift still occurs after the image arrives. The value is much lower than 0.1289 and falls in the "good" range, but it did not reach 0.
Another page had only the attributes added, without height: auto. CLS was 0 there, but the image was displayed at 380×675. The width shrank because of max-width: 100%, but the height stayed at the attribute's 675px, so the image was stretched vertically. When you use max-width: 100%, also write height: auto.
In cases such as HTML output by a CMS, where you cannot add attributes to <img>, the web.dev guide suggests reserving the space with CSS such as aspect-ratio instead.





