Hreflang XML Sitemap

No Comments
Hreflang xml sitemap

AI Summary

Hreflang in the XML sitemap declares your language and region alternates inside the sitemap using xhtml link entries, instead of in the page head or HTTP headers. For large multilingual sites it is usually the least painful method, but you must pick one method and keep hreflang out of the head.

  • Declare the xhtml namespace on the urlset element, or every alternate is silently invalid.
  • Annotations must be bidirectional and self referential, so each url block lists every alternate plus itself.
  • Alternates must point at final, indexable, self canonical 200 URLs, never redirects, noindex pages, or 404s.
  • Use valid ISO codes: the country code for the United Kingdom is gb, not uk.
Diagram of an xml sitemap url block with reciprocal xhtml link hreflang alternates for en-us, en-gb, fr-fr, and x-default, declared in the sitemap only.
Every locale in the cluster lists the full set of alternates plus itself, declared in the sitemap only.

What hreflang in the XML sitemap means

Hreflang in the XML sitemap is one of the three official ways to tell Google which language and region version of a page to serve to which users, you declare the alternates inside the sitemap using <xhtml:link rel="alternate" hreflang="..."> entries instead of putting them in the page's HTML head or HTTP headers. Done right, the correct localized page shows up for the correct audience; done wrong, Google serves your French page to English users or ignores your alternates entirely.

Here is the rule that trips most teams up, and we hold to it firmly: pick one implementation method and stick with it. Hreflang is a clustering signal, and putting it in the sitemap and the HTML head at the same time is redundant, doubles your maintenance surface, and multiplies the chances the two copies drift out of sync and contradict each other. If you use the sitemap method, keep hreflang out of the head.

Why the sitemap method is often the right pick

For large multilingual sites, the sitemap approach is usually the least painful. You keep every hreflang relationship in one file set instead of editing the <head> of thousands of templates, it does not add weight to every page load, and it is far easier to generate and validate programmatically.

MethodBest whenMain downside
XML sitemap (xhtml:link)Large sites, many locales, centralized generationHarder to eyeball per-page; needs a solid sitemap pipeline
HTML head (link rel="alternate")Small sites, per-page control, easy to inspectAdds markup to every page; painful to maintain at scale
HTTP header (Link:)Non-HTML files like PDFsAwkward to manage; easy to forget on new files

Whichever you choose, every rule is the same across methods: annotations must be bidirectional (each page points back), self-referential (each page lists itself), and use valid ISO codes.

A real sitemap entry with alternates

Note the xhtml namespace declared on the opening <urlset> tag, miss that and the whole thing is invalid. This block is a single <url> for a three-locale page (US English, UK English, France French) plus an x-default fallback:

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
        xmlns:xhtml="http://www.w3.org/1999/xhtml">
  <url>
    <loc>https://example.com/us/product/</loc>
    <xhtml:link rel="alternate" hreflang="en-us" href="https://example.com/us/product/"/>
    <xhtml:link rel="alternate" hreflang="en-gb" href="https://example.com/uk/product/"/>
    <xhtml:link rel="alternate" hreflang="fr-fr" href="https://example.com/fr/produit/"/>
    <xhtml:link rel="alternate" hreflang="x-default" href="https://example.com/us/product/"/>
  </url>
</urlset>

Critically, you must repeat the same full set of xhtml:link alternates inside the <url> block for /uk/product/ and /fr/produit/ as well, including each page's self-reference. If the French URL's block does not point back at the US and UK URLs, the cluster is broken and Google discards it.

How to check it on your own site

  1. Open your sitemap file and confirm the xmlns:xhtml namespace is declared on the root <urlset> element. Without it, no xhtml:link is valid.
  2. Pick one page cluster and confirm every locale's <url> block lists the full set of alternates, including a self-referential entry.
  3. Confirm the return links match exactly, if A lists B, B must list A, with identical absolute URLs (same protocol, same trailing-slash convention).
  4. Grep your page source and HTTP headers to make sure hreflang is not also present there. Two methods at once is the mistake you are checking for.
  5. Submit the sitemap in Search Console and watch the International Targeting / hreflang error signals, plus run a crawl in a validator that parses sitemap hreflang.
  6. Verify the URLs in the alternates return 200 and are indexable, hreflang pointing at redirected, noindexed, or 404 URLs is ignored.

Common mistakes and how to fix them

  • Declaring hreflang in both the sitemap and the head. Redundant and fragile, the two copies drift apart and send Google conflicting instructions. Choose the sitemap method and strip hreflang out of the HTML head entirely.
  • Forgetting the xhtml namespace. No xmlns:xhtml on <urlset> means every alternate is silently invalid. Add it once at the top.
  • Missing return links. Every page in the cluster must list every other page and itself. A one-way reference gets thrown out. Generate the blocks from one source of truth so they stay symmetric.
  • Pointing at non-canonical or non-200 URLs. Alternates must be the final, indexable, self-canonical URLs. Hreflang to a redirect, a noindex page, or a 404 is discarded.
  • Wrong or invented codes. hreflang="en-uk" is invalid, the country is gb. Use ISO 639-1 language plus optional ISO 3166-1 Alpha-2 region, and remember hreflang region is optional while language is required.

FAQ

Can I use both sitemap and HTML head hreflang for safety?

Don't. It is not a safety net, it is two things to keep in sync that inevitably diverge, and when they contradict each other Google has to guess. Pick one method. If it is the sitemap, keep the head clean.

Do I still need self-referential hreflang in the sitemap?

Yes. Each <url> block must include an xhtml:link pointing to itself. A cluster without self-references is treated as incomplete and often dropped.

Is hreflang in the sitemap the same as the language attribute?

No, and this is a frequent mix-up. Hreflang tells search engines about alternate localized versions. The HTML lang attribute tells browsers and assistive tech what language this page is written in. Different jobs, you often need both, but one never replaces the other.

How do I know Google accepted my sitemap hreflang?

Submit the sitemap in Search Console and monitor for hreflang errors. Then spot-check by seeing whether the right locale surfaces for the right region. For deeper validation, crawl with a tool that parses xhtml:link from sitemaps.

What does x-default do here?

The x-default alternate names the fallback page for users whose language or region you have not explicitly targeted. It is optional but recommended, it stops Google from guessing when someone falls outside your defined locales.

Related reading

Claude Vincent is a technical SEO consultant focused on crawlability, rendering, and AI-search visibility. He writes the field guides and case studies at SEO ProCheck, with a bias toward the durable, unglamorous work that decides whether search engines and AI answer engines can actually read and cite a site.

About SEO ProCheck

Technical SEO consulting and GEO strategy with 20 years of enterprise experience. Case studies, resources, and tools for search and AI visibility.

Work With Me

Technical SEO audits, GEO strategy, site migrations, and international SEO. Hourly consulting for teams who need hands-on support, not just reports.

Subscribe to our newsletter!

More from our blog