Skip to main content

HTML Guide

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

Ensure all descriptors in the srcset have positive widths greater than zero. In the srcset attribute, each source candidate consists of a URL followed by a width descriptor, which should be a positive integer followed by w.

The issue arises from using 0w, which is not valid as width descriptors must be positive numbers. The srcset attribute allows browsers to choose the appropriate image from different candidates based on device resolution and screen size, so specifying a meaningful width is important.

Here’s how you can fix it:

  1. Verify that each candidate in the srcset includes a valid URL and a width descriptor greater than zero.
  2. Decide the relevant width for your images and update the descriptors accordingly.

Here’s a corrected example of how to use the srcset attribute:

<picture>
  <source 
    srcset="/images/icon_small_1x.png 300w,
            /images/icon_small_2x.png 600w" 
    media="(max-width: 600px)">
  <img src="/images/icon_fallback.png" 
       alt="App Logo">
</picture>

In this example, each image in srcset has a positive width descriptor: 300w and 600w. This ensures that the browser can make an appropriate choice based on the current viewport and resolution, adhering to the W3C HTML standards.

Learn more:

Related W3C validator issues