Skip to main content

HTML Guide

Bad value X for attribute “srcset” on element “img”: Expected width descriptor but found Y at Z. (When the “sizes” attribute is present, all image candidate strings must specify a width.)

All values in the srcset attribute must include a width descriptor (such as 300w) when the sizes attribute is present.

The srcset attribute is used to provide multiple image sources for responsive images. Each image candidate string in srcset must specify the image’s width (e.g., 600w) or pixel density (e.g., 2x). When you use a sizes attribute, all srcset candidates must use width descriptors (w).

Example of incorrect usage:

<img
  src="/img/pic1.jpg"
  srcset="/img/pic1.jpg"
  sizes="(max-width: 600px) 100vw, 600px"
  alt=""
>

This example is invalid because the srcset value does not include a width descriptor.

Corrected usage with width descriptors:

<img
  src="/img/pic1.jpg"
  srcset="/img/pic1.jpg 600w"
  sizes="(max-width: 600px) 100vw, 600px"
  alt=""
>

If you have multiple image sizes, include each with its corresponding width:

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

Always match each image URL in srcset with a width (w) or pixel density (x) descriptor if appropriate for your layout.

Learn more:

Related W3C validator issues