Description
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 update the source set, default source will remain the empty string
- In create a source set, if default source is the empty string, obviously there's nothing to add to source set
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?