Sitewalk / Guides / Images and page weight / Image width and height
Image width and height: stop the page from jumping
When an image tag has no width and height, the browser does not know how much room to keep for the picture. It lays out the text, then pushes everything down when the file arrives. That jump is a layout shift, and web.dev lists images without dimensions as a main cause of it.
The fix is two attributes per image. This guide shows how to find the images that lack them, how to pick the right numbers, and how to keep images responsive on phones.

What happens when the size is missing
Picture a page with a heading, an image and a paragraph. The browser reads the HTML top to bottom. If the image tag gives no size, the browser reserves nothing for it and places the paragraph right under the heading. When the image file finishes downloading, the browser learns its size and moves the paragraph down.
Anyone who started reading the paragraph loses their place. Anyone about to tap a button below the image may tap the wrong thing. web.dev describes the same harm: people lose their place in the text, or click the wrong link or button.
Google's web.dev guide explains how this became common. Early web pages put width and height on images. When responsive design arrived, developers dropped them and resized with CSS instead. Without those attributes the browser cannot reserve space until it has downloaded enough of the image to know its size.
How the browser uses the two numbers
web.dev says modern browsers use the width and height attributes to set a default aspect ratio for the image before it loads. MDN says the same: the browser can calculate the ratio before the image is downloaded and uses it to reserve space, which reduces or prevents the shift.
Note what the numbers are. They are the intrinsic size of the file in pixels, as plain integers with no unit. They do not fix how large the image appears on screen. Next.js says this in its docs for the same two properties: they infer the aspect ratio, and the rendered size is controlled by CSS.
So a 1600 by 900 photo shown 320 pixels wide on a phone still gets width="1600" height="900". The browser works out that the ratio is 16 to 9 and reserves a 320 by 180 box.
Why Sitewalk flags it
Sitewalk reports a page when an image tag has no width and height. The score that measures the damage is Cumulative Layout Shift. web.dev says a good CLS is 0.1 or less, measured at the 75th percentile of page loads, and that anything above 0.25 is poor.
Images are not the only cause. web.dev also names ads, embeds and iframes without dimensions, content injected late, and web fonts that swap in at a different size. Fixing images clears one common cause and leaves the others for you to check.
How to find images with no width and height
For one page, view the source and look at each <img tag. Both attributes should be there.
This script checks any page. It uses only Python's standard library. It counts the images and lists each one that lacks a width, a height or both.
import sys, urllib.request
from html.parser import HTMLParser
class P(HTMLParser):
def __init__(s):
super().__init__(); s.n = 0; s.bad = []
def handle_starttag(s, tag, attrs):
if tag == "img":
s.n += 1; d = dict(attrs)
lacks = [a for a in ("width", "height") if not d.get(a)]
if lacks: s.bad.append((d.get("src", "?"), " and ".join(lacks)))
p = P()
p.feed(urllib.request.urlopen(sys.argv[1]).read().decode("utf8", "replace"))
print(p.n, "images,", len(p.bad), "missing width or height")
for src, what in p.bad: print(" no", what + ":", src)
Save it as check_dims.py and run python3 check_dims.py https://example.com/. We tested it on a page with four images: one with neither attribute, one with only a width, one with both and one with only a height. It printed 4 images, 3 missing width or height and named the three.
We also ran it on sitewalkseo.com on 23 Nov 2026. The home page has 0 <img> tags, so there was nothing to report.
If you get 0 images for a page with pictures, a script probably adds them after load. This script cannot see those, and neither can a crawler that reads only the HTML. See pages that need JavaScript to show content.
PageSpeed Insights can also point you to the images. web.dev says Lighthouse has audits that name images causing layout shift because they lack width and height, and a list of the elements that shifted with their contribution to the score.
How to get the real size of an image
You need the pixel size of the file you are linking to. Do not guess.
On a Mac, this prints both numbers:
sips -g pixelWidth -g pixelHeight photo.png
We ran it on a 640 by 360 test file and it printed pixelWidth: 640 and pixelHeight: 360. The file command also shows the size for PNG and JPEG files on Mac and Linux. It printed PNG image data, 640 x 360 for the same file.
Your image editor shows the same numbers. Use the size of the file the tag actually points to, not of the original you uploaded.
How to fix it

