Blog
How to Set Up Hreflang Tags: Technical SEO Implementation Guide
Want a Quick Summary?
Summarize this article instantly with ChatGPT.
The hreflang attribute is an HTML specification that informs search engines about the language and geographical targeting of a webpage. When a website publishes variations of the same content tailored for different languages (such as English, Spanish, and Arabic) or specific regions (such as English in the United Kingdom versus English in Australia), hreflang tags instruct search crawlers which localized URL to display to each user in search results.
Without proper international annotations, search engines often treat multi-regional pages as duplicate content. This can cause the wrong regional page to rank, misalign currency and shipping messaging, split organic ranking equity, and degrade international conversion rates. Learning how to set up hreflang tags correctly ensures search engines serve the exact localized version intended for each audience.
Understanding Hreflang Syntax and Format Requirements
The basic HTML syntax for an hreflang annotation uses the <link> element:
<link rel="alternate" hreflang="language-country" href="https://www.example.com/target-page/" />
The value inside the hreflang attribute must strictly follow standardized naming conventions:
- Language Code (Required): Must use the two-letter ISO 639-1 format (e.g.,
enfor English,esfor Spanish,arfor Arabic,frfor French). - Country / Region Code (Optional): Must follow the ISO 3166-1 Alpha-2 format (e.g.,
GBfor United Kingdom,USfor United States,AEfor United Arab Emirates,AUfor Australia). - Formatting Rule: The language code must always precede the country code, separated by a hyphen (e.g.,
en-GB,en-US,ar-AE). Country codes cannot stand alone. An entry specifying onlyhreflang="US"is invalid becauseusrepresents the language code for the historical language of Ubykh, not the United States.
The 4 Golden Rules of Hreflang Implementation
Regardless of the technical implementation method chosen, all hreflang setups must adhere to four core architectural rules:
1. Return Links Are Mandatory (Bidirectional Confirmation)
Hreflang annotations operate on strict reciprocity. If Page A links to Page B as its German alternative, Page B must link back to Page A as its English alternative. If bidirectional confirmation is missing on even one URL in the cluster, search engines ignore the relationship entirely to prevent unauthorized cross-domain hijacking.
2. Self-Referencing Annotations Are Required
Every localized page must include an hreflang tag that points directly to itself. For example, the English page must include an en tag pointing to itself, alongside alternate tags pointing to the French, German, or regional counterparts.
3. Always Use Absolute Canonical URLs
Never use relative URL paths (such as href="/fr/page/") in hreflang declarations. Every href attribute must specify the complete protocol, domain, and path (e.g., https://www.example.com/fr/page/). Furthermore, only link to indexable 200 OK canonical pages. Never point hreflang tags to URLs that return 301 redirects, 404 errors, or contain noindex tags.
4. Include the x-default Tag for Unmatched Visitors
The x-default value is a specialized reservation indicating the default landing page for international users whose language or location does not match any specified alternate tags. It is standard practice to assign x-default to a global English page or an international language/country selector gateway.
Method 1: Implementation via HTML Head Elements
The most common approach for static or brochure websites is placing link tags directly within the <head> element of each HTML page.
Consider an international website with three localized versions of its homepage: an American English version, a British English version, and a Spanish version. Every single one of those three pages must contain the identical block of code in its <head>:
<head>
<!-- Self-referencing and regional alternates -->
<link rel="alternate" hreflang="en-US" href="https://www.example.com/us/" />
<link rel="alternate" hreflang="en-GB" href="https://www.example.com/uk/" />
<link rel="alternate" hreflang="es" href="https://www.example.com/es/" />
<!-- Fallback default for unmatched users -->
<link rel="alternate" hreflang="x-default" href="https://www.example.com/" />
</head>
Pros: Easy to configure on small websites; inspectable via standard browser source code.
Cons: Bloats HTML page weight when dealing with dozens of languages, and requires extensive maintenance as new regional pages are published.
Method 2: Implementation via XML Sitemaps (Best for Large Sites)
For large enterprise platforms, e-commerce stores, or multi-lingual catalogs with thousands of pages, managing hreflang tags in the HTML head creates massive template bloat. Defining international relationships inside XML sitemaps moves the processing overhead off the frontend page load entirely.
In an XML sitemap, each URL is listed within a <url> block, and every language version is declared as an xhtml:link child element:
<?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">
<!-- US English URL Entry -->
<url>
<loc>https://www.example.com/us/</loc>
<xhtml:link rel="alternate" hreflang="en-US" href="https://www.example.com/us/" />
<xhtml:link rel="alternate" hreflang="en-GB" href="https://www.example.com/uk/" />
<xhtml:link rel="alternate" hreflang="es" href="https://www.example.com/es/" />
<xhtml:link rel="alternate" hreflang="x-default" href="https://www.example.com/" />
</url>
<!-- UK English URL Entry -->
<url>
<loc>https://www.example.com/uk/</loc>
<xhtml:link rel="alternate" hreflang="en-US" href="https://www.example.com/us/" />
<xhtml:link rel="alternate" hreflang="en-GB" href="https://www.example.com/uk/" />
<xhtml:link rel="alternate" hreflang="es" href="https://www.example.com/es/" />
<xhtml:link rel="alternate" hreflang="x-default" href="https://www.example.com/" />
</url>
<!-- Spanish URL Entry -->
<url>
<loc>https://www.example.com/es/</loc>
<xhtml:link rel="alternate" hreflang="en-US" href="https://www.example.com/us/" />
<xhtml:link rel="alternate" hreflang="en-GB" href="https://www.example.com/uk/" />
<xhtml:link rel="alternate" hreflang="es" href="https://www.example.com/es/" />
<xhtml:link rel="alternate" hreflang="x-default" href="https://www.example.com/" />
</url>
</urlset>
Pros: Zero impact on page rendering speed; fully managed and automated at the database level.
Cons: Sitemap files grow significantly in size and must be split into sitemap indexes adhering to standard 50,000 URL and 50MB file size limits.
Method 3: Implementation via HTTP Response Headers
HTML link tags and XML sitemaps work for HTML documents, but websites frequently publish non-HTML assets like multi-lingual downloadable PDF brochures, whitepapers, or documentation sheets. For non-HTML files, declare hreflang directives using the Link header in the server's HTTP response.
Example Apache Configuration (.htaccess):
<Files "product-guide.pdf">
Header add Link '<https://www.example.com/docs/en/product-guide.pdf>; rel="alternate"; hreflang="en"'
Header add Link '<https://www.example.com/docs/de/product-guide.pdf>; rel="alternate"; hreflang="de"'
Header add Link '<https://www.example.com/docs/product-guide.pdf>; rel="alternate"; hreflang="x-default"'
</Files>
Common Hreflang Implementation Scenarios
The table below summarizes standard international deployment use cases and the correct hreflang configurations:
| Targeting Scenario | Hreflang Attribute Values | Target Audience | Typical Use Case |
|---|---|---|---|
| Broad Language Targeting | hreflang="en", hreflang="es" |
Any English or Spanish speaker globally | Universal translation where currency and legal terms do not vary |
| Regional Language Dialects | hreflang="en-US", hreflang="en-GB" |
English speakers in USA vs. United Kingdom | Local product inventory, regional pricing (USD vs. GBP), shipping terms |
| Multi-Language Single Country | hreflang="fr-CA", hreflang="en-CA" |
French vs. English speakers inside Canada | Bilingual national markets requiring regulatory compliance |
| Generic Country Fallback | hreflang="en" alongside en-US and en-AU |
English speakers outside US and Australia | Catches global English speakers in South Africa, Singapore, etc. |
| Global Unmatched Fallback | hreflang="x-default" |
Users with unspecified language preferences | International splash page or global root homepage |
Critical Hreflang Mistakes to Avoid
Because hreflang parsing is unforgiving, minor technical oversights can invalidate your entire configuration:
- Using Incorrect Country Codes: A frequent mistake is using
en-UKinstead of the official ISO 3166-1 Alpha-2 designationen-GB, or usingen-EU(EU is a political union, not an individual ISO country code). - Forgetting Return Links: If Page A links to Page B, but Page B lacks a reverse link back to Page A, search engines treat the instruction as incomplete and discard it.
- Conflicting Canonical and Hreflang Targets: Every page in an hreflang cluster must be self-canonical. If
https://example.com/uk/declares an hreflang tag pointing to itself, but its canonical tag points tohttps://example.com/us/, the instructions contradict one another. Search engines will disregard the hreflang annotation. - Linking to Non-200 OK Status Codes: Including URLs that return 301 redirects, 302 redirects, or 404 errors breaks the chain. All alternate links must resolve directly to live 200 OK pages.
- Mixing Implementation Methods: Choose one method (HTML head, XML sitemaps, or HTTP headers) and stick to it. Declaring hreflang tags in both the HTML head and the XML sitemap increases maintenance complexity and risks contradictory signals.
Step-by-Step Validation and Troubleshooting Workflow
After deploying your hreflang configuration, verify that search engines process the directives cleanly:
- Crawl with Screaming Frog SEO Spider:
Configure Screaming Frog under Configuration > Spider > Crawl > Hreflang to extract language annotations. Review the Hreflang tab to detect missing return links, unconfirmed alternates, language code errors, and non-canonical destinations.
- Inspect Network Headers and Source Code:
Spot-check localized templates using browser developer tools. Confirm that the
hreflangandrel="alternate"attributes appear in the raw HTML before JavaScript execution. - Test Live URLs in Google Search Console:
Use the GSC URL Inspection tool on individual localized pages to verify that Googlebot renders the page correctly and identifies alternate language signals without errors.
Maintain Scalable International SEO Architecture
Setting up hreflang tags is a structural requirement for any multi-language or multi-regional website. By applying standardized ISO language and country codes, enforcing bidirectional return links, pairing every localized page with a self-referencing canonical tag, and designating an x-default fallback, you ensure search engines deliver the correct regional experience to your global audience.
Looking for Measurable Business Growth?
Partner with BrandStory for end-to-end digital & creative excellence.
Transform Your Digital Growth with BrandStory
From SEO, PPC, social media marketing, and content marketing to website development, branding, and lead generation, BrandStory delivers result-driven digital marketing services in Dubai and across the UAE, helping businesses attract, engage, and convert more customers.
Trusted by 1000+ leading brands in Dubai and globally including:
Related Blogs
How to Fix Mobile Usability Issues: Step-by-Step Technical Guide
With Google operating entirely on mobile-first indexing, search engine crawlers assess, index, and rank web pages base...
How to Fix JavaScript SEO Issues: Complete Technical Guide
Modern web development relies heavily on JavaScript frameworks like React, Next.js, Vue, Angular, and Nuxt to build ri...
How to Fix Soft 404 Errors: Complete Technical SEO Guide
A Soft 404 error occurs when a web server responds with an HTTP 200 OK status code signaling success, but search engin...
How to Fix Mixed Content Errors: Complete Security Guide
A mixed content error occurs when an initial webpage loads securely over HTTPS, but subresources such as images, scrip...
How to Fix Missing Meta Descriptions: Complete SEO Guide
A missing meta description occurs when an HTML document lacks a <meta name="description"> tag in its <head>...
How to Fix Duplicate Title Tags: Step-by-Step Technical Guide
A duplicate title tag occurs when two or more distinct URLs on your website share the exact same <title> HTML el...
