About This HTML Issue
sizes contains an invalid media condition; the value must be a comma-separated list of media conditions with corresponding slot sizes, ending with an optional fallback length.
Detailed explanation:
-
The
sizesattribute onimgpairs a media condition with a slot size that represents the layout width of the image for that condition. Syntax:(<media-condition>) <length>[, ...], <length>where the last item can be a bare length fallback. -
A media condition uses the same grammar as CSS media queries. It must be valid CSS, e.g.,
(min-width: 600px)or(width <= 50rem) and (orientation: landscape). Each condition must be enclosed in parentheses unless using logical operators combining proper conditions.
Common parse errors:
-
Missing parentheses: use
(min-width: 600px), notmin-width: 600px. -
Invalid units or tokens: use
px,em,rem,vw, etc.; avoid%in media conditions. -
Missing slot size after a condition:
(min-width: 600px)must be followed by a length like600px. -
Using
pxonly for slot size without units or using percentages: slot size must be a length like300px,50vw, not300. - Trailing comma or extra commas.
-
Misusing comparison syntax: use modern range syntax like
(600px <= width <= 1000px)or the traditional form(min-width: 600px) and (max-width: 1000px). Do not write(min-width <= 600px). -
Slot sizes must be lengths:
px,em,rem,vw,vh,vmin,vmax,ch. Percentages are not allowed insizesslot sizes. -
The
srcsetwidths (wdescriptors) must correspond to the intrinsic widths of the image candidates, e.g.,400w,800w. The browser picks one based onsizes.
HTML examples:
-
Correct usage with media conditions and fallback:
<img src="image-800.jpg" srcset="image-400.jpg 400w, image-800.jpg 800w, image-1200.jpg 1200w" sizes="(min-width: 900px) 50vw, (min-width: 600px) 66vw, 100vw" alt="Decorative pattern"> -
Using range syntax and avoiding common mistakes:
<img src="hero-1600.jpg" srcset="hero-800.jpg 800w, hero-1200.jpg 1200w, hero-1600.jpg 1600w" sizes="(800px <= width < 1200px) 80vw, (width >= 1200px) 50vw, 100vw" alt="Hero banner"> -
Minimal fixed example for a typical error (missing parentheses and slot size): Incorrect:
<img src="pic-800.jpg" srcset="pic-400.jpg 400w, pic-800.jpg 800w" sizes="min-width: 600px, 100vw" alt="Sample">Correct:
<img src="pic-800.jpg" srcset="pic-400.jpg 400w, pic-800.jpg 800w" sizes="(min-width: 600px) 50vw, 100vw" alt="Sample"> -
Example avoiding invalid tokens and commas:
<img src="avatar-256.png" srcset="avatar-128.png 128w, avatar-256.png 256w" sizes="(orientation: landscape) 30vw, 50vw" alt="User avatar">
Last reviewed: August 08, 2025
Find issues like this automatically
Rocket Validator scans thousands of pages in seconds, detecting HTML issues across your entire site.