About This HTML Issue
Use a valid media length in the sizes attribute; each slot’s length must include a unit (e.g., px, vw) and cannot be unitless.
Detailed explanation
The sizes attribute on responsive images (<img> or <source> within <picture>) specifies, for each media condition, the slot size that the image will occupy in the layout. Each size value must be a valid CSS length with units, or the keyword auto (for <img> only; not useful with <source>). Unitless numbers (e.g., 300) are invalid; use 300px. Percentages are not allowed in sizes. Valid units include: px, em, rem, vw, vh, and the full set listed by the validator (e.g., svw, lvh, cm, etc.).
Common pitfalls:
-
Missing units:
sizes="(min-width: 768px) 600, 100vw"→600must be600px. -
Using
%:sizes="50%"is invalid; use a viewport unit like50vw. - Malformed list: values must be comma-separated media conditions followed by a length, ending with a fallback length.
-
Putting
sizeson<source>is valid, but syntax must match the same rules as on<img>.
Reference keywords:
-
sizes -
srcset -
media(on<source>) - CSS length units
Valid pattern
-
With conditions:
sizes="(media-condition) length, ... , fallback-length" -
Without conditions:
sizes="fallback-length"
HTML examples
Fix missing units
Before (invalid):
<picture>
<source
type="image/webp"
srcset="hero-800.webp 800w, hero-1200.webp 1200w"
sizes="(min-width: 900px) 800, 100vw">
<img
src="hero-800.jpg"
srcset="hero-800.jpg 800w, hero-1200.jpg 1200w"
sizes="(min-width: 900px) 800, 100vw"
alt="Hero image">
</picture>
After (valid):
<picture>
<source
type="image/webp"
srcset="hero-800.webp 800w, hero-1200.webp 1200w"
sizes="(min-width: 900px) 800px, 100vw">
<img
src="hero-800.jpg"
srcset="hero-800.jpg 800w, hero-1200.jpg 1200w"
sizes="(min-width: 900px) 800px, 100vw"
alt="Hero image">
</picture>
Replace percentage with viewport units
Before (invalid):
<picture>
<source
media="(min-width: 600px)"
srcset="card-600.webp 600w, card-900.webp 900w"
sizes="50%">
<img
src="card-600.jpg"
srcset="card-600.jpg 600w, card-900.jpg 900w"
sizes="50%"
alt="Product card">
</picture>
After (valid):
<picture>
<source
media="(min-width: 600px)"
srcset="card-600.webp 600w, card-900.webp 900w"
sizes="50vw">
<img
src="card-600.jpg"
srcset="card-600.jpg 600w, card-900.jpg 900w"
sizes="50vw"
alt="Product card">
</picture>
Clean, minimal example with multiple slots
<picture>
<source
type="image/avif"
srcset="banner-480.avif 480w, banner-960.avif 960w, banner-1440.avif 1440w"
sizes="(min-width: 1200px) 960px, (min-width: 600px) 80vw, 100vw">
<img
src="banner-480.jpg"
srcset="banner-480.jpg 480w, banner-960.jpg 960w, banner-1440.jpg 1440w"
sizes="(min-width: 1200px) 960px, (min-width: 600px) 80vw, 100vw"
alt="Responsive banner">
</picture>
If the validator reports “found Y at Z,” inspect the exact character at position Z for a missing unit, stray %, or malformed comma/whitespace, then replace with a valid CSS length unit.
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.