Hreflang Tag Generator
The hreflang attribute helps Google serve the correct language or regional URL in search results. Use this free tool to generate the correct hreflang implementation for your multilingual or multi-regional website.
Simple Hreflang Generator
Use this basic tool to quickly generate hreflang tags for your website’s language/region variations.
Generated Hreflang Tags
Advanced Hreflang Generator
Use this comprehensive tool to generate and manage hreflang tags for complex multilingual websites. Features include CSV import/export, sitemap generation, and validation.
Input Methods
Use {lang} as placeholder for language code and {country} for country code.
URL Variations
CSV should have columns: URL, Language, Region (optional), x-default (true/false)
CSV Template
URL,Language,Region,x-default https://example.com/en/,en,,true https://example.com/es/,es,,false https://example.com/fr/,fr,,false https://example.com/de-de/,de,de,false
Generated Output
Understanding Hreflang Tags
What are Hreflang Tags?
Hreflang tags are HTML attributes that tell search engines which language and regional version of a page should be shown to users in search results. They help Google and other search engines serve the correct language or regional URL to users based on their location or language preferences.
For example, if your website has content in English, Spanish, and French, hreflang tags help ensure that English speakers see the English version, Spanish speakers see the Spanish version, and French speakers see the French version in search results.
Why are Hreflang Tags Important?
Without proper hreflang implementation, search engines might:
- Consider your translated content as duplicate content
- Display the wrong language version to users
- Dilute your search ranking potential across multiple versions
- Provide a poor user experience for international visitors
Properly implemented hreflang tags help search engines understand the relationship between your multilingual or multi-regional pages, improving your international SEO and user experience.
Hreflang Syntax and Format
Hreflang tags can be implemented in three ways:
1. HTML Head Method
<link rel="alternate" href="https://example.com" hreflang="en" />
<link rel="alternate" href="https://example.com/es" hreflang="es" />
<link rel="alternate" href="https://example.com/fr" hreflang="fr" />
2. XML Sitemap Method
<url>
<loc>https://example.com/</loc>
<xhtml:link rel="alternate" hreflang="en" href="https://example.com/" />
<xhtml:link rel="alternate" hreflang="es" href="https://example.com/es/" />
<xhtml:link rel="alternate" hreflang="fr" href="https://example.com/fr/" />
</url>
3. HTTP Headers Method (for PDFs and non-HTML files)
Link: <https://example.com/file.pdf>; rel="alternate"; hreflang="en",
<https://example.com/es/file.pdf>; rel="alternate"; hreflang="es",
<https://example.com/fr/file.pdf>; rel="alternate"; hreflang="fr"
Language and Region Codes
Hreflang values use ISO language codes (ISO 639-1) and optional country codes (ISO 3166-1 Alpha 2):
- Language only:
hreflang="en"
(English, any region) - Language + Region:
hreflang="en-us"
(English, United States) - x-default:
hreflang="x-default"
(Default page when no matching language is available)
Common examples:
en
– Englishen-us
– English (United States)en-gb
– English (United Kingdom)es
– Spanishes-mx
– Spanish (Mexico)fr
– Frenchfr-ca
– French (Canada)de
– Germanzh-cn
– Chinese (Simplified)zh-tw
– Chinese (Traditional)
Implementation Requirements
For hreflang tags to work correctly, you must follow these critical requirements:
- Bidirectional References: Each language version must reference all other language versions, including itself. This creates a complete bidirectional linking structure.
- Absolute URLs: Always use absolute URLs (including protocol and domain) in hreflang tags.
- Consistent Implementation: Use the same implementation method across your site (HTML head, XML sitemap, or HTTP headers).
- Canonical Tags: Ensure canonical tags are consistent with your hreflang implementation.
- x-default: Include an x-default version to specify which page should be shown when no language version matches the user’s preference.
Common Implementation Mistakes
- Missing self-referential hreflang tags
- Incomplete bidirectional linking
- Using incorrect language/region codes
- Mixing relative and absolute URLs
- Conflicting canonical and hreflang signals
Best Practices for Hreflang Implementation
1. Complete Bidirectional Linking
Every page must reference all language alternatives, including itself. If Page A links to Pages B and C, then Pages B and C must also link to Page A and each other.
2. Use the x-default Tag
The x-default tag specifies which page to show when no language version matches the user’s browser language. This is typically your main or global page.
<link rel="alternate" href="https://example.com/" hreflang="x-default" />
3. Consistent URL Structure
Maintain a consistent URL structure for different language versions. Common approaches include:
- Subdirectories: example.com/es/, example.com/fr/
- Subdomains: es.example.com, fr.example.com
- Country-specific domains: example.es, example.fr
4. Align Hreflang with Content
Ensure the language specified in the hreflang tag matches the actual language of the content. Don’t use hreflang=”es” if the page content is in English.
5. Regular Validation
Regularly check your hreflang implementation using tools like Google Search Console’s International Targeting report or third-party SEO tools.
6. Combine with Other International SEO Signals
Use hreflang tags alongside other international SEO best practices:
- Server location (when using country-specific domains)
- Language meta tags
- Local content and cultural adaptations
- Local backlinks
Complete Hreflang Example
Here’s a complete example for a website with English (default), Spanish, and French versions:
HTML Head Implementation
On the English page (https://example.com/):
<link rel="alternate" href="https://example.com/" hreflang="x-default" />
<link rel="alternate" href="https://example.com/" hreflang="en" />
<link rel="alternate" href="https://example.com/es/" hreflang="es" />
<link rel="alternate" href="https://example.com/fr/" hreflang="fr" />
On the Spanish page (https://example.com/es/):
<link rel="alternate" href="https://example.com/" hreflang="x-default" />
<link rel="alternate" href="https://example.com/" hreflang="en" />
<link rel="alternate" href="https://example.com/es/" hreflang="es" />
<link rel="alternate" href="https://example.com/fr/" hreflang="fr" />
On the French page (https://example.com/fr/):
<link rel="alternate" href="https://example.com/" hreflang="x-default" />
<link rel="alternate" href="https://example.com/" hreflang="en" />
<link rel="alternate" href="https://example.com/es/" hreflang="es" />
<link rel="alternate" href="https://example.com/fr/" hreflang="fr" />
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/</loc>
<xhtml:link rel="alternate" hreflang="x-default" href="https://example.com/" />
<xhtml:link rel="alternate" hreflang="en" href="https://example.com/" />
<xhtml:link rel="alternate" hreflang="es" href="https://example.com/es/" />
<xhtml:link rel="alternate" hreflang="fr" href="https://example.com/fr/" />
</url>
<url>
<loc>https://example.com/es/</loc>
<xhtml:link rel="alternate" hreflang="x-default" href="https://example.com/" />
<xhtml:link rel="alternate" hreflang="en" href="https://example.com/" />
<xhtml:link rel="alternate" hreflang="es" href="https://example.com/es/" />
<xhtml:link rel="alternate" hreflang="fr" href="https://example.com/fr/" />
</url>
<url>
<loc>https://example.com/fr/</loc>
<xhtml:link rel="alternate" hreflang="x-default" href="https://example.com/" />
<xhtml:link rel="alternate" hreflang="en" href="https://example.com/" />
<xhtml:link rel="alternate" hreflang="es" href="https://example.com/es/" />
<xhtml:link rel="alternate" hreflang="fr" href="https://example.com/fr/" />
</url>
</urlset>