Fix "Image Elements Do Not Have Explicit Width and Height"

You run Lighthouse or PageSpeed Insights, and there it is: "Image elements do not have explicit width and height." Meanwhile your Cumulative Layout Shift score is sitting in the red, your page visibly jumps as it loads, and visitors keep tapping the wrong button because content shifted out from under their thumb right as they clicked.

The warning sounds like a minor accessibility nitpick, but it's usually the single biggest lever you have on CLS. When the browser doesn't know how big an image will be, it renders the layout as if the image takes up zero space — then, the instant the file finishes downloading, everything below it lurches down the page to make room. Fixing this is mechanical, fast, and rarely touches your design at all.

Quick Answer

Add explicit width and height attributes (or a CSS aspect-ratio) to every <img> tag on the page. This lets the browser reserve the correct amount of space before the image loads, so nothing shifts once it arrives. Combine it with width: 100%; height: auto; in CSS to keep images responsive, and audit lazy-loaded or dynamically inserted images separately — they need the same fix applied the moment their placeholder appears.

What actually causes this warning?

This warning fires whenever an <img> tag reaches the browser without enough information for it to calculate an aspect ratio up front. A few different root causes usually stack together:

The key insight: the browser can calculate correct on-screen space for any image the instant it knows two numbers — width and height (or their ratio). Every fix below is just a different way of supplying that ratio before the pixels arrive.

Why it matters

Layout shift isn't just visually annoying — it's a measured, scored part of how modern browsers and search engines judge a page's usability:

📊 Quick stat On image-heavy pages, missing width and height attributes are commonly the single largest contributor to a poor CLS score — fixing just this one issue frequently moves a page from "poor" (above 0.25) into the "good" range (under 0.1) with no other changes.

Step-by-step: fix explicit width and height

  1. Find the flagged images. Run Lighthouse, PageSpeed Insights, or your browser's DevTools audit to get the exact list of <img> tags missing dimensions.
  2. Get each image's real dimensions. Use an Image Dimension Checker to pull the exact intrinsic width and height in pixels for every file, rather than guessing or eyeballing them.
  3. Add width and height attributes to the HTML. Set width and height directly on the <img> tag using the image's natural pixel dimensions — this is what lets the browser calculate the correct aspect ratio immediately.
  4. Keep images responsive with CSS. Add width: 100%; height: auto; (or max-width: 100%) in your stylesheet so the image still scales to its container, while the HTML attributes preserve the ratio.
  5. Use CSS aspect-ratio where HTML attributes aren't practical. For background images, generated thumbnails, or elements without a natural width/height, set aspect-ratio: width / height; on the container to reserve the same space.
  6. Size placeholders for lazy-loaded images. Give skeleton boxes or lazy-load placeholders the same aspect ratio as the final image, applied the moment the placeholder enters the DOM — not after the real image arrives.
  7. Re-run Lighthouse and check the CLS score. Use an Aspect Ratio and CLS Calculator to confirm the reserved space matches the delivered image and that your CLS score has moved into the "good" range.
Try the Rebrixe Image Dimension Checker — free Upload or link an image to get its exact width, height, and ratio instantly.
Check Image Dimensions →

Common mistakes that leave CLS unfixed

1. Setting dimensions in CSS but not HTML

Sizing images purely through a stylesheet class works visually, but some rendering paths still need the HTML attributes present for the earliest layout pass. Set both — the attributes for guaranteed space reservation, CSS for responsive scaling.

2. Using width without height, or vice versa

A single dimension isn't enough for the browser to compute an aspect ratio. Both width and height (or an explicit aspect-ratio) need to be present together, or the space reservation calculation has nothing to work from.

3. Forgetting srcset and responsive variants

Teams often fix the default src image but leave srcset entries pointing to differently-cropped variants with a different ratio. If the served image doesn't match the declared ratio, the browser still shifts to correct it.

4. Only auditing above-the-fold images

Lazy-loaded galleries, infinite scroll feeds, and below-the-fold product grids cause exactly the same shift the moment they load — they just happen later in the session, which makes them easy to miss during a quick manual check.

