href apparently not required on preload imagesrcset LINK

For technical support for all editions of CSS HTML Validator. Includes bug reports.
Post Reply
TomHTML
Rank III - Intermediate
Rank III - Intermediate
Posts: 60
Joined: Sun Feb 04, 2018 10:19 am

href apparently not required on preload imagesrcset LINK

Post by TomHTML »

The HTML specs on the rel=preload imagesrcset LINK element found here:

https://html.spec.whatwg.org/multipage/ ... magesrcset

...includes this example:
These attributes allow preloading the appropriate resource that is later used by an img element that has the corresponding values for its srcset and sizes attributes:

Code: Select all

<link rel="preload" as="image"
      imagesrcset="wolf_400px.jpg 400w, wolf_800px.jpg 800w, wolf_1600px.jpg 1600w"
      imagesizes="50vw">

<!-- ... later, or perhaps inserted dynamically ... -->
<img src="wolf.jpg" alt="A rad wolf"
     srcset="wolf_400px.jpg 400w, wolf_800px.jpg 800w, wolf_1600px.jpg 1600w"
     sizes="50vw">
Note how we omit the href attribute, as it would only be relevant for browsers that do not support imagesrcset, and in those cases it would likely cause the incorrect image to be preloaded.
The last sentence indicates that no `href` belongs on this LINK element. However, when I attempt to validate it with the validator, it issues this error:
The "link" element requires the "href" attribute to specify the link. This is an HTML5 requirement.
Unless the spec quoted above has been revised, it looks like the validator shouldn't count this type of LINK without an `href` as erroneous HTML.
User avatar
Albert Wiersch
Site Admin
Site Admin
Posts: 3644
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX
Contact:

Re: href apparently not required on preload imagesrcset LINK

Post by Albert Wiersch »

Hello,

Thank you. The HTML5 spec now says this for the "link" element:
One or both of the href or imagesrcset attributes must be present.
I've fixed this in the latest config file which is available here:
https://www.htmlvalidator.com/2021/htmlvalV210cfg.zip

Please see the "readme" file in the above ZIP file for installation instructions.
TomHTML
Rank III - Intermediate
Rank III - Intermediate
Posts: 60
Joined: Sun Feb 04, 2018 10:19 am

Re: href apparently not required on preload imagesrcset LINK

Post by TomHTML »

Thanks! I can confirm it works for my site code. And it identified a few images that were misnamed in the imagesrcset listing that I wouldn't have caught otherwise (it reported a 404 when trying to retrieve them...fantastic!)
User avatar
Albert Wiersch
Site Admin
Site Admin
Posts: 3644
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX
Contact:

Re: href apparently not required on preload imagesrcset LINK

Post by Albert Wiersch »

TomHTML wrote: Sun Oct 10, 2021 3:59 pm Thanks! I can confirm it works for my site code. And it identified a few images that were misnamed in the imagesrcset listing that I wouldn't have caught otherwise (it reported a 404 when trying to retrieve them...fantastic!)
Great! :D
Post Reply