How to make a sitemap link in the page head pass the W3C validator?

The short answer is that you cannot.

HTML 5 defines the values that you are allowed to use in rel and sitemap is not one of the ones recognised by the validator.

The error message does say that you can register a new link type on a wiki, but sitemap is already there so you just have to wait for the validator developers to update the validator to reflect the new state of the wiki (assuming nobody deletes the entry).

(The basic problems here are that having the specification use a wiki page as a normative resource is nuts, that HTML 5 is still a draft, and that the HTML 5 validator is still considered experimental).


Dropping in from the future (June 2021).

The entry:

<link rel="sitemap" type="application/xml" title="Sitemap" href="/sitemap.xml">

is now accepted by the W3 HTML5 Validator

That is to say:

rel="sitemap"

is now a valid attribute + value.

Validating the following HTML file:

<!DOCTYPE html>
<html lang="en-gb">
<head>
<meta charset="utf-8">
<title>My Rel Sitemap Test</title>
<link rel="sitemap" type="application/xml" title="Sitemap" href="/sitemap.xml">
</head>

<body>
<h1>My Rel Sitemap Test</h1>
<p>This is my Rel Sitemap Test.</p>
<p>The document passes.</p>
<p>This document is valid HTML5 + ARIA + SVG 2 + MathML 3.0</p>
</body>
</html>

here: https://validator.w3.org/nu/

returns the response:

Document checking completed. No errors or warnings to show.


If you only need w3c validator to pass, perhaps you could detect its user agent and modify the output of your application so that it passes. I think of strict validation as more of a marketing benefit then anything when it comes to minor issues like this. If other developers use w3c validator to say your client's web site is full of errors, then that is annoying.

You can check if the HTTP_USER_AGENT contains "W3C_Validator" and remove the non-standard code.

In CFML, I wrote code like this to make my Google Authorship link still able to validate on w3c validator:

<cfif cgi.HTTP_USER_AGENT CONTAINS "W3C_Validator">data-</cfif>rel="publisher"

I just posted a question on the google forum if they could begin supporting data-rel or if they could confirm if google search does already support it. The structured data testing tool they provide doesn't parse data-rel when I tested it just now. http://www.google.com/webmasters/tools/richsnippets

Hopefully, someone will follow up: https://groups.google.com/a/googleproductforums.com/d/msg/webmasters/-/g0RDfpFwmqAJ