How to Fix Missing Image Width and Height Attributes
When an <img> tag has no width and height attributes, the browser doesn't know how much space to reserve, so text and buttons jump down when the image finally loads. This guide shows you how to find the images missing dimensions, add the correct values, keep them responsive with CSS, and confirm the layout shift is gone.
Why it matters
Layout shift is measured by Cumulative Layout Shift (CLS), one of Google's Core Web Vitals. A CLS above 0.1 counts as "needs improvement" in Search Console's page experience reports. Shifting content also causes misclicks, especially on mobile, where a late-loading image can push an "Add to cart" or "Buy" button out from under someone's thumb. Explicit dimensions let the browser compute the aspect ratio up front. It is one of the cheapest CLS fixes available.
What you need
Step-by-step fix
List the images missing dimensions
Open an affected page from the audit, then open DevTools (F12) and go to the Console tab. Run the snippet below to list every <img> that lacks a width or height attribute. Note whether each one comes from a theme template, a content block, or a plugin or app. Template images fix many pages at once, so start with those.
[...document.querySelectorAll('img')].filter(i => !i.getAttribute('width') || !i.getAttribute('height')).forEach(i => console.log(i.currentSrc || i.src, i.naturalWidth + 'x' + i.naturalHeight));Platform-specific notes
WordPress
Images inserted with the Image block get width and height automatically, and WordPress 5.5+ adds them to content images on output. Missing dimensions usually come from theme template files (header.php, logo markup, custom blocks), page builders, or SVG logos. In Elementor, the Image widget outputs dimensions only for Media Library images, not for custom URLs. For theme code, use wp_get_attachment_image() instead of a hand-written <img>, because it prints width, height and srcset.
Shopify
In Online Store > Themes > Edit code, find Liquid img tags built with img_url or a hard-coded src. Replace them with the image_tag filter, for example {{ product.featured_image | image_url: width: 800 | image_tag: loading: 'lazy' }}. It outputs width and height from the image object automatically. Images from apps are controlled by the app, so contact its developer if they lack dimensions.
Next.js
next/image requires width and height for remote and string src values. Imported static images get them automatically. If you use the fill prop, the parent element must have position: relative and a defined size or aspect-ratio, or it will still shift. Add priority (or fetchPriority="high" in Next.js 15+) to the hero image.
Webflow
Webflow's Image element doesn't always write width and height attributes. Select the image, open Settings (gear icon) and add custom attributes width and height. Alternatively, set an aspect-ratio on the image or its wrapper in the Style panel. CMS-bound images need a fixed aspect ratio class, because dimensions vary per item.
Wix
Wix renders images through its own components and generally reserves space for them. Flagged images usually come from Embed HTML / Custom Code elements. Add width and height directly in that embed code.
Check that it worked
โ How to verify
- Re-run the Console snippet from step 1 on each fixed page and confirm it prints nothing.
- Run Lighthouse in Chrome DevTools (Lighthouse tab > Analyze page load) and confirm the 'Image elements do not have explicit width and height' diagnostic is gone and CLS is under 0.1.
- In PageSpeed Insights, open the Layout Shift Culprits section of the Performance trace and confirm no image appears as a shift source.
- Re-run your site audit and confirm the affected URL count for this check drops to zero.
โ ๏ธ Common mistakes
- Adding width and height but leaving CSS like height: 300px or no height: auto, which stretches or squashes the image.
- Using display size values (e.g. width="100%") instead of plain integer pixel values; the attributes accept only whole numbers.
- Lazy-loading the hero image, which delays Largest Contentful Paint. Use fetchpriority="high" on it instead.
- Using dimensions with a different aspect ratio than the real file, so space is reserved incorrectly and the content still shifts.
Is this still an issue on your site? Run a free audit โ ZORO checks this and 294 other SEO, AI-visibility, accessibility and security signals, with fixes for your platform.
Check my site freeFAQ
Do width and height attributes stop images from being responsive?
No. With img { max-width: 100%; height: auto; } in your CSS, the image scales to its container. Browsers use the attributes only to calculate the aspect ratio and reserve space.
What values should I use for width and height?
Use the image file's intrinsic pixel dimensions, or any pair with the same aspect ratio. With srcset, use the dimensions of the default src file. All candidates in the srcset should share that ratio.
Does CSS aspect-ratio replace width and height attributes?
It also prevents layout shift, but the attributes are the standard, most robust method, and audits and Lighthouse check for them. CSS aspect-ratio is mainly for CSS background images, iframes and fill-style containers.
Do SVG images and lazy-loaded images need width and height?
Yes. An <img> pointing to an SVG still needs dimensions for the browser to reserve space. Lazy-loaded images benefit most, because they load late, often after the user has started scrolling.