Skip to main content

Day 53 of 100DaysOfSpec, 4.2.4 The link element, contd.

I am reading and taking notes on the HTML specifications for 100 days as part of #The100DayProject. Read the initial intent/backstory. I am a Microsoft employee but all opinions, comments, etc on this site are my own. I do not speak on behalf of my employer, and thus no comments should be taken as representative of Microsoft's official opinion of the spec. Subsections not listed below were read without comment.

Currently reading in 4.2.4 The link element

UAs (User Agents, for ex, browsers) can surface the link element as a clickable/tappable hyperlink somewhere in the UI; not too much strict guidance on how to do that. I didn’t realize that; I previously thought the link element was pretty much only for loading resources or creating relationships between pages for the sake of machines.

Still uncertain of a living use case.

The media attribute—which describes what kind of media the document was made for, all, handheld, etc—is handled a little bit differently based on what type of link the element is. If it’s a hyperlink, it’s just sort of nice-to-have information.

If the link is actually loading a resource, that resource has to be applied if and only if the “environment” the document is in matches the value of the media attribute (so you could conceivably load a resource only on handheld devices, for example).

If you don’t set the media attribute, the default value is all.

hreflang attribute

Gives the language (human language in ISO values, not a coding language) the linked resource is in, but that’s “purely advisory”.

type attribute

Also purely advistory, containing a MIME type of the linked resource (likely you’ve seen text/html). Here’s a giant list of MIME types, can’t personally speak to how accurate or up to date that is.

The type attribute can help the UA/browser avoid trying to load a resource it doesn’t support, as UAs are supposed to assume—only when fetching—that the resource type matches the value given. No type attribute present falls back to a default type. Lack of detail there suggests this may change given certain contexts.

HOWEVER, UAs are not to trust the type attribute to determine the resource’s type after it has been fetched. There’s a process for using the resource’s Content-Type metadata, and/or applying type sniffing rules.

Only after determining the resource’s true type is the resource applied or not applied, according to UA support and some other rules about relationships between rel and type (for example, the UA should not apply a link with rel="stylesheet" and type="text/plain").

title attribute

Advisory unless it defines “alternative style sheet sets” on a stylesheet link. This attribute doesn’t inherit from the document title, which makes sense because you’re linking up an external resource or document.

sizes attribute

Only used on link elements with rel="icon".


My blog uses Webmentions. Responses from sites which likewise support Webmentions, such as Twitter or people’s personal sites, will show up here.

No Webmentions have been sent to this post yet.