How to fix: image elements do not have explicit width and height
Add the real width and height (in pixels) to each image tag, and keep your CSS set to height: auto, so the browser reserves the right space before the picture loads. This stops the page jumping and improves your Core Web Vitals score.
When a web page loads, the browser has to decide how much space to leave for each image. If the image tag does not include a width and a height, the browser cannot know until the picture has downloaded, so everything below it gets pushed down at that moment. That jump is what the warning *Image elements do not have explicit width and height* is about, and it is usually quick to fix.
What people see
Visitors notice the page shifting while it loads. They start reading a paragraph, an image appears above it, and the text drops down the screen. On a phone, someone about to tap a button may hit a different link instead because the layout moved at the wrong moment.
You may never see it yourself. On a fast connection, or when images are already cached in your browser, the shift is over in a blink. Testing tools, and visitors on slower mobile connections, see it much more clearly.
Why it matters
The layout jump is measured as Cumulative Layout Shift (CLS), one of Google's Core Web Vitals. A poor CLS score can count against your pages in search, and more importantly it makes a site feel careless. If you want the wider picture of layout jumping, see high CLS.
There is a sales angle too. Shifting pages cause misclicks on buttons, mis-tapped menu items and abandoned forms. A shop whose Add to cart button moves just as someone taps it loses trust quickly.
The fix is cheap compared to most speed work. It does not make images download faster, but it makes the page feel stable, which is what visitors judge.
How to check your site for free
Pick your home page and one or two key pages, such as a product page or a contact page.
- Open PageSpeed Insights (pagespeed.web.dev) and test the page. Look in the Diagnostics section for *Image elements do not have explicit width and height*. It lists the exact images.
- Or run Lighthouse in Chrome: right-click the page, choose Inspect, open the Lighthouse tab and run a report. The same audit appears there.
- For a quick manual check, right-click an image, choose Inspect, and look at the highlighted
<img>tag. If you cannot seewidth=andheight=in it, the attributes are missing. - In Chrome DevTools, the Performance panel can also show layout shifts, with a marker for each one.
A small number of images flagged is common. A long list usually means a theme, page builder block or custom template is leaving the attributes out everywhere.
Week 4 of SiteMonday covers speed and Core Web Vitals, so this check is part of that week's report and ranked fix list. The free tools above work just as well for a one-off look.
How to fix it in general
The fix has two parts: give every image its real pixel dimensions, and let CSS keep it responsive.
Here is a correct image tag:
<img src="/images/team.jpg" alt="Our team in the shop" width="1200" height="800">
And the CSS that keeps it flexible on small screens, which most themes already include:
img { max-width: 100%; height: auto; }
A few details that trip people up:
- Use plain numbers with no
px. The attributes are in pixels. - The numbers do not have to match the size shown on screen. What matters most is the ratio. A 1200 by 800 file displayed at 600 wide still leaves the right amount of room, because the browser uses the ratio.
- Do not remove
height: autofrom your CSS. Without it, a fixed height attribute can stretch your images on mobile. - Images set as CSS backgrounds are not
<img>tags. Give their container a fixed size or anaspect-ratiorule instead. - If you use responsive images (
srcset), put the dimensions of the default file inwidthandheight. All versions should share the same ratio. - Do not put
loading="lazy"on your main hero image. That is a separate problem, covered in lazy-loaded LCP image.
Fixing it on common platforms
Menus differ between versions and themes, but the usual pattern is this.
- WordPress: Images inserted through the editor normally get width and height automatically. Missing ones usually come from the theme, a page builder, or images pasted in as raw HTML. Check the theme template and re-insert the affected images from the Media Library. There is a full guide at WordPress image dimensions.
- Shopify: Most modern themes use the
image_tagfilter, which adds dimensions. Older or customised themes may have hand-written<img>tags in the Liquid files. A developer can change those. Shopify specifics are in the Shopify guide. - Wix, Squarespace, Webflow: These builders handle most of it for you. Problems usually come from custom code embeds, or from an image set to fill a container with no defined size. Look for images added through embed or code blocks first.
- Elementor and other page builders: Check the image widget's size setting and any custom HTML widgets. Images in custom HTML need the attributes added by hand.
- Next.js: The
Imagecomponent requires width and height (orfillwith a sized parent), so the problem usually lives in plain<img>tags. - Hand-built or custom sites: Edit the HTML directly, or have your developer add the attributes in the template that outputs images.
If you are not comfortable editing theme files, this is a small, well-defined job to hand to a developer.
How to confirm the fix worked
- Clear any caching plugin or CDN cache, so you are not testing the old page.
- Run PageSpeed Insights again on the same page. The audit should disappear from Diagnostics.
- Check the CLS figure in the lab results. It should drop, though other causes such as late-loading ads, banners or fonts can keep it above zero.
- Reload the page in a private window with the network throttled (DevTools, Network tab, choose Slow 4G) and watch for jumping.
The real-user data in PageSpeed Insights comes from a rolling 28 day window, so that figure improves gradually and not overnight. Do not worry if it lags behind the lab result.
How to stop it coming back
- Ask whoever builds new pages to insert images through the normal editor or component, not pasted HTML.
- When a theme or plugin is updated or replaced, re-test your top pages.
- Keep
height: autoin your base CSS, and addaspect-ratioto containers that hold background images or embeds. - Add a quick check to your routine whenever you launch a landing page or a new product template.
- Re-test regularly. A recurring review such as week 4 catches it if a redesign or plugin quietly brings the problem back.
If CLS is still high after the images are fixed, look next at fonts swapping in late and at third-party widgets, which are the other usual causes.
Step by step for your platform
- Images without width and height attributes on WordPress
- Images without width and height attributes on Shopify
- Images without width and height attributes on Wix
- Images without width and height attributes on Squarespace
- Images without width and height attributes on Webflow
- Images without width and height attributes on Next.js
- Images without width and height attributes on Elementor
Questions
Do I need to set width and height on every image?
Yes, on every image tag that shows content, including logos, product photos and blog images. Decorative images set through CSS backgrounds are the exception, but their containers still need a defined size.
Will adding width and height make my images look stretched?
Not if your CSS includes `height: auto` and the numbers match the image's true ratio. Most themes already include `max-width: 100%; height: auto`, which keeps images responsive.
Do the attribute values have to match the displayed size?
No. The browser uses them mainly to work out the aspect ratio, so a 1200 by 800 image shown at 600 pixels wide still reserves the correct space.
Does this make my images load faster?
No, the file still takes the same time to download. It stops the layout from jumping, which improves your CLS score and how stable the page feels.
Why does my page builder or theme leave the attributes out?
Some themes, older templates and custom HTML blocks write image tags by hand without them. Updating the theme, re-inserting images through the editor or editing the template usually solves it.
How long until Google shows the improvement?
Lab tests such as PageSpeed Insights update immediately after you re-run them. Real-user data covers a rolling 28 day period, so expect it to improve gradually.