Skip to main content

HTML Guide

Bad value X for attribute “srcset” on element “img”: No width specified for image Y. (When the “sizes” attribute is present, all image candidate strings must specify a width.)

The srcset attribute requires a width descriptor (w) or pixel density descriptor (x) for each image candidate when the sizes attribute is present.

When using the sizes attribute on an img element, each entry in srcset must include either a width descriptor (e.g., 860w) or a pixel density descriptor (e.g., 2x). This tells browsers how to select the most appropriate image source for the current viewport or display density. Omitting the descriptor leads to HTML validation errors and unexpected image selection.

Correct usage with width descriptors:

<img
  alt=""
  sizes="(min-width:568px) 140px"
  srcset="photo.png?w=860&amp;q=90 860w"
  src="photo.png?w=860&amp;q=90">

Correct usage with pixel density descriptors (if sizes is removed):

<img
  alt=""
  srcset="photo.png?w=860&amp;q=90 2x"
  src="photo.png?w=860&amp;q=90">

Key points:

  • With sizes, use width descriptors (e.g., 860w).
  • Without sizes, you may use pixel density descriptors (e.g., 2x).
  • Always use either px or w units in the sizes attribute values; do not use w.

Learn more:

Related W3C validator issues