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

> Canonical HTML version: https://rocketvalidator.com/html-validation/bad-value-x-for-attribute-sizes-on-element-img-expected-media-condition-before-at-y
> Attribution: Rocket Validator (https://rocketvalidator.com)
> License: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/)

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`:

```html
<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:

```html
<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">
```
