Skip links

Hreflang Implementation: Correct Setup, Examples & Troubleshooting

The hardest part of hreflang implementation is not writing the tag. It is keeping every localized URL, canonical, sitemap entry, and fallback page saying the same thing.

What hreflang implementation is and why it matters

Hreflang is an annotation that tells search engines which URLs are alternate language or regional versions of the same content. Hreflang meaning, in plain English, is simple: map equivalent pages so a user in Canada can be shown the Canadian page, while a user in the UK can be shown the UK page, if those versions exist. Hreflang is used for multilingual and multiregional websites, not for random pages that merely look similar. A language-only value such as en targets English broadly, while a language-region value such as en-ca, en-gb, or fr-ca targets a specific locale. Hreflang can influence which localized URL Google chooses to show, but it does not guarantee a specific SERP outcome. It is a signal about alternates, not a ranking boost and not a replacement for localized content, internal linking, or proper indexability. Hreflang can help search engines understand near-duplicate localized pages, but it is not a duplicate-content cure by itself. If your canonicals, redirects, or indexability rules conflict with the cluster, hreflang usually loses that fight.

When to use hreflang and when not to use it

Use hreflang when you have true alternate versions of the same page for different languages, countries, or both. Good fits include example.com/en-ca/product-a/ and example.com/en-gb/product-a/, where the core page intent is the same and the locale changes. Use language-only codes when the content is meant for all speakers of that language, and use language-country codes when pricing, spelling, inventory, shipping, legal copy, or market targeting changes by country. en is broader than en-ca, and fr is broader than fr-ca. Skip hreflang on single-language, single-region sites that have no alternate locale URLs. If there is only one English version for one market, adding hreflang creates overhead without solving a real problem. Exclude URLs that should not be part of an indexable alternate cluster. In practice, that usually means leaving out noindex pages, redirecting URLs, 404 pages, and URLs canonicalized to a different page, because those URLs are sending a stronger instruction than hreflang. Partially translated pages need judgment before implementing hreflang. If two pages are not true equivalents in purpose, depth, or template coverage, forcing them into one cluster creates bad signals and weak user experience. Plan URL structure before implementing hreflang, because stable clusters are easier to maintain than clusters rebuilt after launch. This matters more as a site grows from a few localized pages to hundreds or thousands of URLs.

Hreflang syntax explained with correct code examples

A valid hreflang tag has three core parts: rel="alternate", an hreflang value, and an absolute href URL. In HTML, it belongs in the <head> of each localized page, or the same relationship can be expressed in XML sitemaps or HTTP headers. Here is a basic hreflang implementation example in HTML for US, UK, and Canada pages, plus a fallback page:
<link rel="alternate" hreflang="en-us" href="https://www.example.com/us/page/" />
<link rel="alternate" hreflang="en-gb" href="https://www.example.com/uk/page/" />
<link rel="alternate" hreflang="en-ca" href="https://www.example.com/ca/page/" />
<link rel="alternate" hreflang="x-default" href="https://www.example.com/language-selector/" />
A language-only cluster looks similar, but without the region segment in the code. For example, en, fr, and es are valid language values when country targeting is unnecessary. Correct formatting uses a language code first and, when needed, a region code second. A common convention is lowercase language and uppercase region in documentation, such as en-CA, but search engines generally process the code value case-insensitively; consistency across your implementation matters more than stylistic casing. This is an incorrect hreflang example:
<link rel="alternate" hreflang="ca" href="https://www.example.com/ca/page/" />
That code is wrong because ca is a language code for Catalan, not a Canada target. If you mean English for Canada, use en-ca; if you mean French for Canada, use fr-ca.

Common hreflang format examples

Target Example code Use case
English, all regions en One English page for all English users
English, Canada en-ca Canadian English page
English, United Kingdom en-gb UK English page
French, Canada fr-ca Canadian French page
Fallback page x-default Selector or generic fallback URL

lang vs hreflang: what is the difference?