Text version
Without a size, text sits high while the image loads and jumps down when it arrives. With width and height set, the space is reserved and nothing moves. Example: img width=1600 height=900, with height auto in CSS.
Put both numbers in the tag, then add one rule of CSS so the image still scales down.
<img src="puppy.jpg" width="640" height="360" alt="Puppy with balloons">
img {
max-width: 100%;
height: auto;
}
web.dev recommends this combination. The attributes give the browser the ratio at the start. height: auto lets the height follow the width when CSS sets the width, and web.dev's own example sets width: 100% for an image in a container.
If you cannot edit the HTML, web.dev says you can reserve the space with the CSS aspect-ratio property instead. Its guide also notes that the browser sets a default aspect-ratio from the attributes, written as auto 640 / 360, and the auto part lets the image's real dimensions take over after it downloads.
| Situation | What to do |
|---|---|
| You write the HTML yourself | Add width and height to every <img> and keep height: auto in your CSS |
You use a responsive srcset | Use one aspect ratio for all sizes, and set the attributes to the intrinsic size of the largest file |
Different crops for phone and desktop with <picture> | Set width and height on each <source> as well as the <img> |
| You cannot add attributes | Reserve the space with the CSS aspect-ratio property on the image |
web.dev's example for responsive images keeps the same ratio across sizes: a 1000 by 1000 width and height with a srcset of three square files. For art direction with <picture>, its example gives the phone crop width="480" height="400" and the desktop crop width="800" height="400", and says Chrome, Firefox and Safari support these attributes on <source>.
How to fix it on common platforms
WordPress. WordPress core has a function, wp_img_tag_add_width_and_height_attr(), that adds width and height to an img tag. Its documentation describes the function and its parameters, and I did not read when core runs it, so check your output instead of assuming. The usual gaps are images printed by hand in a theme template or inserted by a page builder. Use the script above on your own pages.
Next.js. The Image component needs both width and height. The docs say you must set both unless the image is statically imported or uses the fill prop. When the size is unknown, the docs recommend fill. If you set a custom width with the style prop, also set height: 'auto' to keep the ratio.
Plain HTML and static sites. Write the attributes in the tag. A small build script that reads the file size and writes the tag is worth writing on a site with hundreds of images.
Embeds and iframes. web.dev lists these as a separate cause of layout shift. Give them dimensions or reserve their space too.
Common mistakes
- Adding
width="100%". MDN says the value must be an integer with no unit, so write pixels. - Setting numbers that do not match the real ratio. web.dev says the browser still reserves a box, and if the real ratio differs there is still some shift after the image loads, though less than with no size at all.
- Setting
height: 400pxin CSS next tomax-width: 100%. The image squashes on narrow screens. Useheight: auto. - Fixing images and ignoring ad slots, embeds and iframes, which need reserved space too.
- Using one
srcsetwith files of different ratios and a single pair of numbers.
If an image also has no description, see images without alt text, which sits in the same tag. While you are in the templates, two other fixes live there too: duplicate titles and title and meta description length.
Check it worked
- Run the script again and confirm
0 missing width or heightfor the pages you fixed. - Reload the page on a throttled connection in your browser's developer tools and watch the first screen. Text should stay put as images arrive.
- Test the page in PageSpeed Insights and read the Cumulative Layout Shift value in the lab results.
- Check a phone width and confirm images still shrink and do not overflow.
- Run a new Sitewalk audit.
What Sitewalk found on real sites
Counted on 23 Nov 2026, from the latest audit of each site.
Of 119 audited sites, on the latest audit of each, 51 (43%) had at least one page with images missing width and height. That counts sites with at least one page, not images. This is a small early-user group, a first look and not a survey.
Questions people ask
Do I need width and height on every image?
Yes, for images that load in the page. web.dev says to always include width and height on images and video, or reserve the space with CSS aspect-ratio.
Will width and height make my images a fixed size?
No. They give the browser the intrinsic size so it can work out the aspect ratio. With max-width: 100% and height: auto in your CSS, the image still scales to its container.
Does a missing image size hurt SEO?
It can hurt your Cumulative Layout Shift score, which web.dev describes as a measure of layout stability. I did not find a Google statement in these sources that ties missing dimensions directly to rankings, so we make no ranking claim.
What is a good CLS score?
web.dev says 0.1 or less is good and above 0.25 is poor, measured at the 75th percentile of page loads.
Should I use width and height attributes or CSS aspect-ratio?
Use the attributes when you can edit the tag, because web.dev says the browser calculates the ratio from them at the very start of layout. Use CSS aspect-ratio when you cannot edit the tag, or for containers that hold embeds.
What about images in a srcset?
Give every file the same aspect ratio and set width and height to the intrinsic size of the largest one. If crops differ by screen, use <picture> and set the attributes on each <source>.
Check your whole site in one sentence
Sitewalk looks at every image on every page it crawls, along with 200+ other technical checks. In ChatGPT, say:
Audit example.com for technical SEO problems
Checked on 23 Nov 2026. Sources read on 23 Nov 2026: web.dev, "Cumulative Layout Shift (CLS)" and "Optimize Cumulative Layout Shift"; MDN Web Docs, "The Image Embed element"; Next.js, "Image component" docs; WordPress Developer Resources, "wp_img_tag_add_width_and_height_attr()". Sitewalk counts are from 119 audited sites, each site's latest audit: a small early-user group, a first look and not a survey.