The Complete Hreflang Guide: Implementation, Codes and Debugging

Implement hreflang with HTML, headers or sitemaps: cluster rules, codes, x-default, canonicals and a debugging checklist.

The Complete Hreflang Guide: reciprocal arrows between locale URL pills and an x-default pill on a white grid

Hreflang is one of the most important—and most frequently broken—signals in international SEO. Teams add annotations hoping Google will “send users to the right language,” then discover months later that return links are missing, region codes are invalid, or canonical tags contradict the cluster.

This guide is a practical implementation reference. It explains what hreflang does (and does not do), when you need it, the three supported methods, the cluster rules that actually matter, how codes and x-default work, how to align hreflang with canonicals, and how to debug the mistakes that cause annotations to be ignored. Claims stay grounded in Google’s documentation—no ranking guarantees.

Questions this guide answers

  • What is hreflang and what problem does it solve?
  • When should a site implement hreflang?
  • What are the three supported implementation methods, and how should teams choose among them?
  • What rules must every hreflang cluster follow?
  • How do language and region codes work, including x-default?
  • How should hreflang interact with canonical tags?
  • What are the most common hreflang mistakes and how do you debug them?
  • Does hreflang detect page language or replace translation?

Quick answer: what hreflang does

Hreflang tells Google about language or region variants of a page so Search can point users to the most appropriate version. Explicit indication is recommended even though Google may still find some alternate language versions without annotations.

Hreflang does not:

  • detect the language of a page (Google uses algorithms on visible content, not hreflang or the HTML lang attribute)
  • replace translation or localization work
  • guarantee rankings in any country or language

Treat it as a relationship map between alternate URLs, not as a language detector or a ranking lever.

When you need hreflang

Google recommends alternate-page annotations in situations such as:

  • template-only translation where the main content stays in one language
  • small regional variations of the same language (for example currency, contact details, or legal copy)
  • fully translated multi-language content

Localized versions are only treated as duplicates when the main content remains untranslated. That distinction matters: a lightly localized same-language country page can still be a valid alternate; a thin chrome-only “translation” should not be treated as a full language version.

You typically need hreflang when users in different languages or countries should land on different crawlable URLs for the same intent. You may not need it for a single-language, single-market site—or when you deliberately publish one global URL and accept one experience for everyone.

Folder names and subdomain labels (/de/, de.example.com) are not enough by themselves. Google does not use those path or subdomain codes to determine target audience unless you map audience explicitly—hreflang is the usual way to do that.

Core cluster rules

Every correct hreflang setup is a cluster: a set of URLs that declare each other as alternates. Google’s rules are strict enough that partial clusters often fail silently.

Core cluster rules
RuleWhat to doWhy it matters
Self-referenceEach version lists itself and all other versionsIncomplete self-maps break the cluster
ReciprocityIf A points to B, B must point back to ANon-reciprocal pairs are ignored
Absolute URLsUse fully qualified URLs including http/httpsRelative URLs are not valid alternates
Cross-domain OKAlternates need not share a domainUseful for ccTLD programs
One methodPrefer one of HTML, HTTP headers, or sitemapsTriple maintenance creates drift

If a complete bidirectional set is hard to maintain at scale, Google still processes pairs that point to each other—but new languages should be bidirectionally linked to the originating or dominant language(s). Do not treat “partially reciprocal” as a long-term strategy; treat it as a migration hazard.

Language and region codes

Hreflang values use ISO 639-1 language codes, optionally combined with ISO 3166-1 Alpha 2 region codes.

Language and region codes
PatternExampleMeaning
Language onlyen, fr, deLanguage without a specific country
Language + regionen-US, en-GB, fr-CALanguage for a specific country
Script variantzh-Hans, zh-HantSimplified vs Traditional Chinese (ISO 15924)
Script + regionzh-Hans-USScript plus country when needed
Fallbackx-defaultNo other language/region match

Invalid or ineffective patterns to avoid:

  • region alone (US) — not valid
  • treating EU, UN, or UK as region codes that affect Google Search — they do not
  • unsupported forms such as es-419

