Hreflang Generator
Free hreflang generator and validator: build reciprocal HTML link tags and XML sitemap xhtml:link blocks from one table (or CSV import), toggle x-default, and audit pasted BCP-47 tags locally — no signup.
Add at least two language/region × URL rows (or click Load sample) to generate reciprocal HTML <link> tags and XML sitemap alternates.
How Google actually processes hreflang (3 implementation methods compared)
Per Google Search Central's localized versions specification, hreflang is a signal, not a directive, telling search engines which localized URL in an equivalent cluster to swap into SERPs for a user's language and country. Google supports three technically equivalent delivery channels — choosing the right one depends on locale count and file type:
| Method | Best fit | Pros | Operational watch-outs |
|---|---|---|---|
HTML <link rel="alternate"> | Sites with 2–8 locales and template-level control | Easy to inspect via View Source / DevTools; updates atomically with each page deploy | Adds N link elements to every page's <head>; 30 locales add ~4 KB of repeated markup per HTML response |
XML Sitemap <xhtml:link> | Multi-region e-commerce & SaaS with 10+ locales or cross-domain ccTLDs | Zero HTML bloat; centralizes reciprocity in one generated artifact | Requires xmlns:xhtml="http://www.w3.org/1999/xhtml"; every localized URL must repeat the full cluster (validate with our sitemap checker) |
HTTP Link: response header | Non-HTML files (localized PDFs, whitepapers, spreadsheets) | Only valid way to pair non-HTML assets without an HTML <head> | Adds bytes to every HTTP header response; harder for non-engineers to audit |
Never ship conflicting sets across two methods. If your CMS injects HTML tags while a build script outputs a different XML sitemap cluster, Google receives contradictory annotations and may drop both.
The canonical + hreflang interaction matrix (the #1 production bug)
More hreflang deployments fail from conflicting rel="canonical" tags than from bad language codes. Canonicalization tells Google “these pages are duplicates, index only one”; hreflang tells Google “keep each localized URL indexed and swap the right one per country.” Check your template against these four states:
Setup on localized page (e.g. /en-gb/pricing/) | Status | What happens in Google Search |
|---|---|---|
Self-referencing canonical (/en-gb/pricing/) + reciprocal hreflang set | Valid | Google indexes each locale cleanly and serves /en-gb/ to UK searchers and /en-us/ to US searchers |
Canonical points to master (/en-us/pricing/) + hreflang lists /en-gb/ | Broken | Canonical overrides hreflang; /en-gb/ drops out of the index and the UK annotation is ignored |
Canonical has trailing slash (/de/pricing/), hreflang omits it (/de/pricing) | Broken | String mismatch breaks exact-URL reciprocity (and often triggers a 301 redirect hop inside hreflang) |
Page has noindex or is blocked in robots.txt while listed in hreflang | Broken | Googlebot cannot crawl or verify the return link, invalidating the pair |
Copy-paste production templates (HTML, XML sitemap, and PDF HTTP header)
Notice two details every working cluster shares: every URL is absolute (including https:// and exact trailing slash), and every sibling carries its own self-referencing canonical alongside the identical alternate block:
1. HTML <head> block (for /en-gb/pricing/)
<!-- Placed identically inside <head> on ALL three URLs -->
<link rel="canonical" href="https://example.com/en-gb/pricing/" /> <!-- self-referencing per URL -->
<link rel="alternate" hreflang="en-US" href="https://example.com/en-us/pricing/" />
<link rel="alternate" hreflang="en-GB" href="https://example.com/en-gb/pricing/" />
<link rel="alternate" hreflang="de" href="https://example.com/de/pricing/" />
<link rel="alternate" hreflang="x-default" href="https://example.com/en-us/pricing/" />2. XML sitemap block
<?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">
<!-- Every localized URL gets its own <url> block repeating the full sibling cluster -->
<url>
<loc>https://example.com/en-us/pricing/</loc>
<xhtml:link rel="alternate" hreflang="en-US" href="https://example.com/en-us/pricing/" />
<xhtml:link rel="alternate" hreflang="en-GB" href="https://example.com/en-gb/pricing/" />
<xhtml:link rel="alternate" hreflang="de" href="https://example.com/de/pricing/" />
<xhtml:link rel="alternate" hreflang="x-default" href="https://example.com/en-us/pricing/" />
</url>
<url>
<loc>https://example.com/en-gb/pricing/</loc>
<xhtml:link rel="alternate" hreflang="en-US" href="https://example.com/en-us/pricing/" />
<xhtml:link rel="alternate" hreflang="en-GB" href="https://example.com/en-gb/pricing/" />
<xhtml:link rel="alternate" hreflang="de" href="https://example.com/de/pricing/" />
<xhtml:link rel="alternate" hreflang="x-default" href="https://example.com/en-us/pricing/" />
</url>
</urlset>3. HTTP Link header (for localized PDFs)
Link: <https://example.com/en-us/handbook.pdf>; rel="alternate"; hreflang="en-US",
<https://example.com/de/handbuch.pdf>; rel="alternate"; hreflang="de",
<https://example.com/en-us/handbook.pdf>; rel="alternate"; hreflang="x-default"BCP-47 language, script & region cheat sheet (high-frequency bugs)
Google follows BCP 47: ISO 639-1 language code first, optional ISO 15924 script code second, and optional ISO 3166-1 alpha-2 (or UN M.49) region code last. Region-only tags (such as hreflang="US") are always invalid.
| Target audience | Correct code | Common bug (ignored by Google) | Why it fails |
|---|---|---|---|
| English — United Kingdom | en-GB | en-UK | ISO 3166-1 alpha-2 uses GB, not UK |
| Japanese (all regions / Japan) | ja or ja-JP | jp or jp-JP | jp is the country code; the ISO 639-1 language code is ja |
| Simplified vs Traditional Chinese | zh-Hans / zh-Hant (or zh-CN / zh-TW) | cn or zh-CHS | cn is a country; legacy CHS/CHT are non-standard |
| Spanish — Latin America | es-419 (or es) | es-LA | LA is Laos in ISO 3166-1; Latin America uses UN M.49 code 419 |
| Portuguese — Brazil vs Portugal | pt-BR / pt-PT | br | br is Breton (language), not Brazilian Portuguese |
| Unmatched global fallback | x-default | en-x-default / default | Reserved literal token; takes no language prefix |
7-point pre-launch hreflang audit checklist
- 100% reciprocity: confirm URL A lists URL B and URL B lists URL A, plus every page lists itself.
- Exact canonical match: every
hrefin the block matches the target page's ownrel="canonical"character-for-character (protocol,www, trailing slash). - HTTP 200 destinations only: run sample URLs through our redirect checker so no hreflang tag points at a 301/302 chain or 404.
- Zero geo-IP redirects blocking Googlebot: test regional URLs from a US IP with a Googlebot User-Agent to verify you serve
200 OKrather than redirecting back to/en-us/. - Valid BCP-47 syntax: paste your generated or live markup into Check existing tags above to catch
en-UK, relative URLs, or duplicate locale codes before shipping. - No noindex / robots.txt conflicts: verify localized URLs return
200 OKwithoutnoindexheaders and are not disallowed inrobots.txt. - Monitor country splits in Search Console: after rollout, filter Search Console by Country and Page to confirm UK impressions shift onto
/en-gb/and German impressions onto/de/.
Explore more free SEO tools: validate localized snippets in the meta description length checker, inspect XML files in the XML sitemap checker, benchmark localized rank-band click rates in the organic CTR calculator, or read how serpvi works.
Related tools
- Sitemap Checker — Free sitemap checker: find sitemap.xml, validate urlset or sitemap index, count URLs, and flag missing lastmod or malformed XML — no signup.
- Redirect Checker — Free redirect checker: enter a URL to see every hop, status code, and final destination. Detect loops and compare 301 vs 302 — no signup.
- Meta Description Length Checker — Free meta description and title length checker with SERP pixel width and desktop/mobile truncation previews. Catch cuts early — no signup.
- Organic CTR calculator — Work out CTR from clicks and impressions, then compare every page with your own site's CTR at the same rank. Upload a Search Console export; it runs in your browser.
Questions
- Do I need hreflang on every page variant, including a self-referencing tag?
- Yes. Google Search Central requires every localized URL in a cluster to list itself (self-referencing hreflang) alongside every translated or regional sibling. If page A points to page B without page B pointing back to page A, Google can ignore the entire pair to prevent external sites from hijacking another site's localization signals.
- How should canonical tags work alongside hreflang?
- Every localized URL must carry a self-referencing rel="canonical" pointing to its own absolute 200 OK URL — never cross-canonicalize regional pages (like en-GB or fr-CA) to a single en-US master page. Cross-canonicalization tells Google the regional URL is a duplicate to consolidate, which directly contradicts hreflang and drops the localized page from the cluster.
- Is a country code required, or is a language code enough?
- Language alone is valid and often better — hreflang="de" serves German speakers worldwide without fragmenting Germany, Austria, and Switzerland. Add an ISO 3166-1 alpha-2 region subtag (such as en-GB, en-AU, or de-CH) only when you serve meaningfully different prices, currencies, shipping rules, or regional wording on distinct URLs.
- When should I use hreflang="x-default"?
- Use x-default for your country/language selector page or your global default landing page that visitors should see when none of your declared language-region codes match their search locale. Never append a language code to x-default, and you may point both a specific code (like en) and x-default to the same global URL.
- HTML <link> tags vs XML sitemap hreflang vs HTTP headers — which is best?
- Google treats all three identically. HTML <head> link tags are simplest to debug on small sites (under ~5 locales); XML sitemap xhtml:link entries avoid bloating HTML weight when you maintain 10–50 locales across thousands of URLs; HTTP Link headers are specifically for non-HTML files such as localized PDFs. Pick one primary method and avoid shipping conflicting blocks across HTML and XML.
- Can CDN or geo-IP auto-redirects break hreflang?
- Yes — it is one of the most frequent international SEO failures. Googlebot crawls predominantly from US IP addresses. If your server automatically 302-redirects US IPs away from /de/ or /en-gb/ back to /en-us/, Googlebot can never fetch the return hreflang link on those regional URLs. Let users switch regions via a banner or selector instead of forcing IP redirects.
- Does paste validation check live return links across my website?
- No. Switch to Check existing tags above to validate BCP-47 syntax, duplicate locales, relative URLs, and missing x-default locally in your browser without uploading anything. Confirming live HTTP 200 status and return links across every sibling URL still requires crawling those URLs (or verifying status codes with our redirect checker).