💡 Pro tip Bake width and height attributes into your CMS or component templates so every future image is covered automatically, instead of retroactively auditing new images every time content gets published.
Not sure what CLS score your fix produced? Use the Rebrixe Aspect Ratio and CLS Calculator to check reserved space against real dimensions.
Open CLS Calculator →

Real-world CLS improvement examples

These are representative before/after results from adding explicit width and height (or aspect-ratio) to every image on a page:

Blog article page
12 inline images, no dimensions
0.34 → 0.06
CLS dropped from "poor" to "good" after adding width/height to every tag.
Product listing grid
Lazy-loaded thumbnails
0.41 → 0.08
Fixed by sizing skeleton placeholders to match final image ratio.
News homepage
Hero + 8 card thumbnails
0.29 → 0.04
Explicit dimensions plus aspect-ratio on the hero background image.
CSS-only fix attempt
Width set, height omitted
0.34 → 0.31
Minimal improvement — confirms both dimensions are required together.

The pattern holds across page types: the shift almost entirely disappears once every image — including lazy-loaded and responsive variants — has a declared ratio the browser can act on before the file arrives.

Comparison: which fix method should you use?

There's more than one way to supply an image's ratio to the browser. Here's how the main options compare:

Method Browser support Responsive-friendly Effort Best for
HTML width/height attributes Universal Yes, with CSS Low Every standard content image
CSS aspect-ratio Modern browsers Yes Low Background images, generated thumbnails
Padding-top hack Universal Yes Medium Legacy support without aspect-ratio
Sized skeleton placeholder Universal Yes Medium Lazy-loaded and JS-inserted images
CSS width only, no height Unreliable Partial Low Not recommended — leaves shift unresolved

Free tools: Aspect Ratio & CLS Calculator, Image Dimension Checker

Both Rebrixe tools run entirely in your browser. Nothing is uploaded to a server — ratios and dimensions are calculated locally, so you can check images and confirm your CLS math before you touch production code.

Stop the jump. Fix CLS in minutes.

Check your image dimensions, calculate the right aspect ratio, and reserve the correct space before a single pixel loads.

Frequently asked questions

Without a width and height (or an aspect-ratio), the browser has no way to know how much space an image will take up before it finishes downloading. It renders the layout at zero height for that image, then suddenly resizes once the file arrives, shoving everything below it down the page. Lighthouse flags this because it's a direct, measurable cause of Cumulative Layout Shift.
Yes, in practice every content image should declare its intrinsic width and height (or use CSS aspect-ratio), including images inside carousels, cards, and lazy-loaded galleries. The only images that can skip this are ones already fully constrained by a fixed-size parent container with no possibility of reflow.
No. The width and height attributes only set the image's intrinsic aspect ratio for the browser's layout calculations. Responsive sizing still comes from CSS, typically "width: 100%; height: auto;" on the image, which scales it while preserving that ratio.
HTML width and height attributes work in every browser, including very old ones, and are the most reliable baseline fix. CSS aspect-ratio is a newer property that achieves the same space-reservation effect and is useful for elements without a natural width/height, like background images or generated thumbnails, but it needs a modern browser to take effect.
Reserve the space before the image loads by setting width and height attributes (or an aspect-ratio container) at the moment the placeholder is inserted into the DOM, not after the real image arrives. A skeleton or placeholder box sized to the final image's aspect ratio prevents any shift once the actual image swaps in.
On image-heavy pages, missing width and height on images is frequently the single largest contributor to a poor CLS score. Adding explicit dimensions to every image commonly brings CLS from a "poor" rating (above 0.25) down into the "good" range (under 0.1) without any other changes.
Yes. Cumulative Layout Shift is one of the three Core Web Vitals metrics search engines use as a page experience signal, alongside loading speed (LCP) and interactivity (INP). Pages with poor CLS scores can be at a disadvantage compared to visually stable pages with otherwise similar content.
← Back to blogs