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.

Hreflang Sitemap: How to Add Language Versions to Your XML Sitemap
Contents
  1. What is hreflang?
  2. Three ways to add hreflang
  3. Why use a hreflang sitemap?
  4. Hreflang sitemap example
  5. Language and region codes
  6. What is x-default?
  7. The rules, step by step
  8. Common hreflang sitemap mistakes
  9. Hreflang sitemaps for large and multi-domain sites
  10. How to check your hreflang sitemap
  11. 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

MethodWhere it goesBest for
HTML tags<link rel="alternate" hreflang="…"> in each page’s <head>Small sites and CMS plugins that add tags for you
HTTP headersA Link: header sent by the serverNon-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:

ValueMeans
enEnglish, for English speakers anywhere
en-pkEnglish, for users in Pakistan
ur-pkUrdu, for users in Pakistan
ar-aeArabic, for users in the United Arab Emirates
en-gbEnglish, for users in the United Kingdom (not en-uk)
x-defaultThe 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

  1. Add the namespace. The root <urlset> must include xmlns:xhtml="http://www.w3.org/1999/xhtml", or the links are ignored.
  2. 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 is en-gb, not en-uk.
  3. List every version in every entry, including the page itself (the “self-reference”).
  4. 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.
  5. Add x-default for the page to show when no language matches — often a language-selector page or your main version.
  6. Use full, final URLs. Every href must be absolute and point to a live, indexable, canonical page — not a redirect, a 404 or a noindex page.

Common hreflang sitemap mistakes

MistakeWhat happensFix
Missing return linksGoogle ignores the pairMake sure every version lists all the others
Wrong codes (en-uk, es-LA)The tag is invalidUse ISO language and country codes only
Alternates that redirect or are non-canonicalConflicting signalsPoint only to the canonical, final URL
Missing xmlns:xhtmlLinks are not read at allAdd the namespace to the root tag
Language only on some pagesVisitors land on the wrong versionCover 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 hreflang links it found. A quick sum helps here. Three versions, each listing three alternates plus x-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.

Crawly

Crawly is the friendly sitemap guide of XML Sitemap Generator. Every guide is written and checked by the team behind our free sitemap tools.

Related articles

Sitemap Guides

Sitemap Size Limit: 50,000 URLs and 50 MB Explained

23 Nov 2026 · 5 min read
Technical SEO

Non-Canonical URLs in Your Sitemap: Why They Matter and How to Fix Them

23 Nov 2026 · 4 min read
Sitemap Guides

Mobile Sitemaps: Do You Still Need One?

23 Nov 2026 · 4 min read