XML Sitemap Hreflang Syntax

You've got hundreds of translated pages and no appetite for editing a <head> tag on every single one. So you skip the HTML link tags and try declaring hreflang in your XML sitemap instead — only to check Search Console a week later and find the International Targeting report empty, as if you'd never added anything at all.

Sitemap hreflang isn't harder than the HTML version, but it's less forgiving of small mistakes. There's a namespace declaration it depends on, an element name that looks similar to HTML's but isn't identical, and a nesting structure that's easy to get subtly wrong without a validator ever telling you why it failed.

Quick Answer

Hreflang in an XML sitemap is written using xhtml:link elements nested inside each <url> block, with rel="alternate" and hreflang="code" attributes. The sitemap's opening <urlset> tag must declare the xmlns:xhtml namespace, and every URL in a cluster needs a full, self-referencing set of alternates — the same return-tag rule that applies to HTML hreflang.

What is sitemap hreflang syntax?

Sitemap hreflang is the same underlying signal as HTML hreflang — a declaration that several URLs are language or region alternates of the same content — written in XML instead of inside a page's head. It uses elements borrowed from the XHTML namespace rather than the plain sitemap schema, which is why the namespace declaration matters so much.

<!-- Minimal example: two language versions of one page --> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml"> <url> <loc>https://example.com/en/</loc> <xhtml:link rel="alternate" hreflang="en" href="https://example.com/en/" /> <xhtml:link rel="alternate" hreflang="fr" href="https://example.com/fr/" /> </url> <url> <loc>https://example.com/fr/</loc> <xhtml:link rel="alternate" hreflang="en" href="https://example.com/en/" /> <xhtml:link rel="alternate" hreflang="fr" href="https://example.com/fr/" /> </url> </urlset>

Why it matters

Choosing the sitemap over HTML tags is usually a practical decision, and getting the syntax right is what makes that decision pay off:

📊 Quick stat The most frequent reason a sitemap's hreflang entries are silently ignored isn't a wrong language code — it's a missing or misspelled xmlns:xhtml namespace declaration on the <urlset> tag.

Step-by-step: writing hreflang into a sitemap

  1. Start from a valid sitemap. Confirm your base sitemap already validates against the standard sitemap schema before adding hreflang on top of it.
  2. Add the xhtml namespace. Include xmlns:xhtml="http://www.w3.org/1999/xhtml" on the opening <urlset> tag alongside the default sitemap namespace.
  3. Group your URLs by cluster. Identify which <url> blocks represent the same content in different languages or regions.
  4. Nest a full set of xhtml:link entries in every block. Each <url> element needs one xhtml:link per page in the cluster, including itself, all using rel="alternate".
  5. Use absolute URLs in every href. Match the canonical, fully-qualified version of each URL exactly, protocol included.
  6. Add x-default where relevant. Include one additional xhtml:link with hreflang="x-default" per block if you have a sensible fallback page.
  7. Submit and validate. Upload the sitemap in Google Search Console and check the International Targeting report for return-tag or namespace errors.
Try the Rebrixe Hreflang Generator — free Add your URL clusters and language codes, get ready-to-paste sitemap XML with the namespace and return tags handled for you.
Generate Hreflang Tags →

Common mistakes that break sitemap hreflang

1. Forgetting the xhtml namespace declaration

Without xmlns:xhtml on the <urlset> tag, every xhtml:link element in the file is technically invalid in this schema context, and parsers typically drop the whole hreflang block rather than erroring loudly.

2. Missing return tags across url blocks

The same rule from HTML hreflang carries over here: if the English <url> block lists the French page but the French block doesn't list the English page back, the pair is treated as unreliable and ignored.

3. Confusing xhtml:link with a plain link element

Writing <link rel="alternate" hreflang="fr" ... /> without the xhtml: prefix means the element doesn't belong to the declared namespace and won't be recognized as a hreflang annotation at all.

4. Using relative or mismatched URLs