When several regional URLs share a language (for example en-IE, en-CA, en-AU), also provide a generic language catch-all such as en for geographically unspecified users of that language.

Use x-default for a fallback when no other language or region matches—especially for language selectors or auto-redirecting home pages. x-default is not “English”; it is “no better match.”

Place alternate link tags in a well-formed <head>. Do not combine hreflang with other alternate-representation attributes such as media on the same link tag.

Example for a small cluster (en-US, en-GB, fr, x-default):

<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="fr" href="https://example.com/fr/pricing" />
<link rel="alternate" hreflang="x-default" href="https://example.com/pricing" />

Every page in the cluster needs the same set of annotations (including its own URL). Generating tags from a shared locale matrix in your CMS or static site generator is safer than hand-editing pages.

Implementation method 2: HTTP headers

For non-HTML files—or when your edge/CDN stack prefers header injection—Google supports the HTTP Link header with the same semantics:

Link: <https://example.com/en-us/pricing>; rel="alternate"; hreflang="en-US",
      <https://example.com/en-gb/pricing>; rel="alternate"; hreflang="en-GB",
      <https://example.com/fr/pricing>; rel="alternate"; hreflang="fr",
      <https://example.com/pricing>; rel="alternate"; hreflang="x-default"

Headers are useful when HTML <head> injection is awkward, but they are harder for content teams to inspect. If you use headers, document the generating service and include header checks in QA.

Implementation method 3: XML sitemaps

Sitemaps can declare alternate language or locale versions with xhtml:link entries. Each URL entry should list every alternate, including itself.

<?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-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="fr" href="https://example.com/fr/pricing"/>
    <xhtml:link rel="alternate" hreflang="x-default" href="https://example.com/pricing"/>
  </url>
  <!-- Repeat a <url> block for each alternate, each listing the full set -->
</urlset>

Sitemap generation scales well for large catalogs, but only if your pipeline regenerates the full reciprocal set when a locale is added or removed.

Choosing one method

From Google’s perspective, HTML tags, HTTP headers, and sitemaps are equivalent. Using all three at once does not improve Search outcomes; it multiplies drift risk.

Choosing one method
MethodBest when…Watch out for…
HTML <link>Page templates already control <head>Template bugs that omit self-references
HTTP LinkPDFs or edge-controlled responsesOpaque ops ownership; hard for editors to verify
XML sitemapsLarge URL sets, centralized locale matrixStale sitemap after locale launches

Pick one source of truth. Many engineering teams prefer sitemaps for scale and HTML for marketing sites with few locales. Either is fine if reciprocity stays correct.

Hreflang and canonical tags

Hreflang and canonicals solve different problems. Hreflang maps language or region alternates. Canonicals declare the preferred URL among near-duplicates.

Rules that keep the two aligned:

  1. When using hreflang, specify a canonical page in the same language, or the best possible substitute language if a same-language canonical does not exist.
  2. Do not overload a single rel="canonical" link with hreflang, lang, media, or type attributes—those combined annotations are not used for canonicalization. Keep alternate annotations separate.
  3. For canonicalization, Google prefers URLs that participate in reciprocal hreflang clusters over otherwise similar URLs left out of the cluster.
  4. For similar or duplicate same-language content on multi-regional URLs, choose a preferred version and use rel="canonical" together with hreflang.

Practical pattern for same-language country pages: each country URL can be an hreflang alternate (en-US, en-CA), while each page’s canonical points to itself (or to a deliberately chosen preferred URL if you truly want consolidation). Do not point every country’s canonical at a single global English URL while also expecting each country URL to remain the served alternate—those signals fight each other.

Worked example: language + region cluster

Imagine a pricing page with:

  • United States English: https://example.com/en-us/pricing → en-US
  • United Kingdom English: https://example.com/en-gb/pricing → en-GB
  • Global French: https://example.com/fr/pricing → fr
  • Language selector / fallback: https://example.com/pricing → x-default
  • Optional catch-all English: https://example.com/en/pricing → en (recommended when regional English variants exist)