The HTML lang attribute declares the language of the page itself, while hreflang maps alternate localized URLs for search engines. One describes page language; the other describes page relationships across a cluster. Neither replaces the other. A localized page can and usually should have both a proper HTML lang attribute and a valid hreflang setup if alternate versions exist.
Attribute Purpose Where it lives Main users Common mistake
lang Declares page content language <html lang="..."> Browsers, assistive tech, some crawlers Assuming it handles international SEO by itself
hreflang Maps alternate locale URLs HTML head, XML sitemap, or HTTP header Search engines Using it without reciprocal alternates or indexable URLs

Choose the right implementation method: HTML, XML sitemap, or HTTP header

The right method depends on file type, scale, and deployment control. HTML head tags fit manageable HTML pages, XML sitemaps fit centralized large-scale management, and HTTP headers fit PDFs or other non-HTML assets. Use HTML head tags when templates are easy to edit and localized pages are rendered server-side in a predictable way. This method is transparent during manual QA, but it can become fragile when multiple templates or plugins inject conflicting tags. Use XML sitemap annotations when you need one central source of truth across hundreds to thousands of URLs. This approach reduces head markup bloat and is easier to automate, but stale exports, namespace mistakes, and mismatched canonicals can break clusters quickly. Use HTTP headers when the file has no HTML head, such as a PDF. This method works well for non-HTML assets, but it needs server or CDN control and careful testing because header directives are easy to miss. Pick one primary method per cluster where possible, then keep the signals consistent. Mixing methods is not inherently wrong, but using different sources of truth for the same URLs increases failure risk.

Quick decision tree

  • Use HTML if your localized pages are standard HTML and template control is simple.
  • Use XML sitemaps if the site is large, multilingual, or maintained centrally.
  • Use HTTP headers if the asset is a PDF or another non-HTML file.
  • Rework architecture first if canonicals, redirects, or URL equivalents are still unstable.

How to implement hreflang in HTML

A developer adding hreflang tags in the HTML head of a localized page.
Implement hreflang in HTML by mapping equivalent localized URLs first, then placing a complete alternate set in the <head> of each page. If page A references page B and C, then B and C should return that relationship with their own matching sets. Start with equivalent URLs only. A product page should map to the same product page in other locales, not to a category page, a homepage, or a loosely related article. Keep each page indexable and normally self-canonical before adding hreflang. A standard pattern is one self-referencing canonical per localized page, plus self-referencing hreflang alongside alternates. Add a self-reference in the hreflang cluster for the current page. That means the Canadian page includes en-ca for itself, not only references to the US and UK versions. Return links matter because alternate mapping is a relationship, not a one-way declaration. If one locale points to another but the second locale does not acknowledge it, the cluster is weaker and may be ignored. Add x-default when you have a selector page or a generic fallback destination. Do not use it as a substitute for real locale URLs that should exist separately. Validate the rendered HTML, not only the template file. JavaScript rendering, plugin conflicts, CDN transformations, and partial template loads can remove or duplicate tags in production. Here is a 3-page HTML cluster example with self-references:
<!-- On https://www.example.com/ca/page/ -->
<link rel="alternate" hreflang="en-ca" href="https://www.example.com/ca/page/" />
<link rel="alternate" hreflang="en-us" href="https://www.example.com/us/page/" />
<link rel="alternate" hreflang="en-gb" href="https://www.example.com/uk/page/" />
<link rel="alternate" hreflang="x-default" href="https://www.example.com/language-selector/" />

How to implement hreflang in XML sitemaps

A specialist reviewing hreflang entries in an XML sitemap.
XML sitemaps are usually the cleanest way to scale correct hreflang implementation across large sites. Instead of placing tags in every HTML head, you define alternate relationships in one centralized export. A sitemap entry lists one canonical URL entry and nests all alternates for that page inside it. Every localized equivalent should appear in the cluster with its own hreflang value. Here is a compact sitemap example:
<?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.example.com/ca/page/</loc>
    <xhtml:link rel="alternate" hreflang="en-ca" href="https://www.example.com/ca/page/" />
    <xhtml:link rel="alternate" hreflang="en-us" href="https://www.example.com/us/page/" />
    <xhtml:link rel="alternate" hreflang="en-gb" href="https://www.example.com/uk/page/" />
    <xhtml:link rel="alternate" hreflang="x-default" href="https://www.example.com/language-selector/" />
  </url>
