# 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.

> Canonical HTML version: https://rocketvalidator.com/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
> Attribution: Rocket Validator (https://rocketvalidator.com)
> License: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/)

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

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

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

```html
<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)`.
