Skip to content

Make <img> src attribute optional if srcset is present #9181

Open
@foolip

Description

@foolip

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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions