https://html.spec.whatwg.org/multipage/embedded-content.html#the-img-element currently requires:
The src attribute must be present, and must contain a valid non-empty URL potentially surrounded by spaces referencing a non-interactive, optionally animated, image resource that is neither paged nor scripted.
and
The srcset attribute may also be present, and is a srcset attribute.
In other words, a validator should complain about an img element with a srcset attribute but no src, and https://validator.nu/ does.
However, it's not clear why it's important to require putting one source in the src attribute, instead of putting them all in srcset. The processing model deals with src being missing:
In other words, omitting src works just fine in practice.
When srcset was new it made sense to require a src, but now srcset has been supported everywhere for many years:
https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/srcset#browser_compatibility
Is it time to make src optional and not require sending unused markup like this?
https://html.spec.whatwg.org/multipage/embedded-content.html#the-img-element currently requires:
and
In other words, a validator should complain about an
imgelement with asrcsetattribute but nosrc, and https://validator.nu/ does.However, it's not clear why it's important to require putting one source in the
srcattribute, instead of putting them all insrcset. The processing model deals withsrcbeing missing:In other words, omitting
srcworks just fine in practice.When
srcsetwas new it made sense to require asrc, but nowsrcsethas been supported everywhere for many years:https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/srcset#browser_compatibility
Is it time to make
srcoptional and not require sending unused markup like this?