On every URL above, emit the full reciprocal set. On the US page, the HTML would include self-reference plus GB, FR, x-default, and the English catch-all if you publish one.

Ownership tip: store the matrix as data (locale → url), generate annotations from that matrix, and fail CI if a locale is missing a return link. Manual tag editing does not survive a third language launch.

Common mistakes and debugging

Google explicitly calls out common mistakes: missing return links, incorrect language codes, and incorrect region codes. In practice, most production failures look like one of these:

Common mistakes and debugging
SymptomLikely causeFix
Annotations ignoredNon-reciprocal pairsRebuild clusters so every URL points both ways
Wrong country version shownInvalid or ambiguous codes (UK, region-only)Use valid ISO language and language-region codes
Cluster incomplete after launchNew locale added only on one templateRegenerate full set from the matrix
Conflicting indexingCanonical points across languages carelesslySame-language canonical preference
“We added /de/ so we’re done”Path label without hreflangMap audience explicitly with annotations
Triple-method driftHTML + headers + sitemap disagreeChoose one method

Debug sequence:

  1. Export the intended locale × URL matrix.
  2. For a sample URL, fetch rendered HTML headers/sitemap entries and list every hreflang target.
  3. Confirm the page includes itself.
  4. Confirm each target returns the same set (or at least a reciprocal pair during migration).
  5. Validate codes against ISO lists; reject UK/EU/UN as region codes.
  6. Confirm canonical language alignment.
  7. Re-check after the next locale launch—not only at initial go-live.

Third-party validators can help, but Google does not maintain them. Prefer Google’s documentation plus your own reciprocity tests over any single tool’s green checkmark.

Implementation checklist

Hreflang and AI answer engines

Hreflang is a Google Search annotation (also relevant to other search engines that honor alternate-page signals). It tells crawlers how language and region versions relate. It does not guarantee that ChatGPT, Claude, Gemini, Perplexity, Copilot, or Google AI Overviews will pick the “correct” language version in an answer.

What still helps answer engines: each language version is crawlable, indexable, fully localized in main content, and consistent about the same entity. Those qualities support discovery and source selection even when hreflang itself is ignored by an assistant. Do not apply Google hreflang debugging steps as if they were universal AI ranking controls.

Dedicated multilingual SEO guides for Google and Bing remain the place for engine-specific implementation depth.

Optimizing for Google Search (hreflang)

Google Search is the primary consumer of hreflang annotations. Implement reciprocal clusters, valid codes, and aligned canonicals exactly as Google documents. Debug with Search Console international reports where available.

Optimizing for Bing (alternate pages)

Bing may honor alternate-page signals differently from Google. Keep locale URLs crawlable and verify coverage in Bing Webmaster Tools rather than assuming Google’s hreflang cluster behavior maps 1:1.

Platform guide: ChatGPT

Hreflang does not force ChatGPT to pick a language version. What helps is a crawlable, fully localized URL that can be cited or used as a source when grounding applies. Treat language selection in answers as uncertain.

Platform guide: Gemini

Gemini and Google AI experiences still benefit from indexable language versions. Do not treat hreflang as an AI Overview language switch—keep people-first localized pages that Google can crawl.

Platform guide: Google AI Overviews

AI Overviews may link supporting pages. Hreflang alone does not assign overview language. Localized, indexable pages remain the practical prerequisite; inclusion is not guaranteed.

Where GlotEO fits

Correct hreflang is an engineering and content-ops problem: the matrix must stay aligned with research, briefs and published language versions as markets expand. GlotEO’s multilingual SEO platform can support that editorial workflow for multilingual programs—without replacing the annotation rules above.

Teams that need editorial control across locales can use GlotEO’s multilingual SEO solution, then compare GlotEO pricing and plans.

For strategy context on language versus country targeting, see International SEO vs Multilingual SEO. URL architecture and translation-versus-localization decisions should stay aligned with the annotation rules above.

Citations