About This HTML Issue
The sizes attribute on the img element must use CSS length units (such as px, vw, em) and not image width descriptors like w.
The sizes attribute defines the intended display size of the image in CSS length units, which helps the browser select the appropriate image from the srcset. Use units like px (pixels) or vw (viewport width percentage), not w, which is used in the srcset descriptors. The srcset attribute specifies different image resources and their width descriptors (e.g., 860w), while sizes reflects the image’s display size in the layout.
Correct usage:
-
sizes="(min-width: 568px) 140px"tells the browser the image will be displayed as 140 pixels wide when the viewport is at least 568 pixels wide. -
srcset="photo.png?w=860&q=90 860w"useswas the descriptor for the image resource’s width.
HTML example:
<img
alt=""
sizes="(min-width: 568px) 140px"
srcset="photo.png?w=860&q=90 860w"
src="photo.png?w=860&q=90">
Summary:
-
Use CSS units like
px,vw, etc. in thesizesattribute. -
Use the
wdescriptor only insrcset, not insizes.
Last reviewed: May 05, 2025
Find issues like this automatically
Rocket Validator scans thousands of pages in seconds, detecting HTML issues across your entire site.