Hreflang Sitemap: How to Add Language Versions to Your XML Sitemap
Show the right language version in the right country. How a hreflang sitemap works, with an example you can copy.

Contents
- What is hreflang?
- Three ways to add hreflang
- Why use a hreflang sitemap?
- Hreflang sitemap example
- Language and region codes
- What is x-default?
- The rules, step by step
- Common hreflang sitemap mistakes
- Hreflang sitemaps for large and multi-domain sites
- How to check your hreflang sitemap
- Do you need hreflang at all?
A hreflang sitemap is an XML sitemap that tells Google which language and country versions of a page belong together. You do this by adding <xhtml:link rel="alternate" hreflang="…"> lines inside each <url> entry. Every version lists all the others, including itself, plus an optional x-default. Google then shows searchers the version that matches their language or country. It works exactly like hreflang tags in the page’s HTML, but keeps everything in one file. This guide gives you a copy-paste example, explains the codes and x-default, covers large and multi-domain sites, and lists the mistakes that stop hreflang from working.
What is hreflang?
Hreflang is an attribute that tells search engines “this page has other versions in other languages or for other regions, and here they are”. For example, an English page for the UK, an English page for the USA and a Spanish page for Spain can all point to each other. Google then shows the British page to searchers in the UK, the American page in the US, and the Spanish page to Spanish speakers.
Hreflang does not translate anything and it is not a ranking boost. It simply helps the right version appear in the right country, and it reduces the risk of similar pages being treated as duplicates.
Three ways to add hreflang
| Method | Where it goes | Best for |
|---|---|---|
| HTML tags | <link rel="alternate" hreflang="…"> in each page’s <head> | Small sites and CMS plugins that add tags for you |
| HTTP headers | A Link: header sent by the server | Non-HTML files such as PDFs |
| XML sitemap | <xhtml:link> elements inside each <url> | Large or multi-country sites, and when you can’t edit page templates |
Google treats all three methods the same. Pick one and use it consistently — mixing methods makes mistakes much harder to spot.
Why use a hreflang sitemap?
- Lighter pages. A page with 20 language versions would otherwise need 20 extra tags in its
<head>. - One place to manage. All language connections live in one file, so they are easy to check and update.
- No template changes. Useful when your developers or your platform make it hard to edit the page header.
Hreflang sitemap example
Here is a sitemap for one page that exists in three versions: English for the UK, English for the USA, and Spanish. Notice the extra xmlns:xhtml namespace on the root tag:
<?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/en-gb/pricing</loc>
<xhtml:link rel="alternate" hreflang="en-gb" href="https://example.com/en-gb/pricing"/>
<xhtml:link rel="alternate" hreflang="en-us" href="https://example.com/en-us/pricing"/>
<xhtml:link rel="alternate" hreflang="es" href="https://example.com/es/precios"/>
<xhtml:link rel="alternate" hreflang="x-default" href="https://example.com/pricing"/>
</url>
<url>
<loc>https://example.com/en-us/pricing</loc>
<xhtml:link rel="alternate" hreflang="en-gb" href="https://example.com/en-gb/pricing"/>
<xhtml:link rel="alternate" hreflang="en-us" href="https://example.com/en-us/pricing"/>
<xhtml:link rel="alternate" hreflang="es" href="https://example.com/es/precios"/>
<xhtml:link rel="alternate" hreflang="x-default" href="https://example.com/pricing"/>
</url>
<url>
<loc>https://example.com/es/precios</loc>
<xhtml:link rel="alternate" hreflang="en-gb" href="https://example.com/en-gb/pricing"/>
<xhtml:link rel="alternate" hreflang="en-us" href="https://example.com/en-us/pricing"/>
<xhtml:link rel="alternate" hreflang="es" href="https://example.com/es/precios"/>
<xhtml:link rel="alternate" hreflang="x-default" href="https://example.com/pricing"/>
</url>
</urlset>
Each language version gets its own <url> entry, and every entry lists the full set of alternates — including itself. That repetition is intentional: it is how Google confirms the pages belong together.
Language and region codes
The hreflang value is a language code, optionally followed by a region code:
| Value | Means |
|---|---|
en | English, for English speakers anywhere |
en-pk | English, for users in Pakistan |
ur-pk | Urdu, for users in Pakistan |
ar-ae | Arabic, for users in the United Arab Emirates |
en-gb | English, for users in the United Kingdom (not en-uk) |
x-default | The fallback page when no other version matches |
You cannot use a region on its own. pk by itself is read as a language code (and is not a valid one), so always start with the language. When a page targets a country, it is good practice to also include a language-only version (such as en) as a catch-all.
What is x-default?
x-default tells Google which page to show when a searcher’s language or country doesn’t match any of your versions. For example, it might be a page where visitors choose their language, or your main international English page. It is optional but recommended. Like every other alternate, it must appear in the entry of every version, and it should point to a live, indexable page.
The rules, step by step
- Add the namespace. The root
<urlset>must includexmlns:xhtml="http://www.w3.org/1999/xhtml", or the links are ignored. - Use correct codes. The language is a two-letter ISO 639-1 code (
en,es,de). An optional region uses ISO 3166-1 alpha-2 (gb,us,mx). The UK isen-gb, noten-uk. - List every version in every entry, including the page itself (the “self-reference”).
- Make the links two-way. If page A points to page B, page B must point back to page A. Links without a return link are ignored.
- Add
x-defaultfor the page to show when no language matches — often a language-selector page or your main version. - Use full, final URLs. Every
hrefmust be absolute and point to a live, indexable, canonical page — not a redirect, a 404 or anoindexpage.
Common hreflang sitemap mistakes
| Mistake | What happens | Fix |
|---|---|---|
| Missing return links | Google ignores the pair | Make sure every version lists all the others |
Wrong codes (en-uk, es-LA) | The tag is invalid | Use ISO language and country codes only |
| Alternates that redirect or are non-canonical | Conflicting signals | Point only to the canonical, final URL |
Missing xmlns:xhtml | Links are not read at all | Add the namespace to the root tag |
| Language only on some pages | Visitors land on the wrong version | Cover every translated page, not just the homepage |
Hreflang sitemaps for large and multi-domain sites
Splitting across files with a sitemap index
Hreflang makes sitemaps grow fast. A site in 10 languages adds 10 <xhtml:link> lines to every entry, so files often reach the 50 MB size limit long before the 50,000-URL limit. Split the URLs over several files and join them with a sitemap index. A common split is one file per language. The entry for each URL must still list all of its alternates, but the alternate pages themselves can be listed in other files. See sitemap size limits explained for the exact numbers.
Versions on different domains
Alternates can live on different domains, for example example.pk and example.ae. If you list them all in one sitemap hosted on a single domain, Google needs proof that you own every domain in it. Verify each one in Search Console. Otherwise, give each domain its own sitemap with the same hreflang sets.
Tip: Hreflang URLs must match your canonical tags. If you are not sure your pages are self-canonical, read our guide to non-canonical URLs in sitemaps first.
How to check your hreflang sitemap
Hreflang errors are easy to make and hard to see by eye, so test the file before you submit it:
- Run it through our Sitemap Checker. It validates the XML and namespaces, and its summary shows how many
hreflanglinks it found. A quick sum helps here. Three versions, each listing three alternates plusx-default, should give 12 links. A much lower number means links are missing or not being read. - Export the URLs with the Sitemap URL Extractor and compare the language folders in a spreadsheet, to catch pages that exist in one language but not another.
- Submit the sitemap in Search Console and add it to robots.txt, as described in how to submit a sitemap to Google.
Do you need hreflang at all?
Only if you have the same or similar content in more than one language or for more than one country. A site in a single language for a single market doesn’t need it. If you translate only part of your site, add hreflang just to the pages that have translations. The rest can stay as normal sitemap entries. New to sitemaps? Start with What Is an XML Sitemap? and build the base file with our free XML Sitemap Generator, then add the hreflang links for your translated pages.
Frequently asked questions
Quick answers to the questions we hear most. Still have a question? Ask us through our contact page.
What is a hreflang sitemap?
An XML sitemap that uses xhtml:link tags to tell search engines which pages are language or country versions of each other.
Is a hreflang sitemap better than HTML tags?
Google treats both the same. A sitemap is easier to manage on large sites and keeps page headers light.
Does every URL need to list itself?
Yes. Each entry should list all language versions, including itself, and every version must link back.
What is x-default?
The fallback page Google shows when none of your language or country versions match the searcher.
Which hreflang code is used for Urdu in Pakistan?
ur-pk: the language code ur followed by the country code pk. English for Pakistan is en-pk. A country code can never be used on its own.
Can hreflang versions be on different domains?
Yes. If one sitemap lists URLs on several domains, verify every domain in Google Search Console. Otherwise, give each domain its own sitemap with the same hreflang sets.