</urlset>
This method reduces template complexity and helps teams manage hundreds to thousands of URLs from one system. It is especially useful for enterprise sites, marketplaces, and multi-location architectures with repeatable page types. The common sitemap failure modes are mechanical, not strategic. Wrong namespace declarations, missing alternates, stale URL exports, orphaned localized pages, and clusters that point at non-canonical URLs are the usual reasons a sitemap-based setup fails.

How to implement hreflang via HTTP headers for PDFs and non-HTML files

A response header inspection showing hreflang for a PDF file.
HTTP headers are the right hreflang implementation method for files that do not have an HTML head, including PDFs. If the asset is indexable and has localized equivalents, you can express the alternate relationship at the response-header level. A header example looks like this:
Link: <https://www.example.com/ca/brochure.pdf>; rel="alternate"; hreflang="en-ca",
      <https://www.example.com/us/brochure.pdf>; rel="alternate"; hreflang="en-us",
      <https://www.example.com/uk/brochure.pdf>; rel="alternate"; hreflang="en-gb"
This setup is useful for brochures, white papers, manuals, and similar downloadable assets. It usually requires coordination between the application layer, server configuration, or CDN rules. Header-level hreflang needs stronger QA than HTML because you cannot spot it by viewing page source. Use response-header inspection in your crawler, browser dev tools, or command-line checks to confirm the directive is live.

What x-default is and how it should behave

x-default is the fallback hreflang value for users whose language-region pair is not otherwise targeted in the cluster. It is commonly used for a global homepage, a language selector page, or a generic market-selection URL. Use x-default when the page is a real fallback destination, not as a shortcut around missing locale pages. If your US, UK, and Canada pages exist, those locale URLs still need their own explicit hreflang values. Language selector pages are one of the best uses for x-default. A selector lets users and crawlers reach alternate markets without forcing a country guess that may be wrong. Aggressive auto-redirects can undermine hreflang discovery and user control. If a selector page instantly redirects every visitor based on IP or browser language, search engines and users may struggle to access the alternate URLs you are trying to advertise. A better pattern is a visible selector with optional suggestions, not a hard wall. Let users switch locale manually and make alternate paths crawlable.

URL structure and hreflang: domains, subdomains, and subfolders

Hreflang can be used across different domains, subdomains, and subfolders as long as the URLs are true alternates of each other. The annotation is about equivalence, not folder style. ccTLDs such as example.ca and example.co.uk create strong market separation, but they increase governance and implementation complexity. Cross-domain clusters demand tighter coordination for canonicals, sitemaps, QA, and deployments. Subdomains such as ca.example.com sit in the middle from a governance standpoint. They can work well for operational separation, but they still create more moving parts than a unified folder model. Subfolders such as example.com/ca/ are usually simpler to maintain in one codebase. They often make cluster parity, internal linking, and global QA easier. The best structure is the one your team can keep consistent over time. Hreflang fails less from the chosen architecture than from inconsistent implementation across that architecture.

Canonical tags and hreflang: how they work together without conflict

Canonical tags choose the preferred URL among duplicates, while hreflang maps alternate locale equivalents. Those are different jobs, and mixing them up is one of the most common implementation failures. The usual valid pattern is simple: each localized page self-canonicals to itself and references alternates through hreflang. If the Canadian page canonicals to the US page, the Canadian URL is telling search engines not to index itself as its own version. Hreflang does not override a canonical pointing somewhere else. If all locale pages canonicalize to one master URL, the cluster is sending contradictory signals and the localized pages may be ignored.
Scenario Valid? Why
Each locale self-canonical + hreflang alternates Yes Signals are aligned
All locales canonicalize to one master URL + hreflang between all versions No Canonical conflicts with alternate mapping
Hreflang points to a non-canonical URL No Alternate points at a URL search engines may not keep
Canonicalized, noindex, or redirecting URLs included in cluster No Stronger directives conflict with hreflang
Hreflang can help search engines understand localized similarity, but it cannot fix duplicate-content problems created by bad canonical logic. Clean canonical strategy comes first.

