Skip to main content
HTML Validation

Bad value for attribute “sizes” on element “img”: Expected units (one of “em”, “ex”, “ch”, “rem”, “cap”, “ic”, “vw”, “svw”, “lvw”, “dvw”, “vh”, “svh”, “lvh”, “dvh”, “vi”, “svi”, “lvi”, “dvi”, “vb”, “svb”, “lvb”, “dvb”, “vmin”, “svmin”, “lvmin”, “dvmin”, “vmax”, “svmax”, “lvmax”, “dvmax”, “cm”, “mm”, “q”, “in”, “pc”, “pt”, “px”) but found no units at X.

About This HTML Issue

The sizes attribute on an img element contains a value that is missing a CSS unit (such as px, vw, or em).

The sizes attribute tells the browser how wide an image will be displayed at a given viewport condition. Each entry in the sizes list must be a valid CSS length. A bare number like 300 is not a valid CSS length — it must include a unit, such as 300px or 50vw.

A common mistake is writing something like sizes="(max-width: 600px) 300, 600" instead of sizes="(max-width: 600px) 300px, 600px". Another frequent error is omitting the unit on the default (last) value.

The sizes attribute accepts a comma-separated list of source size entries. Each entry except the last consists of a media condition followed by a length. The last entry is just a length and acts as the default. Every length value must have a CSS unit.

Invalid example

<img
  src="photo.jpg"
  srcset="photo-300.jpg 300w, photo-600.jpg 600w"
  sizes="(max-width: 600px) 300, 600"
  alt="A photo">

Both 300 and 600 lack units, so the validator rejects them.

Valid example

<img
  src="photo.jpg"
  srcset="photo-300.jpg 300w, photo-600.jpg 600w"
  sizes="(max-width: 600px) 300px, 600px"
  alt="A photo">

You can also use viewport-relative units like vw:

<img
  src="photo.jpg"
  srcset="photo-300.jpg 300w, photo-600.jpg 600w"
  sizes="(max-width: 600px) 100vw, 50vw"
  alt="A photo">

Check every length in your sizes attribute and make sure each one ends with a valid CSS unit. The calc() function is also allowed, for example calc(100vw - 2rem).

Find issues like this automatically

Rocket Validator scans thousands of pages in seconds, detecting HTML issues across your entire site.

Help us improve our guides

Was this guide helpful?
🌍 Trusted by teams worldwide

Validate at scale.
Ship accessible websites, faster.

Automated HTML & accessibility validation for large sites. Check thousands of pages against WCAG guidelines and W3C standards in minutes, not days.

Scheduled Reports
API Access
Open Source Standards
$7 / 7 days

Pro Trial

Full Pro access. Cancel anytime.

Start Pro Trial →

Join teams across 40+ countries