Lighthouse audit unsized-images · Performance

"Image elements do not have explicit width and height": how to fix it

Quick answer: Lighthouse flags "Image elements do not have explicit width and height" when an img has no size the browser can read before the file loads, so content below it shifts and CLS rises. Fix it by adding the real pixel size as width and height attributes, then keep it responsive with max-width: 100% and height: auto in CSS.
View raw .md for LLMs / your notes

Lighthouse prints Image elements do not have explicit width and height when an <img> on the page has no size the browser can read before the file downloads. Without that size, the browser lays the page out with a zero-height box, then pushes everything below it down when the image arrives. That jump is a layout shift, and it counts toward Cumulative Layout Shift (CLS), a Core Web Vital. In our study of 269 Shopify storefronts, 127 of them (47.2%) failed this audit. This page covers what Lighthouse checks, why width: 100% in CSS does not pass it, and the one-line fix for HTML, WordPress, Shopify, React and Next.js.

TL;DR

What does "Image elements do not have explicit width and height" mean?

The browser builds the layout before most images finish downloading. If the <img> tag tells it the image's size, it reserves a box of the right shape and the page does not move later. If the tag does not, the box starts at zero height and grows when the file arrives.

Lighthouse lists every image that has no usable size. Per the audit source, an image passes when it has any one of these:

The image hasPasses?
width and height HTML attributesYes
CSS width and CSS height, neither set to autoYes
A width (HTML or CSS) plus CSS aspect-ratioYes
A height (HTML or CSS) plus CSS aspect-ratioYes
Only CSS width: 100% with height: autoNo
No size at allNo

Lighthouse skips images that cannot shift the layout: CSS background images, images inside a shadow root, images with position: fixed or position: absolute, inline SVG data URIs, and images that are not displayed. The audit carries no weight in the Performance score by itself. It explains the score through CLS, which carries 25% of it.

Why does width: 100% not fix it?

Because CSS height: auto is not an explicit height. The rule img { width: 100%; height: auto; } tells the browser how wide to draw the image, but not how tall, so it still has to wait for the file to know the shape. Lighthouse treats auto, initial, unset and inherit as "not set".

The fix is not to remove that CSS. Keep it, and add the HTML attributes. Modern browsers use the width and height attributes to compute an aspect ratio before the image loads, so the box has the right height at any rendered width.

How do I fix it?

1. Add width and height attributes with the image's real size

Use the intrinsic pixel size of the file, not the size it displays at:

<img src="/hero.jpg" alt="Spring collection" width="1600" height="900">

Then keep the image responsive in CSS:

img {
  max-width: 100%;
  height: auto;
}

The browser reads 1600 by 900 as a 16:9 ratio and reserves a 16:9 box at whatever width the layout gives it. The image still scales, and nothing shifts.

2. For srcset images, use the size of the src file

Every file in a srcset should have the same aspect ratio. Put the dimensions of the default src in the attributes. If you use <picture> with art direction (different crops per breakpoint), set width and height on each <source> element too; current Chrome, Firefox and Safari read them.

<picture>
  <source media="(max-width: 600px)" srcset="/hero-square.jpg" width="800" height="800">
  <img src="/hero-wide.jpg" alt="Spring collection" width="1600" height="900">
</picture>

3. Use CSS aspect-ratio when you cannot touch the HTML

If a CMS or a component library writes the <img> tag, set a width and an aspect ratio in CSS. Lighthouse accepts a width plus aspect-ratio:

.product-card img {
  width: 100%;
  aspect-ratio: 4 / 5;
  object-fit: cover;
}

Use object-fit: cover so images with a slightly different ratio crop instead of stretching.

4. Reserve space for lazy-loaded images too

loading="lazy" does not remove the need for dimensions. A lazy image without them shifts the page when the visitor scrolls to it, which still counts toward CLS in the field. Lighthouse lists lazy images in this audit as well.

How do I fix it in WordPress, Shopify, React, or Next.js?

Can I fix this for third-party images?

Usually yes, because the space belongs to your layout even when the image does not. Review widgets, ad slots and embedded badges inject their own <img> tags. Wrap them in a container with a fixed min-height or an aspect-ratio, so the space is reserved before the widget renders. That fixes the shift even though Lighthouse may still list the vendor's tag.

How do I verify the fix?

  1. Re-run Lighthouse. The images you fixed should be gone from Image elements do not have explicit width and height.
  2. In DevTools, select the image in the Elements panel. The computed aspect-ratio should read auto 1600 / 900 (your dimensions), which shows the browser is using the attributes.
  3. Open the Performance panel, record a reload, and check the Layout shifts track. The shift at the moment the image loaded should be gone.
  4. Watch CLS in the Lighthouse report and in field data. That is the metric this audit protects.

What mistakes should I avoid?


Audit your URL at https://lighthouse-md.com.

Audit your page now

Paste your URL, get scores plus a CLAUDE.md plan for Claude Code.

Run audit →
Add us as a preferred source on Google

One click, and Google shows more of lighthouse-md.com in your search results.