Hreflang Generator
Generate the correct hreflang link tags for your multilingual website. Add each language version of your page, and get the ready-to-paste HTML for your <head>.
What is hreflang?
The hreflang attribute tells Google which language version of a page to serve based on a user's locale. Without it, Google may treat multilingual pages as duplicates or surface the wrong language version in search results.
When to use x-default?
x-default designates the fallback URL shown to users whose locale doesn't match any variant, typically a language-selector page or your primary landing page. Every hreflang set should include one.
Where to Place hreflang Tags
You can implement hreflang in one of three ways. If you use more than one method, make sure they are consistent:
- HTML
<head>: The most common method. Add the<link>tags directly into the<head>section of your HTML. - HTTP Headers: Used primarily for non-HTML files like PDFs. The information is passed in the response header.
- XML Sitemap: Ideal for large sites with thousands of pages to avoid increasing the file size of your HTML pages. You define the variants within your
sitemap.xml.
Language vs. Region: Is the Region Necessary?
The simple answer is no, the region code is not mandatory. However, the language code is strictly required.
1. The Mandatory Component: Language
You must always specify a language using the ISO 639-1 format (e.g., en, es, fr). If you only have one version of your site for all Spanish speakers globally, you should use hreflang="es". Adding a region in this case (like es-ES) would unnecessarily limit your reach because it would tell Google that the page is only for people in Spain, potentially hurting your visibility in Mexico or Argentina.
2. The Optional Component: Region
The region code (ISO 3166-1 alpha-2) is an optional modifier. You should only use it when you have different content for people who speak the same language but live in different places.
- Use a region code if: You have different currencies (USD vs. GBP) or different shipping policies.
- Use a region code if: There are significant dialect differences (Portuguese in Brazil vs. Portugal).
- Do NOT use a region code if: The content is identical for all speakers of that language. Using
en-USwhen you don't have anen-GBversion just limits your reach.
3. The Golden Rule of Syntax
You can have a language alone, but you cannot have a region alone.
| Format | Status | Example |
|---|---|---|
| Language Only | Valid | hreflang="en" |
| Language + Region | Valid | hreflang="en-GB" |
| Region Only | Invalid | hreflang="GB" |
Best Practices
- Every page in the set must reference all other pages, including itself. For example, if you have an English page at
/en/and a Turkish page at/tr/, both pages must carryhreflangtags pointing to/en/,/tr/, andx-default. A tag on only one side is invalid and ignored. - All references must be consistent across every page in the set. If page A lists page B but page B doesn't list page A, the link from A is discarded.
- Use absolute URLs (
https://example.com/en/) - relative URLs (/en/) are not supported. - Each language code must be unique within a set; duplicates cause the signals to be ignored.