hreflang in an XML sitemap is one of three ways to tell Google about language and country versions of a page. Instead of the HTML head, the links sit in the sitemap as xhtml:link entries for each URL.
How does it work?
The sitemap needs the namespace xmlns:xhtml="http://www.w3.org/1999/xhtml". According to Google, each <url> element must contain a child <xhtml:link rel="alternate" hreflang="..."> for every alternate version, including the page itself. Each language version gets its own <url> block with the same set of links, so the versions confirm each other.
The method helps when the HTML head is hard to change or when the links are generated from central data. Errors become visible in the sitemap file or in testing tools rather than on the page. According to Google, the xhtml:link child elements do not count toward a sitemap’s URL limit, and using several methods at once brings no benefit.
Example
<url>
<loc>https://example.com/en/page/</loc>
<xhtml:link rel="alternate" hreflang="en" href="https://example.com/en/page/"/>
<xhtml:link rel="alternate" hreflang="de" href="https://example.com/de/seite/"/>
<xhtml:link rel="alternate" hreflang="x-default" href="https://example.com/"/>
</url>
A second <url> block for https://example.com/de/seite/ holds the same three links.
Common mistakes
- A version is missing or does not link back
- The page does not list itself
- Language and region codes in the wrong order, such as the region first
Sources
- Tell Google about localized versions of your page – Google Search Centraldevelopers.google.com
- hreflang sitemap – Weglot (secondary)weglot.com
- XML sitemap with hreflang tags – seoClarity (secondary)seoclarity.net
Last updated: