Skip to main content
HTML Validation

Bad value for attribute “srcset” on element “img”: Ends with empty image-candidate string.

About This HTML Issue

An srcset attribute must not end with a trailing comma, as each entry must be a complete image candidate string with a URL and an optional width or pixel density descriptor.

The srcset attribute accepts a comma-separated list of image candidate strings. Each string contains a URL and, optionally, a width descriptor (like 400w) or a pixel density descriptor (like 2x). A trailing comma after the last entry creates an empty image candidate string, which is invalid.

This error often appears when srcset values are built dynamically by a template engine or CMS that appends a comma after every item, including the last one.

Invalid example

<img
  srcset="image-small.jpg 400w,
          image-medium.jpg 800w,
          image-large.jpg 1200w,"
  sizes="(max-width: 800px) 400px, 800px"
  src="image-medium.jpg"
  alt="A sample photo"
>

The trailing comma after image-large.jpg 1200w, produces the validation error.

Fixed example

<img
  srcset="image-small.jpg 400w,
          image-medium.jpg 800w,
          image-large.jpg 1200w"
  sizes="(max-width: 800px) 400px, 800px"
  src="image-medium.jpg"
  alt="A sample photo"
>

Removing the trailing comma after the last image candidate string fixes the issue.

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