Skip to content
FunnelGuard

Fix guide by FunnelsGuard

Images missing width and height: fix layout shift and slow LCP

PRF-024Medium impactCould addBy FunnelGuardPublished Updated
On this page

What this issue is

Every <img> tag can carry width and height attributes. They tell the browser the image's shape before the file has downloaded. Without them, the browser treats the image as 0 pixels tall, lays out the text, then pushes everything down when the file arrives.

Modern browsers use the two attributes to work out an aspect ratio (width divided by height) and reserve the right amount of space straight away. This works even when CSS scales the image to fit the screen.

Largest Contentful Paint (LCP) is the time until the biggest visible element, often a hero image, is drawn. Missing dimensions mostly hurt a different metric, Cumulative Layout Shift (CLS), but they also make the page do extra layout work and can make the hero render later than it should, particularly when the image sits inside a container that has no fixed height.

Why it costs you leads or sales

A page that jumps while loading feels unstable. A visitor about to tap a button or a form field may hit something else when the layout shifts. A hero that appears late makes a paid landing page look slow, and visitors from ads leave quickly.

How a missing image size hurts a landing page
  1. Page starts loadingHTML arrives, image size unknown
  2. Text and form drawnNo space reserved for the hero
  3. Image arrivesLayout reflows, content jumps
  4. Visitor taps buttonLands on the wrong element
  5. Lead form submittedVisitor gives up before this

The break happens when the image arrives and pushes the page down.

Layout shift score before and after adding dimensionsExample numbers
Layout shift score before and after adding dimensions (example)No width/height: 0.3 CLS score; With width/height: 0 CLS score0010.30No width/heightWith width/heightCLS score

Example: illustrative CLS scores for one landing page. Google treats 0.1 or below as good.

How to check if your site has it

Find images without dimensions
  1. Run Lighthouse

    In Chrome, open DevTools, go to the Lighthouse tab and run a mobile report. Look for 'Image elements do not have explicit width and height' and for the CLS score.

  2. Use PageSpeed Insights

    Test your landing page URL at pagespeed.web.dev. Check the 'Avoid large layout shifts' list to see which elements moved.

  3. Record a Performance trace

    In DevTools, open Performance, tick Screenshots, reload the page and look at the Layout Shifts track. Click a shift to see which image caused it.

  4. Scan the HTML

    View source and search for <img. Any tag without both width= and height= is a candidate. Run this in the console to list them.

List images with no width or height attribute (paste in the DevTools console)javascript
[...document.images]
  .filter(i => !i.getAttribute('width') || !i.getAttribute('height'))
  .forEach(i => console.log(i.currentSrc || i.src, i));

How to fix it

Set width and height to the image's real pixel size (its intrinsic size), not the size it is shown at. Then let CSS make it fluid. The browser will use the ratio to reserve space at any screen width.

Image with dimensionshtml
<img src="/img/hero.webp" width="1200" height="675" alt="Product on a desk">
Keep images responsivecss
img {
  max-width: 100%;
  height: auto;
}
Fix by platform
  1. Use the media library

    Images inserted through the block editor or wp_get_attachment_image() get width and height automatically. Re-insert images that were pasted in as raw HTML.

  2. Fix theme templates

    In theme files, replace hard-coded <img> tags with wp_get_attachment_image( $id, 'full' ) or add the attributes by hand.

  3. Check page builders and plugins

    Some builders and optimisation plugins strip or rewrite attributes. Test with the plugin off to find the cause.

Image markup

Before

  • <img src="hero.webp">
  • Space is reserved only after download
  • Text and buttons jump down

After

  • <img src="hero.webp" width="1200" height="675">
  • Space is reserved straight away
  • Layout stays still while the image loads

How to confirm it's fixed

Checks after the change
  • The console snippet above lists no images on the page
  • Lighthouse no longer reports missing width and height
  • The Layout Shifts track in DevTools shows no shift from images
  • CLS is 0.1 or below on mobile
  • The page does not jump when you reload with the cache disabled and network throttled to Slow 4G

How to prevent it happening again

Habits that keep it fixed
  • Add width and height to image components in your theme or design system once, so every new image gets them
  • Run a Lighthouse or PageSpeed check on each new landing page before it goes live
  • Re-test after installing optimisation plugins or changing themes
  • Tell editors to upload images through the media library, not paste raw HTML
  • Review third-party widgets and banners that inject images

How FunnelGuard handles this

FunnelGuard does not check for missing image dimensions or layout shift today. It is a possible future check.

What FunnelGuard does do is run your real customer journeys on a schedule, such as lead forms and checkouts, and check each step, the tracking hits and whether test leads arrive. If a layout problem breaks a journey, for example a button that cannot be reached, a failed step can show up that way, with a screenshot. It will not tell you the cause is a missing image size.

To watch for this issue yourself, re-run PageSpeed Insights or Lighthouse on your key landing pages after each release, and check the Core Web Vitals report in Google Search Console, which groups URLs by CLS and LCP. You can also try the free plan (1 site, 2 journeys, daily checks, no card) for journey monitoring.

Questions people ask

Why do my images make the page jump while it loads?

The browser does not know how big an image is until it downloads, so it reserves no space. When the file arrives, the content below is pushed down. Adding width and height attributes lets the browser reserve the right space in advance.

Do I need width and height on every image?

Yes, on every <img> where you can. They matter most for images at the top of the page, but they cost nothing on others and prevent layout shift everywhere.

Do width and height attributes stop images being responsive?

No. Add img { max-width: 100%; height: auto; } in CSS and the image scales with its container. The browser uses the attributes only to calculate the aspect ratio and reserve space.

Do missing image dimensions slow down LCP?

They mainly cause layout shift, but they can also delay when the hero is painted, especially when its container has no fixed height. Fixing them is a low-effort step alongside compressing and prioritising the hero image.

What size should I put in width and height?

Use the intrinsic pixel size of the image file, for example 1200 and 675 for a 1200 by 675 image. The displayed size can differ because CSS scales it, as long as the ratio stays the same.

How do I find images without width and height?

Run Lighthouse in Chrome DevTools and look for the 'Image elements do not have explicit width and height' warning. You can also paste a short script in the console that lists images missing either attribute.

Can I use CSS aspect-ratio instead of width and height?

Yes. Setting aspect-ratio: 16 / 9; on the image or its wrapper reserves the space too. HTML attributes are still the simplest option because they work before any CSS loads.

Does FunnelGuard check for missing image dimensions?

Not yet. It is a possible future check. FunnelGuard currently monitors journeys, tracking hits and lead delivery, so use PageSpeed Insights or Search Console for this one.

Does FunnelGuard catch this?

Could add

Not checked yet: could be added to FunnelGuard.

Stop finding out from your customers

FunnelGuard runs your real forms and checkouts on a schedule, checks the tracking and the leads behind them, and alerts you once, with a screenshot. Try any paid plan free for 3 days.