Common hreflang mistakes and how to fix them

Most hreflang errors are structural and repeatable, which is good news because they are fixable with a proper audit. The bad news is that one broken rule can invalidate an entire cluster. Here are the most common mistakes we see in technical SEO reviews: 1. Invalid language or region codes, such as using ca to mean Canada instead of Catalan. 2. Missing reciprocal return links between alternates. 3. Missing self-referencing hreflang entries on the page itself. 4. Alternates pointing to redirects instead of final 200 URLs. 5. Alternates pointing to 404 or soft-404 pages. 6. Alternates pointing to noindex URLs. 7. Including URLs that canonicalize to another page. 8. Implementing hreflang only on the homepage while deeper localized pages are left unmapped. 9. Mixing protocols, trailing slashes, or parameterized URLs inside one cluster. 10. Mapping non-equivalent pages together, such as a UK product page to a Canadian category page. The fix is usually to normalize the cluster around final, indexable, self-canonical, equivalent URLs. Then revalidate reciprocity, self-references, and fallback logic before re-crawling the site.

Hreflang troubleshooting matrix: symptom, likely cause, and fix

A troubleshooting matrix is faster than guessing because the visible symptom usually points to a small set of technical causes. Wrong-version indexing is rarely random.
Symptom Likely cause How to verify Recommended fix
Google shows the wrong regional page Missing or conflicting hreflang, weak internal localization signals, or canonical conflict Inspect source, canonicals, sitemap, and internal links Align canonicals, fix cluster parity, reinforce locale links
Alternate page not discovered Missing return link or orphaned URL Crawl cluster and compare alternates Add reciprocal references and internal links
Tags present in template but missing live JS rendering, partial template load, or CMS/plugin conflict Check rendered HTML on live URL Fix rendering path and test production output
Sitemap says one thing, page says another Dual-source mismatch Compare HTML, sitemap, and headers Choose one source of truth and sync exports
Locale page excluded from index noindex, redirect, canonicalized elsewhere, or 404 Check status code, robots, canonical, meta robots Remove from cluster or make it indexable
Partially translated page performs poorly Not a true equivalent page Compare template, content blocks, and intent Exclude until equivalent localization exists
Faceted or paginated URLs cause noise Non-equivalent URLs included in cluster Review URL patterns in crawl export Restrict hreflang to true one-to-one alternates
PDFs not honoring alternates Header syntax or delivery issue Inspect response headers Correct Link header format at server or CDN

Pre-launch and post-launch hreflang QA checklist

A checklist catches more hreflang issues than ad hoc spot checks because the same failure points appear on every multilingual rollout. Use one pass before launch and another after the site is live.

Pre-launch QA checklist

  • Confirm every localized page has a true equivalent in the cluster.
  • Confirm each target URL returns a 200 status code.
  • Confirm target URLs are indexable and not blocked by meta robots.
  • Confirm canonicals are self-referencing unless there is a documented exception.
  • Confirm hreflang values use valid language and region combinations.
  • Confirm each page includes a self-referencing hreflang entry.
  • Confirm all alternates are reciprocal.
  • Confirm URLs are normalized for protocol, slash style, and preferred format.
  • Confirm x-default points to a real fallback or selector page.
  • Confirm templates render tags in the live head, not only in source code files.
  • Confirm XML sitemap namespaces and alternate entries validate if using sitemap delivery.
  • Confirm non-HTML assets use valid HTTP header delivery if needed.

Post-launch QA checklist

  • Crawl the live site and compare alternate clusters page by page.
  • Inspect rendered HTML on sample pages in every locale.
  • Inspect response headers for PDFs and other non-HTML files.
  • Validate live XML sitemap exports against actual canonical URLs.
  • Spot-check selector pages and x-default routing behavior.
  • Monitor indexing to ensure intended localized URLs are eligible.
  • Review wrong-version cases in search and trace them back to cluster gaps.
  • Re-audit after CMS updates, migrations, and each new locale launch.

