Multilingual Sitemap: How to Implement Hreflang in XML
For multilingual and multi-regional websites, XML sitemaps can carry hreflang annotations that tell Google which language and regional variants exist for each page. This is one of three methods to implement hreflang (the others being HTML link tags and HTTP headers), and it is often the preferred approach for large sites because it centralizes all hreflang declarations in one place without modifying individual page HTML.
What Is Hreflang and Why Use It in Sitemaps?
The hreflang attribute tells Google which language and optionally which geographic region a URL targets. Without it, Google may serve the wrong language variant to users in different countries, or may treat your language variants as duplicate content. The sitemap method is particularly useful for large multilingual sites (thousands of pages) because adding hreflang link tags to every HTML page head is complex and error-prone at scale, while the sitemap approach consolidates all declarations into a single file that can be validated independently.
The Sitemap Hreflang XML Syntax
Hreflang in sitemaps uses the XHTML namespace extension. Each URL entry lists all its language variants including itself. Every variant must point back to all other variants — this reciprocal linking is required:
<?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/page/</loc>
<xhtml:link rel="alternate" hreflang="en"
href="https://example.com/page/"/>
<xhtml:link rel="alternate" hreflang="de"
href="https://example.com/de/seite/"/>
<xhtml:link rel="alternate" hreflang="fr"
href="https://example.com/fr/page/"/>
<xhtml:link rel="alternate" hreflang="x-default"
href="https://example.com/page/"/>
</url>
<url>
<loc>https://example.com/de/seite/</loc>
<xhtml:link rel="alternate" hreflang="en"
href="https://example.com/page/"/>
<xhtml:link rel="alternate" hreflang="de"
href="https://example.com/de/seite/"/>
<xhtml:link rel="alternate" hreflang="fr"
href="https://example.com/fr/page/"/>
<xhtml:link rel="alternate" hreflang="x-default"
href="https://example.com/page/"/>
</url>
</urlset>Note the required xmlns:xhtml namespace declaration on the root urlset element. Without it, the xhtml:link tags will not be recognized.
Hreflang Language and Region Codes
Hreflang values use ISO 639-1 language codes (two lowercase letters) optionally combined with ISO 3166-1 Alpha-2 region codes (two uppercase letters). Examples: en (English), en-US (English for the US), en-GB (English for the UK), de (German), de-AT (German for Austria), pt-BR (Portuguese for Brazil). The special value x-default marks the fallback URL for users whose language doesn't match any declared variant — typically the international or English version.
The Reciprocal Linking Requirement
Google requires that every URL in a hreflang group points to all other URLs in that group, including itself. If page A declares page B as its German variant, page B must also declare page A as its English variant. Incomplete reciprocal linking is the most common hreflang error — Google ignores hreflang annotations from pages that are not confirmed by their counterparts. When using the sitemap method, you must list all variants in every URL's entry, making this requirement explicit and easier to enforce programmatically.
Sitemap Hreflang vs. HTML Hreflang Tags
Both methods work equally well from Google's perspective. The sitemap method is preferred when: you have thousands of pages (modifying every page's HTML is impractical), your site is rendered client-side (HTML head tags may not be crawled reliably), or you want a single source of truth for all hreflang declarations. The HTML method is simpler for small sites and provides inline confirmation that each page is aware of its variants. Many large sites use both methods as redundancy — Google will use either one.
Common Hreflang Sitemap Errors
The most frequent hreflang sitemap errors are: missing the XHTML namespace declaration, using incorrect language or region codes (e.g., EN instead of en), omitting the self-referencing annotation (a URL must list itself in its own hreflang group), pointing to URLs that return non-200 status codes, inconsistent URL formats (trailing slash vs. no trailing slash), and missing the x-default annotation. SitemapFixer detects all of these and reports them with specific fix recommendations.
Scale Considerations for Multilingual Sitemaps
Each hreflang annotation adds one xhtml:link element per URL per variant. A site with 10,000 pages in 5 languages will have 50,000 URL entries and 250,000 xhtml:link elements. This grows quickly and can push individual sitemap files close to the 50 MB limit even before the 50,000 URL count limit. For large multilingual sites, use a sitemap index to split by language or by content type, and monitor file sizes carefully as the site grows.
Validating Your Multilingual Sitemap
After implementing hreflang in your sitemap, validate it with a dedicated checker that understands the XHTML namespace extension. Basic XML validators won't flag hreflang-specific errors like missing reciprocal links or incorrect language codes. Google Search Console's International Targeting report will show hreflang errors detected from your sitemap once Googlebot has processed it. Combine GSC reports with a pre-submission validator to catch errors before they reach production.