# Bad value X for attribute “srcset” on element “source”: Expected number greater than zero but found “0” at Y.

> Canonical HTML version: https://rocketvalidator.com/html-validation/bad-value-x-for-attribute-srcset-on-element-source-expected-number-greater-than-zero-but-found-0-at
> Attribution: Rocket Validator (https://rocketvalidator.com)
> License: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/)

The `srcset` attribute lets browsers intelligently choose which image to load based on the viewport size and device pixel ratio. Each entry in a `srcset` consists of a URL followed by either a width descriptor (like `300w`) or a pixel density descriptor (like `2x`). When using width descriptors, the value represents the intrinsic pixel width of the image file — that is, the actual width of the image as stored on disk.

A width descriptor of `0w` violates the [HTML specification](https://html.spec.whatwg.org/multipage/images.html#srcset-attributes), which requires width descriptors to be integers greater than zero. A zero-width image cannot meaningfully participate in the browser's source selection process. The browser uses these width values in combination with the `sizes` attribute to calculate which image best fits the current layout — a value of zero would break this calculation entirely.

This issue commonly occurs when:

- Image dimensions are dynamically generated and a fallback of `0` is used for missing data.
- A placeholder or empty state is accidentally included in the `srcset`.
- A CMS or build tool outputs a `0w` descriptor for images whose dimensions weren't computed.

### Why it matters

- **Standards compliance:** The HTML specification explicitly requires width descriptors to be positive integers. Validators will flag `0w` as an error.
- **Browser behavior:** While browsers may silently ignore the invalid entry, you can't rely on consistent handling across all browsers and versions. The image selection algorithm may behave unpredictably.
- **Performance:** A well-formed `srcset` is key to responsive image loading. Invalid descriptors can prevent browsers from selecting the optimal image, leading to unnecessarily large downloads or poor image quality.

### How to fix it

1. Open the image file associated with the `0w` descriptor and check its actual pixel width using an image editor or the command line.
2. Replace `0w` with the correct width (e.g., `150w` for a 150-pixel-wide image).
3. If the image is truly zero-width or a placeholder, remove that entry from the `srcset` entirely.
4. Ensure every remaining entry has a unique, positive width descriptor.

## Examples

### ❌ Invalid: width descriptor of `0w`

```html
<picture>
  <source
    srcset="/images/icon_placeholder.png 0w,
            /images/icon_large.png 600w"
    media="(max-width: 600px)">
  <img src="/images/icon_fallback.png" alt="App logo">
</picture>
```

The `0w` descriptor triggers the validation error because zero is not a valid width.

### ✅ Fixed: all width descriptors are positive

```html
<picture>
  <source
    srcset="/images/icon_small.png 300w,
            /images/icon_large.png 600w"
    media="(max-width: 600px)">
  <img src="/images/icon_fallback.png" alt="App logo">
</picture>
```

Each entry now has a meaningful width descriptor (`300w` and `600w`) that reflects the actual pixel width of the corresponding image.

### ❌ Invalid: `0w` on an `<img>` element

```html
<img
  srcset="/images/hero_tiny.jpg 0w,
          /images/hero_medium.jpg 800w,
          /images/hero_large.jpg 1200w"
  sizes="100vw"
  src="/images/hero_medium.jpg"
  alt="Mountain landscape">
```

### ✅ Fixed: placeholder entry removed or corrected

If the tiny image is 400 pixels wide, use `400w`:

```html
<img
  srcset="/images/hero_tiny.jpg 400w,
          /images/hero_medium.jpg 800w,
          /images/hero_large.jpg 1200w"
  sizes="100vw"
  src="/images/hero_medium.jpg"
  alt="Mountain landscape">
```

Alternatively, if the image doesn't belong in the set at all, simply remove it:

```html
<img
  srcset="/images/hero_medium.jpg 800w,
          /images/hero_large.jpg 1200w"
  sizes="100vw"
  src="/images/hero_medium.jpg"
  alt="Mountain landscape">
```

When using a build tool or CMS that generates `srcset` values dynamically, add a check to filter out any entries where the computed width is zero or missing before rendering the attribute. This prevents the invalid markup from reaching production.
