spectras
spectras

Reputation: 13552

Metadata: should I prefer <link> or <a> with rel attribute

In the process of having correct metadata in my pages, I wonder how <link> tags are actually used (by browsers, crawlers or other tools), and whether they need to be duplicated.

In practice: if I have explicit navigation links in my page, such as this trimmed down example:

<html><body>
  <a href="/page/1">Previous page</a>
  <a href="/page/3">Next page</a>
</body></html>

…then which of those two versions is superior, and why?

Version 1 — using <link> elements for metadata:

<html><head>
  <link rel="prev" href="/page/1">
  <link rel="next" href="/page/3">
</head><body>
  <a href="/page/1">Previous page</a>
  <a href="/page/3">Next page</a>
</body></html>

Version 2 — specifying rel type on links:

<html><body>
  <a rel="prev" href="/page/1">Previous page</a>
  <a rel="next" href="/page/3">Next page</a>
</body></html>

This is valid according to MDN, as prev and next are valid values for the rel attribute on a a element.

Are those equivalent? Are there tools/browsers known to recognize one version but not the other? Should I put both to be safe?

Upvotes: 2

Views: 90

Answers (1)

Mr Lister
Mr Lister

Reputation: 46589

From a practical standpoint, it doesn't really matter.

In most browsers, the <link> elements don't do anything. There are some browsers that still support the navigation links, but they are rare these days, AFAIK only SeaMonkey does this. Opera supported them until v12, and I believe there is a browser for the Mac, iCab, but nobody ever heard of that one. So, you don't have to do it as far as the user interface is concerned.

Webcrawlers can use <link>s for crawling sites more thoroughly, but if you have rel attributes in the <a> elements anyway, that doesn't really make a difference.

Personally, since I'm a heavy SeaMonkey user, I do use <link>s extensively on my own site, and so you can navigate around on it without ever needing an <a>. See this page for an example, but I don't really expect people to go to the same lengths on their own sites.

The question what is better from a semantical viewpoint however, I'm afraid I'm not sure. Maybe it won't hurt to put in both, but duplicating the same info in two different places seems overkill. (DRY springs to mind.)

Upvotes: 2

Related Questions