Every href value inside an xhtml:link needs to be the full, absolute, canonical URL — a relative path or a URL that doesn't exactly match the page's actual canonical is a common cause of validator warnings.

5. Letting the sitemap grow stale as pages change

Because sitemap hreflang is centralized, it's easy to forget it needs regenerating whenever a page is added, moved, or removed — unlike HTML tags, there's no visual reminder on the page itself that something is now out of sync.

💡 Pro tip Generate sitemap hreflang programmatically from the same source-of-truth URL-to-language mapping you'd use for HTML hreflang, so the two never drift apart if you ever switch methods later.

Real-world examples

Where sitemap hreflang syntax tends to show up in practice:

Large marketplace
Thousands of listing pages
50k+ URLs
Hreflang generated into the sitemap at build time rather than edited into individual listing templates.
Documentation site
PDF and non-HTML alternates
Sitemap-only
PDF manuals in multiple languages linked through the sitemap since they can't carry a head tag of their own.
News aggregator
Regional edition clusters
en-US / en-GB / en-IN
Sitemap hreflang keeps three regional editions distinct without editing article templates per region.
SaaS platform
Frequent page additions
CI-generated
Sitemap XML rebuilt on every deploy so new language pages are automatically added to every existing cluster.

In every case, the sitemap wins on scale and automation — it's the better fit whenever pages are added faster than templates get manually updated.

Sitemap hreflang vs HTML hreflang

Both methods declare the same signal; the difference is where the maintenance burden sits.

Aspect XML sitemap HTML head tags
Setup location One central file Every page template
Works for non-HTML files Yes No
Return-tag rule applies Yes, per url block Yes, per page
Fails silently on error Often, via namespace issues Sometimes, via missing return tags
Best fit Large sites, non-HTML files, frequent page additions Small to mid-size templated sites

Generate your hreflang tags right now — free

The Rebrixe Hreflang Generator builds a complete, return-tag-safe set of hreflang markup for every page in your cluster, including x-default, in both HTML link-tag format and sitemap-ready XML. No account, no watermark — enter your URLs and language codes, and copy the finished markup.

Free Hreflang Tag Generator Add your pages and codes, copy the complete tag set.
Open Hreflang Generator →

Frequently asked questions

Hreflang in a sitemap is written as an xhtml:link element nested inside a url block, using rel="alternate" and hreflang="code" attributes, with the sitemap's opening tag declaring the xhtml namespace so those elements are recognized.
The most common cause is a missing xmlns:xhtml namespace declaration on the urlset tag — without it, parsers don't recognize xhtml:link elements as valid, and the entire hreflang block is silently ignored.
Yes. Just like HTML hreflang tags, each url block in a sitemap needs an xhtml:link entry pointing back to itself, in addition to entries for every other page in the set.
It's possible but not recommended, since conflicting entries between the two sources create ambiguous signals. Pick one method — sitemap or HTML head tags — and use it exclusively across the whole cluster.
Yes, x-default works the same way inside a sitemap as it does in HTML — it's added as an additional xhtml:link entry with hreflang="x-default" pointing to the fallback URL for unmatched visitors.
Each hreflang entry adds to a sitemap's overall size and URL count, so a sitemap approaching the 50,000-URL or 50MB uncompressed limit should be split and linked through a sitemap index file.
Yes, and this is one of sitemap hreflang's main advantages — PDFs and other non-HTML files can't carry a head tag, so declaring their alternates through the sitemap or an HTTP header is the only practical option.
Submit the sitemap in Google Search Console and check the International Targeting report for return-tag or format errors, or run the raw XML through a sitemap-aware hreflang validator before publishing.

Generate your hreflang tags in seconds

The Rebrixe Hreflang Generator builds a complete, return-tag-safe set of hreflang markup — no account, no watermark, just ready-to-paste HTML tags or sitemap XML for every page in your cluster.

Launch the Hreflang Generator →
← Back to blogs