Hreflang Tags Explained
Hreflang tells search engines which URL to show for each language or region. Every version of a page lists itself and all its alternates with link rel="alternate" hreflang="code" and a full URL. Codes are an ISO 639-1 language, optionally followed by an ISO 3166-1 region such as en-GB, and x-default covers everyone else.
| Code | Valid? | Meaning |
|---|---|---|
| en | Yes | English, any region |
| en-GB | Yes | English for users in the United Kingdom |
| zh-Hant | Yes | Chinese in Traditional script (ISO 15924 script code) |
| es-419 | No (for Google) | Numeric regions are not supported |
| x-default | Yes | Fallback when no other version matches |
| GB | No | Region alone is not allowed |
| en-UK | No | The region code for the United Kingdom is GB |
Updated
Most hreflang problems are bookkeeping: one page forgets to link back, a code uses the wrong region, or URLs are relative. The generator below builds the full, symmetrical set for every version at once, so each page carries the same complete list.
Hreflang generator
Add each version's code and full URL. The generator checks the codes and writes the tag set and sitemap block for all versions at once.
The three ways to declare alternates
HTML link tags in the head
The same five lines go on the English, British English, German and selector pages.
<link rel="alternate" hreflang="en" href="https://example.com/en/pricing">
<link rel="alternate" hreflang="en-GB" href="https://example.com/uk/pricing">
<link rel="alternate" hreflang="de" href="https://example.com/de/preise">
<link rel="alternate" hreflang="x-default" href="https://example.com/pricing">HTTP Link header for a PDF
Sent by the server with the file, since a PDF has no head to put tags in.
Link: <https://example.com/en/guide.pdf>; rel="alternate"; hreflang="en",
<https://example.com/de/guide.pdf>; rel="alternate"; hreflang="de"Sitemap entries
Each url element lists every version, including itself. The xhtml namespace must be declared on urlset.
<?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/pricing</loc>
<xhtml:link rel="alternate" hreflang="en" href="https://example.com/en/pricing"/>
<xhtml:link rel="alternate" hreflang="de" href="https://example.com/de/preise"/>
</url>
<url>
<loc>https://example.com/de/preise</loc>
<xhtml:link rel="alternate" hreflang="en" href="https://example.com/en/pricing"/>
<xhtml:link rel="alternate" hreflang="de" href="https://example.com/de/preise"/>
</url>
</urlset>Errors and their fixes
| Problem | Fix |
|---|---|
| Missing return link | Add the full set of tags to every version |
| Region without language, such as hreflang="US" | Use a language plus region, such as en-US |
| Wrong region code, such as en-UK | Use the ISO 3166-1 code GB |
| Relative href | Write the full URL with https and host |
| Alternate URL redirects or returns 404 | List only live, final URLs |
When hreflang is worth adding
Use it when the same content exists in more than one language, or in one language with real regional differences such as prices, spelling or delivery terms. It helps Google send a searcher in Mexico to the Mexican Spanish page instead of the Spanish one from Spain.
A site in one language for one market does not need hreflang. Adding it there only creates something else to maintain.
Common mistakes
Relative URLs are not accepted; the href must include https and the host. Underscores are wrong in hreflang: write en-GB, not en_GB, which is the Open Graph locale style.
Listing a URL that redirects or returns an error wastes the annotation. Keep the set to live, final addresses and update it whenever a translated page is added or removed.
How it works
- Add a row for each language or regional version with its code and full URL.
- Optionally mark one URL, often a language picker or your main version, as x-default.
- Copy the link tags into the head of every version, or use the sitemap output instead.
- After the next crawl, inspect a few of the URLs in Search Console to confirm Google picked up the set.
Tips
- Put the identical set of tags on every version. The tags on the English page and the French page should be the same list.
- Use only one method per page set. Mixing HTML tags with sitemap entries makes it harder to keep them in sync.
- Hreflang is a hint about which version to show. It does not translate anything, and Google says it detects a page's language with its own algorithms rather than from hreflang.
Frequently asked questions
Do I need a self-referencing hreflang tag?
Yes. Google's documentation says each version should list itself as well as all the other versions. Without the self reference the set is incomplete.
What is x-default for?
x-default names the page to show when a searcher's language or region matches none of your listed versions. A language selector page or your international homepage is the usual choice.
What happens if page B does not link back to page A?
Google requires the links to go both ways. If A points to B but B does not point back to A, the annotation can be ignored. Return links stop third parties from claiming to be an alternate of your page.
Should I use HTML tags, HTTP headers or the sitemap?
Google treats all three as equivalent. HTML tags suit most sites. HTTP Link headers are the option for PDFs and other non-HTML files. A sitemap keeps the markup out of your pages and is easier for large sites with many languages.
Can I target a country without a language?
No. A region code on its own is invalid. To target Canada in English and French, use en-CA and fr-CA.
Related: Canonical tag checker, Sitemap and robots.txt examples, Next.js SEO checklist, Open Graph tags explained.
Build your site free or see all free tools. On We.Inc you can build your site free, with no card and no trial needed to start. AI building is on paid plans from $19 a month.
More in Guides
- The HTML Blink Tag and Its CSS Replacement
- HTML Boilerplate: A Modern Starter, Explained Line by Line
- HTML Color Names
- HTML Comments, Line Breaks and Spaces
- HTML and CSS Cheat Sheet
- Free HTML Email Templates (Table-Based and Dark-Mode Ready)
- HTML Video and Iframe Embeds That Load Fast
- HTML Images and CSS Background Images
Product
Who It's For
- For Agencies
- For Freelancers
- For Hosting Providers
- For SaaS Platforms
- For Startups
- For Financial Services
- For Healthcare
Features
Resources
- Blog
- Help Center
- Free Business Tools
- Free UI Components
- Website Templates
- Template Collections
- Website Examples
- Guides
- Comparisons
- Alternatives
- Best Lists
- Reviews
- Pricing Guides
- Use Cases
- Glossary & Guides
- Integrations
- Developers
- Benchmark
- Windows App