Skip to main content
HTML Validation

Bad value X for attribute “srcset” on element “source”: Expected number followed by “w” or “x” but found Y at Z.

About This HTML Issue

A srcset attribute on a <source> element inside a <picture> requires each image URL to be paired with a width descriptor (w) or a pixel density descriptor (x).

The srcset attribute differs from the src attribute. While src accepts a bare URL, srcset expects one or more image candidates, where each candidate is a URL followed by a space and a descriptor. When no descriptor is provided, the W3C validator rejects the value because it cannot determine how the browser should select the image.

A width descriptor like 600w tells the browser the intrinsic width of the image in pixels. A pixel density descriptor like 1x or 2x indicates the intended display density. If you only have a single image and don't need responsive selection, you can still satisfy the validator by appending a descriptor.

When <source> is used inside <picture>, the srcset attribute is required instead of src. This is defined in the HTML specification: the <source> element within <picture> does not support src.

Invalid example

<picture>
  <source type="image/webp" srcset="/images/img01.webp">
  <img src="/images/img01.jpg" alt="A sample image" width="600" height="400">
</picture>

Valid examples

Add a width descriptor to each entry in srcset:

<picture>
  <source
    type="image/webp"
    srcset="/images/img01-600.webp 600w, /images/img01-1200.webp 1200w"
    sizes="(max-width: 600px) 100vw, 600px">
  <img src="/images/img01.jpg" alt="A sample image" width="600" height="400">
</picture>

If you have a single image and no responsive variants, use a pixel density descriptor:

<picture>
  <source type="image/webp" srcset="/images/img01.webp 1x">
  <img src="/images/img01.jpg" alt="A sample image" width="600" height="400">
</picture>

Find issues like this automatically

Rocket Validator scans thousands of pages in seconds, detecting HTML issues across your entire site.

Help us improve our guides

Was this guide helpful?
🌍 Trusted by teams worldwide

Validate at scale.
Ship accessible websites, faster.

Automated HTML & accessibility validation for large sites. Check thousands of pages against WCAG guidelines and W3C standards in minutes, not days.

Scheduled Reports
API Access
Open Source Standards
$7 / 7 days

Pro Trial

Full Pro access. Cancel anytime.

Start Pro Trial →

Join teams across 40+ countries