Skip to main content
HTML Validation

Bad value X for attribute “sizes” on element “img”: Expected media condition before “” at Y.

About This HTML Issue

In a sizes attribute, only the last entry can be a bare length: every entry before it needs a media condition such as (max-width: 600px).

The sizes value is a comma-separated list. Each entry pairs a media condition with the width the image takes up when that condition is true. The browser reads the list from left to right and uses the first entry whose condition matches. A length without a condition matches every viewport, so it only makes sense at the end, as the default.

The validator reports this error when a bare length has more entries after it. Browsers follow the HTML parsing rules and stop at the bare length, so anything that comes after it is never read. In (max-width: 600px) 100vw, 940px, 100vw, the final 100vw does nothing. This often happens when a page builder or template appends its own fallback to a sizes value that already ends with one.

To fix it, pick the width you want as the default, keep it as the last entry, and delete everything after it. If a length in the middle of the list should apply only to some viewport widths, give it a media condition instead.

Invalid example

The 940px entry has no media condition, but it is followed by 100vw:

<img
  src="photo-800.jpg"
  srcset="photo-400.jpg 400w, photo-800.jpg 800w, photo-1200.jpg 1200w"
  sizes="(max-width: 600px) 100vw, (max-width: 1000px) 720px, 940px, 100vw"
  alt="A team meeting around a table">

Valid example

With the trailing 100vw removed, 940px is the default. Browsers were already using 940px there, so the image loads the same way as before:

<img
  src="photo-800.jpg"
  srcset="photo-400.jpg 400w, photo-800.jpg 800w, photo-1200.jpg 1200w"
  sizes="(max-width: 600px) 100vw, (max-width: 1000px) 720px, 940px"
  alt="A team meeting around a table">

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
€5 / week

1K Weekly

1,000 monthly checks. Cancel anytime.

Get 1K Weekly →

Join teams across 40+ countries