AdvancedInternational SEOTechnical SEOAdvanced SEO 4 min read

Hreflang

Hreflang is an HTML attribute that tells search engines when a page has alternate versions in different languages or for different regions, preventing duplicate content issues and ensuring the correct version appears in local search results.

What is Hreflang?

Hreflang is a critical technical SEO element for international websites that serve content in multiple languages or target different geographic regions. The attribute signals to Google and other search engines which version of a page is intended for specific users based on their language or location. Without hreflang, Google may struggle to determine which language version to show to users in different countries, potentially showing the wrong version or diluting ranking potential across duplicate language versions. Hreflang prevents duplicate content problems by telling search engines these are alternative versions of the same content, not competing pages.

Implementing hreflang involves adding link tags in the page head section that specify the current page and all alternate versions with their language and/or regional targets. The implementation uses the format 'hreflang=xx' where xx is the ISO 639-1 language code (like 'en', 'es', 'fr') and optionally includes the ISO 3166-1 alpha-2 country code (like 'en-US', 'es-MX', 'en-GB'). You must also include a 'self-referential' hreflang pointing to the current page, confirming it's the correct version for current users. For example, an English page would include hreflang='en' pointing to itself plus hreflang entries for Spanish, French, and other language versions.

Hreflang can be implemented through multiple methods: HTML link tags in the page head (most common), HTTP headers, XML sitemap entries, or JavaScript (for dynamic sites). The HTML link tag method is most straightforward—each alternate version appears as a separate link tag in the head. XML sitemap implementation involves adding hreflang elements to your sitemap file, making it scalable for large sites. The key principle is consistency: if page A says page B is its Spanish version, page B's hreflang must reference page A as its English version (bidirectional linking).

Common hreflang implementation mistakes include incorrect language codes, missing self-referential tags, inconsistent implementation across versions, pointing to wrong URLs, using 'x-default' incorrectly, and placing hreflang on non-canonical URLs. Testing with Google's hreflang testing tool and careful validation prevents these issues. Proper hreflang implementation is particularly important for sites with multiple regional versions (example.com, example.co.uk, example.de) because it ensures each version ranks appropriately in its target market without cannibalizing traffic between versions.

Why It Matters for SEO

Hreflang is essential for international SEO because it ensures the right language or regional version appears to the right users in search results. Without it, users in Spain might see your English pages instead of Spanish versions, creating poor user experience and wasted ranking potential. Hreflang also prevents duplicate content penalties by telling Google these are intentional variations, not spam or duplicate content. This is crucial because duplicate content can dilute your ranking authority across multiple versions instead of consolidating it.

For multinational businesses or sites serving multiple languages, proper hreflang implementation can dramatically improve search visibility in each target market. It allows you to fully optimize each language version without worrying about cannibalizing your own rankings. Without hreflang, Google must guess which version to show different users, often getting it wrong. Getting hreflang right is one of the most impactful technical SEO optimizations for international sites because it directly improves user experience and prevents traffic loss.

Examples & Code Snippets

Hreflang HTML Link Tag Implementation

htmlHreflang HTML Link Tag Implementation
<!-- English US version with hreflang for all versions -->
<link rel="alternate" hreflang="en-US" href="https://example.com/en/" />
<link rel="alternate" hreflang="en-GB" href="https://example.com/en-gb/" />
<link rel="alternate" hreflang="es-ES" href="https://example.es/es/" />
<link rel="alternate" hreflang="es-MX" href="https://example.mx/es/" />
<link rel="alternate" hreflang="fr-FR" href="https://example.fr/fr/" />
<link rel="alternate" hreflang="de-DE" href="https://example.de/de/" />
<!-- Self-referential hreflang confirming this is the correct version -->
<link rel="alternate" hreflang="en-US" href="https://example.com/en/" />
<!-- x-default for users whose language isn't specifically targeted -->
<link rel="alternate" hreflang="x-default" href="https://example.com/" />

<!-- Notes:
- Place all hreflang tags in the <head> section
- Include ALL versions (including the current page)
- Use exact matching URLs (including trailing slashes)
- x-default catches users whose language isn't targeted
- This same structure repeats on every alternate version page -->

Example of proper hreflang implementation in HTML head section

Hreflang XML Sitemap Implementation

xmlHreflang XML Sitemap Implementation
<?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/about/</loc>
    <xhtml:link rel="alternate" hreflang="en-US" href="https://example.com/en/about/" />
    <xhtml:link rel="alternate" hreflang="en-GB" href="https://example.com/en-gb/about/" />
    <xhtml:link rel="alternate" hreflang="es-ES" href="https://example.es/es/acerca-de/" />
    <xhtml:link rel="alternate" hreflang="fr-FR" href="https://example.fr/fr/a-propos/" />
    <xhtml:link rel="alternate" hreflang="x-default" href="https://example.com/about/" />
  </url>
  <url>
    <loc>https://example.es/es/acerca-de/</loc>
    <xhtml:link rel="alternate" hreflang="en-US" href="https://example.com/en/about/" />
    <xhtml:link rel="alternate" hreflang="es-ES" href="https://example.es/es/acerca-de/" />
    <xhtml:link rel="alternate" hreflang="fr-FR" href="https://example.fr/fr/a-propos/" />
    <xhtml:link rel="alternate" hreflang="x-default" href="https://example.com/about/" />
  </url>
  <!-- Each URL includes hreflang entries for all language/regional versions -->
</urlset>

Example of hreflang implementation in XML sitemap for scalable management

Pro Tip

Always test your hreflang implementation with Google's URL Inspection tool and hreflang testing tools before deployment, and ensure bidirectional linking—if English page points to Spanish version, Spanish must point back to English. One-way hreflang breaks the system.

Frequently Asked Questions

'en' targets all English speakers regardless of region. 'en-US' targets English speakers in the United States specifically. 'en-GB' targets English speakers in the UK. Use broader codes like 'en' if you don't have regional variations, but use regional codes when you have different versions for different countries (different pricing, shipping, content).
Yes, best practice is to include a self-referential hreflang tag on every page pointing to itself. This confirms to Google that this is the correct version for this language/region. Without it, Google may not fully trust your hreflang structure.
x-default catches users whose language/region isn't specifically targeted by your hreflang tags. Use it to point to a page that should show to international users or users in countries you don't have specific versions for. Common uses are pointing to an English homepage or language selector page.
No, canonical and hreflang serve different purposes. Canonical should point to one preferred version within the same language. Hreflang tells Google about alternate language versions. You often use both: hreflang for language variations and canonical for near-duplicate content within the same language.
Google may ignore incorrect hreflang and treat alternate versions as duplicate content or show the wrong language version to users. This results in traffic loss and poor user experience. Always test hreflang implementations before deployment using Google's URL Inspection tool.

Ready to Grow Your Organic Traffic?

Get a free SEO audit and a custom strategy roadmap for your business. No commitment required — just results-focused recommendations from our team.