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

> Canonical HTML version: https://rocketvalidator.com/html-validation/bad-value-for-attribute-srcset-on-element-img-ends-with-empty-image-candidate-string
> Attribution: Rocket Validator (https://rocketvalidator.com)
> License: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/)

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

```html
<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

```html
<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.
