Take an eight-language B2B catalogue with 3,000 product pages: hreflang tags embedded in the HTML add nine lines to every page and more than 200,000 extra lines across the site. In the projects we see, that bloat forces a full template redeploy every time a language is added. Implementing hreflang via XML sitemaps solves exactly that: it lifts the language relationships out of the HTML and lets you manage them centrally in one file. This guide walks an exporter's technical team through setting up sitemap-based hreflang correctly in 2026.
Key Takeaways
- The sitemap method keeps large multilingual sites lean and lets you manage hreflang from one place; when you have no template access to the CMS, it is often the only option.
- Every URL entry must list all language alternates, including itself, as
xhtml:linklines; one-way relationships are invalid. - URLs must be absolute, match the canonical exactly and include only indexable pages.
- Splitting into language- or section-based files under a sitemap index solves both the 50,000 URL / 50 MB limit and the maintenance burden.
- Validation happens in three stages: XML syntax check, Search Console submission, then URL Inspection and report monitoring.
Why Put hreflang in the Sitemap Instead of the HTML?
Google accepts three hreflang methods: the HTML <link> tag, the HTTP header and the XML sitemap. For ranking they are equivalent; the difference is upkeep. In our experience, three situations tip the decision towards the sitemap:
- HTML bloat: On sites with six or more languages, every page's
<head>gains seven to ten lines. Across thousands of pages that is a small but measurable cost to crawl budget and page weight. - Managing large sites: When a new language is added or a country version is retired, you change one sitemap generation rule rather than the HTML template.
- No CMS access: Where you cannot touch the
<head>on an enterprise or distributor-managed platform, a sitemap file still delivers the language relationships to Google.
If your site is small (say three languages and 60 pages), the HTML method has fewer moving parts; the sitemap approach pays off most as scale grows. If you have not yet settled on a URL architecture (subdirectory, subdomain or ccTLD), read our URL structure guide first; the sitemap design follows from that decision.
The xhtml Namespace and Syntax: A Complete Example
In the root <urlset> element, declare the xhtml namespace alongside the standard sitemap namespace. In each <url> block, the alternates go directly beneath <loc>. Below is a single URL entry for the Turkish, English and German versions of a page from an agricultural machinery manufacturer in Konya:
<?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://www.examplemachinery.com/tr/urunler/balya-makinesi/</loc>
<xhtml:link rel="alternate" hreflang="tr" href="https://www.examplemachinery.com/tr/urunler/balya-makinesi/" />
<xhtml:link rel="alternate" hreflang="en" href="https://www.examplemachinery.com/en/products/baler-machine/" />
<xhtml:link rel="alternate" hreflang="de" href="https://www.examplemachinery.com/de/produkte/ballenpresse/" />
<xhtml:link rel="alternate" hreflang="x-default" href="https://www.examplemachinery.com/en/products/baler-machine/" />
</url>
</urlset>
The critical points in this block are:
- Self-reference is mandatory: The Turkish page's entry includes an
hreflang="tr"line pointing back to itself. Leave it out and the cluster is incomplete. - A separate entry for every alternate: The same four lines are repeated inside the English and German pages' own
<url>blocks. So a three-language page produces 3 entries × 4 alternate lines; only then is the reciprocal (return link) check satisfied. - x-default: The fallback for users with no matching language, usually English or a language selector page. For choosing it correctly, read the x-default setup guide we published on Day 1.
- Language-region codes: Region codes such as
en-GBmust follow ISO 639-1 (language) + ISO 3166-1 Alpha-2 (country); invalid codes likeen-UKare silently ignored.
Absolute URLs, Canonicals and Sitemap Index Rules
Sitemap-based hreflang has a high blast radius: if a single generation rule is wrong, thousands of URLs break at once. The table below summarises the rules we apply in projects:
| Rule | Correct | Wrong | Why it matters |
|---|---|---|---|
| URL format | https://www.site.com/de/seite/ | /de/seite/ | The sitemap protocol accepts only absolute URLs; relative ones are skipped entirely. |
| Canonical match | hreflang href = the page's canonical | Parameterised or redirecting URL | If the canonical points elsewhere, Google drops that address from the cluster. |
| Protocol / host | One consistent form (https + www or non-www) | Mixed http/https, www variations | Each variant is a separate URL to Google; return links fail to match. |
| Page status | Returns 200, indexable | noindex, 301, 404 | Pages that should not be in the sitemap should not be hreflang alternates either. |
| File size | ≤ 50,000 URLs, ≤ 50 MB | One giant file | hreflang lines inflate files 4-10x; split with an index. |
The sitemap index approach is standard on sites with four or more languages. A root sitemap.xml index sits above language-based files (sitemap-tr.xml, sitemap-en.xml, sitemap-de.xml) or section-based ones (sitemap-products.xml, sitemap-blog.xml). Alternates may point to URLs that live in different sitemap files, because Google evaluates all submitted sitemaps together; each URL's own entry, however, must appear in exactly one file.
Using HTML and Sitemap Together: The Conflict Risk
Some teams use both the HTML tag and the sitemap "to be safe". That is valid on one condition: both sources must produce identical data. A typical case: an HTML template set up in 2024 and a sitemap generated by a new plugin in 2026, where only one includes the French version. Faced with conflicting signals, Google tends to weaken the whole cluster rather than pick a winner. We covered how these inconsistencies surface in Search Console and how to clean them up in our hreflang errors guide.
Our recommendation: pick one source. If you must maintain both, generate them from the same data source (the same database table or translation mapping file) and run an automated comparison test on every deployment.
Automated Generation in Next.js and Static Builds
Most modern exporter websites are built with Next.js, Astro or a similar framework. Without going into code, a process that works looks like this:
- Single source of truth: The mapping between language versions of each piece of content (TR slug ↔ EN slug ↔ DE slug) lives in one table or in the content metadata. If no translation exists, no line is generated for that language.
- Generation at build or request time: The sitemap is produced from that mapping table, either during the build or per request with caching; adding a product or blog post requires no manual step.
- Filtering: Noindex pages, drafts, redirects and pages whose canonical points elsewhere are excluded automatically.
- Splitting: Once the URL count crosses a threshold, the generation logic automatically produces a sitemap index plus child files.
- Post-deploy testing: On every release the sitemap is XML-validated and a return-link check runs on a random sample of 20-30 URLs.
On a project with a home textiles manufacturer from Denizli, roughly 30% of the German sitemap listed seasonal products that were no longer live. Within two months of enabling automatic filtering, the "submitted URL not found" warnings in Search Console dropped to zero and DE impressions recovered noticeably.
Submitting to Search Console and Validating
Once the sitemap is ready, validation proceeds in three stages:
- Syntax check: Before publishing, test the file with our free sitemap validator tool. Missing namespaces, unclosed tags and relative URLs are caught here.
- Submission: Submit the index file under Sitemaps in Search Console; child sitemaps are discovered automatically. If you use different hosts (.com.tr and .de, say), every property must be verified in the same account or cross-host alternates are rejected. Our Search Console guide covers the setup in detail.
- Monitoring: After a few weeks, inspect any page in the URL Inspection tool; the "Google-selected canonical" field and alternate information show the cluster has been read. Watch the international targeting report for "no return tag" and "unknown language code" errors. The final proof is in the Performance report: apply a country filter and confirm the correct language versions are collecting clicks.
Common Mistakes and a Testing Checklist
The mistakes we run into most often, plus a pre-launch checklist:
- Relative URLs: Writing
href="/de/seite/"; the alternate is ignored entirely. - Missing return link: The TR entry points to DE but the DE entry does not point back to TR; the cluster is invalid.
- Missing self-reference: The entry lists only the "other" languages.
- Exceeding 50,000 URLs / 50 MB: Google rejects the file; use an index.
- Listing noindex pages: Conflicting signals that also weaken the other languages in the cluster.
- Unverified cross-host alternates: Alternates pointing to a domain not verified in Search Console are treated as untrusted.
- Canonical conflict: The URL listed in hreflang has a canonical pointing to a different address.
- Invalid codes: Formats such as
en-UKortr-TR-tr.
Pre-launch checklist: (1) Is the xhtml namespace declared in urlset? (2) Does every URL list itself? (3) Are all hrefs absolute, https and identical to the canonical? (4) Is x-default single and consistent in every cluster? (5) No noindex/301/404 pages? (6) File size and URL count under the limits? (7) Validator clean? (8) Submitted to Search Console with all hosts verified?
Conclusion: The Next Step Towards a Scalable Multilingual Site
Implementing hreflang via XML sitemaps is the cleanest way to keep a growing multilingual B2B site under control: the HTML stays lean, adding a language becomes a rule change, and errors surface in one file. Your next step: download your current sitemap, run it through the validator, and manually check return links and canonicals for five random product pages. If the result is not clean, or you are planning a multilingual rebuild, take a look at our exporter-focused international SEO service or request a technical audit quote for your existing setup.




No comments yet
Leave a Comment