← Back to HTML & CSS, page 9

html-css-0163 · Medium mid

Which link rel values do you use in the head and on anchors, and what does each one do?

In the head, rel values include stylesheet, icon, manifest, canonical, alternate with hreflang, and the performance hints. On anchors, noopener and noreferrer protect the opener, and nofollow, ugc and sponsored tell search engines how to treat the link.

Full answer

The rel attribute names the relationship between the current page and the linked resource. It works on link elements in the head and on a and form elements.

Values on link in the head:

  • stylesheet loads CSS. icon gives the small image for the tab. manifest points to the web app manifest.
  • canonical names the preferred address when the same content has several. Search engines use it as a strong hint.
  • alternate points to another version. With hreflang it lists translations: <link rel="alternate" hreflang="hi" href="...">. With type it can point to a feed.
  • preload, prefetch, preconnect and dns-prefetch are performance hints.
  • prev and next mark pages of a series, but major search engines no longer use them. Keep normal links in the page.

Values on anchors, in a space-separated list:

  • noopener stops the new page from reaching window.opener. Current browsers apply it to target="_blank" by default, but writing it is still common.
  • noreferrer hides the referring address, and it also implies noopener.
  • nofollow asks search engines not to count the link. ugc marks links in user content and sponsored marks paid links. They can be combined.
  • external, author, license, help and me describe the target, and me is used for identity links.

A rel value the browser does not know is ignored. relList.supports("preload") tells whether a value is supported for that element.

The canonical link gives the one preferred address. The alternate link names the Hindi version. The anchor carries four values, and its relList shows them as a list.

Use only values that you mean, since wrong values can send the wrong signal to search engines.

html
<link rel="canonical" href="https://example.com/courses/html" id="can">
<link rel="alternate" hreflang="hi" href="https://example.com/hi/courses/html" id="alt">
<link rel="icon" href="data:," id="ico">
<a href="https://example.org" target="_blank" rel="noopener noreferrer nofollow ugc" id="a">Comment link</a>

Run in Chrome 156 (headless) as a page; the snippet is wrapped in a minimal HTML document with doctype, charset and viewport meta tag. Two full runs gave identical results, and the measured values in the answer come from them.

Key points

  • canonical names the preferred URL.
  • alternate with hreflang lists translations.
  • icon and manifest describe the site to the browser.
  • noopener and noreferrer protect the opener.
  • nofollow, ugc and sponsored describe link trust.

Common mistakes

  • Putting nofollow on all outgoing links without a reason.
  • Forgetting that the canonical link must be an absolute, correct address.
  • Using rel="prev" and rel="next" and expecting search engines to need them.

Follow-ups

  • What is the difference between nofollow, ugc and sponsored?
  • How can you test whether a rel value is supported?

Tips

  • Split the answer into head values and anchor values.
  • Name canonical, alternate with hreflang, noopener and nofollow.