How to validate hreflang implementation

A technical SEO analyst validating hreflang across source, sitemap, and crawl data.
You validate hreflang by checking the live source of truth, not by trusting the CMS setting screen. That means looking at page source or rendered HTML, response headers, and XML sitemaps depending on the delivery method. Manual checks still matter because they catch mismatches automation can miss. Open the localized page, inspect the final output, confirm the canonical, and compare the alternate set against the intended cluster map. A crawler or hreflang checker helps at scale because it can compare reciprocity, status codes, canonicals, and parity across many URLs at once. A hreflang generator or hreflang tag generator can help produce draft code, but generated tags are only safe after validation against live URLs and canonical rules. Search behavior is part of validation, but it is not the whole test. Perfect annotations do not guarantee that one specific URL will appear for every user, so judge success by cluster integrity, indexability, and whether the intended localized pages are eligible and discoverable.

WordPress and CMS implementation patterns

Hreflang WordPress setups depend on the theme, multilingual layer, SEO stack, and whether tags are injected by templates, plugins, or custom code. The method matters less than the output, because search engines only see the final HTML, header, or sitemap. How to add hreflang tags in WordPress depends on your build. On some sites, tags are template-driven; on others, they are generated by multilingual or SEO tooling; on headless builds, the cluster may live in the rendering layer or XML export process. Plugin-generated output still needs auditing. We see WordPress sites with missing self-references, bad locale mapping, canonical conflicts, and homepage-only annotations even when a plugin claims hreflang is enabled. The same rule applies across Shopify, headless CMS builds, enterprise CMS platforms, and custom frameworks. Verify the live output, not the checkbox that says the feature is on.

Scaling hreflang for large sites and complex edge cases

Scaling hreflang for hundreds to thousands of URLs requires a source-of-truth mapping system, not manual copy-paste. Once a site reaches enterprise scale, governance matters as much as syntax. A durable setup uses a structured locale map that defines each page’s equivalents, canonical target, indexability state, and fallback behavior. That map should feed templates, sitemaps, QA crawls, and deployment checks from one dataset where possible. Partially translated templates should stay out of a cluster until they are truly equivalent. If key modules, structured data, legal copy, or transactional elements differ too much, the page is not a clean alternate. Paginated and faceted URLs should be included only when there is a genuine one-to-one alternate in another locale. If the URL is just a filter state, sort order, or crawl trap, it usually does not belong in hreflang at all. Migrations and new locale launches are high-risk moments for breakage. A domain move, template rewrite, or country expansion can desync clusters, canonicals, and sitemap exports in one release. This is where a forensic technical SEO process helps. If you are managing international or multi-location architecture at scale, a technical SEO review or hreflang audit can catch wrong-version indexing issues before they spread across the site.

Quick examples of correct hreflang implementation

These short examples show what correct hreflang implementation looks like across common delivery methods. Use them as patterns, then adapt them to your real URL map.

HTML cluster example

<link rel="alternate" hreflang="en-us" href="https://www.example.com/us/service/" />
<link rel="alternate" hreflang="en-gb" href="https://www.example.com/uk/service/" />
<link rel="alternate" hreflang="en-ca" href="https://www.example.com/ca/service/" />
<link rel="alternate" hreflang="x-default" href="https://www.example.com/language-selector/" />

XML sitemap cluster example

<url>
  <loc>https://www.example.com/us/service/</loc>
  <xhtml:link rel="alternate" hreflang="en-us" href="https://www.example.com/us/service/" />
  <xhtml:link rel="alternate" hreflang="en-gb" href="https://www.example.com/uk/service/" />
  <xhtml:link rel="alternate" hreflang="en-ca" href="https://www.example.com/ca/service/" />
  <xhtml:link rel="alternate" hreflang="x-default" href="https://www.example.com/language-selector/" />
</url>

x-default selector example

<link rel="alternate" hreflang="x-default" href="https://www.example.com/choose-location/" />

Anti-example

<link rel="canonical" href="https://www.example.com/us/service/" />
<!-- repeated on UK and CA versions too -->
That anti-example breaks the cluster because all locales are telling search engines that the US URL is the only preferred version. Hreflang cannot fix a canonical setup that removes the alternate pages from consideration.

FAQ

What is hreflang implementation?

Hreflang implementation is the process of marking equivalent pages for different languages or regions so search engines can understand the relationship between them. It can be delivered in HTML, XML sitemaps, or HTTP headers.

How do I implement hreflang correctly?

Implement hreflang correctly by mapping true alternate URLs, keeping them indexable, using valid codes, adding self-references and reciprocal references, and aligning canonicals with the cluster. Then validate the live output with crawls and manual checks.

Should I use hreflang in HTML or XML sitemaps?

Use HTML when page templates are manageable and use XML sitemaps when centralized management is easier, especially on large sites. Use HTTP headers for PDFs and other non-HTML assets.

What is the difference between lang and hreflang?

lang declares the language of the current page, while hreflang points to alternate localized versions of equivalent pages. They serve different functions and often belong together.

Do hreflang tags need to be bidirectional?

Yes, alternate relationships should be reciprocal across the cluster. If one page references another locale, that locale should normally return the relationship.

Does every page need a self-referencing hreflang tag?

A self-referencing hreflang entry is standard best practice for localized pages in a cluster. It helps define the page’s own place in the alternate set.

What is x-default in hreflang?

x-default is the fallback URL for users not specifically targeted by the listed language-region values. It is commonly used on selector pages or generic global pages.

Can hreflang fix duplicate content?

Not by itself. Hreflang helps search engines understand alternate locale versions, but canonical conflicts and poor content equivalence still need to be fixed separately.

Can I use hreflang across different domains?

Yes, hreflang can connect alternates across domains, subdomains, and subfolders if the pages are true equivalents. Cross-domain setups simply require tighter governance and validation.

Should I add hreflang to PDFs?

Yes, if the PDFs have true localized equivalents and are meant to be indexed. For non-HTML assets, use HTTP headers instead of HTML head tags.

Do I need hreflang on every localized page or only the homepage?

You need it on every localized page that belongs in an alternate cluster, not just the homepage. Homepage-only implementation leaves deeper pages unmapped and usually incomplete.

How do I check if hreflang is working?

Check live HTML, headers, and XML sitemaps, then crawl the site for reciprocity, status codes, canonical alignment, and cluster parity. Also review whether the intended localized URLs are indexed and eligible in search.

What are the most common hreflang errors?

The most common errors are invalid codes, missing return links, missing self-references, redirects or 404s in clusters, noindex targets, and canonical conflicts. Homepage-only setups and non-equivalent page mapping are also common.

How do I add hreflang tags in WordPress?

Add them through the method your WordPress stack supports, which may be templates, multilingual tooling, custom code, or sitemap generation. Then audit the live output for correctness.

When is hreflang not necessary?

Hreflang is not necessary on a site with no alternate language or regional URLs. It is also unnecessary on pages that should not be indexed or that do not have true localized equivalents. If your site is already localized but Google keeps surfacing the wrong version, the next step is not more guesswork. It is a page-cluster audit that checks canonicals, alternates, sitemaps, headers, and fallback logic together.
Facebook
Twitter
LinkedIn
Email
Picture of Roman Haidak

Roman Haidak

I embarked on my SEO journey in 2008, starting with a successful project in Kiev and quickly expanding to diverse online ventures. The birth of my daughter in 2014 marked a shift from hobby to career, deepening my focus on aiding small businesses. As a specialist in SEO, marketing, and automation, I've embraced the rise of artificial intelligence in our field. Balancing practical experience with theoretical knowledge, I'm committed to continuous learning and collaboration.

Table of Contents

Get a Free Full Custom Analysis worth $1150

Recent Blogs