Hreflang tag generator
Generate valid hreflang annotations for multilingual and multi-region sites, as HTML tags, sitemap entries or HTTP headers, with checks for the errors that make Google ignore them.
4 steps, no signup
- 01
List every version
Add one row per language or country version of the page: the language, an optional region, and its URL.
- 02
Set the fallback
Optionally add an x-default URL for visitors whose language you don't target, often a language picker or your main version.
- 03
Fix any warnings
Languages and regions are picked from lists, so invalid codes like
en-UKcan't slip in. Duplicate codes, shared URLs, relative URLs and mixed protocols are flagged as you type. - 04
Copy the format you need
HTML
<link>tags for the page head, XML sitemap entries, or HTTP headers for PDFs and other non-HTML files.
Short answer: add one row per language or country version of a page, pick the language and optional region from the lists, paste each URL, and copy the output. You get the full, reciprocal set of hreflang annotations as HTML <link> tags, sitemap entries or an HTTP header. Paste the same set on every version.
What this hreflang generator does
If your site has the same page in several languages, or versions for different countries, hreflang tells Google which one to show each searcher. Without it, a German searcher may land on your English page, or Google may treat your UK and US pages as duplicates. The hreflang tag generator builds the full, reciprocal set of annotations for a page and checks the codes as you type.
The three ways to add hreflang
| Method | Where | Best for |
|---|---|---|
| HTML tags | <link rel="alternate" hreflang="…" href="…"> in each page's <head> | Most sites; easy to template in a CMS |
| XML sitemap | <xhtml:link> under each <url> | Large sites; keeps page HTML light |
| HTTP header | Link: <url>; rel="alternate"; hreflang="…" | PDFs and other non-HTML files |
Google documents all three as equivalent (Google Search Central). Use one method per page; mixing them makes errors harder to find.
Rules that make hreflang work
- Every version lists every version, including itself. The generator outputs the full set; paste the same block on each version.
- Return links are required. If A references B, B must reference A.
- Language codes are ISO 639-1 (
en,de,pt). Optional region codes are ISO 3166-1 alpha-2 (GB,US,BR). - Absolute URLs only, with the protocol.
- Each version canonicalises to itself.
The most common hreflang mistakes
| Mistake | Fix |
|---|---|
en-UK | en-GB |
Region only: hreflang="DE" | Add a language: de-DE or just de |
Region before language: US-en | en-US |
Underscore: en_US | Hyphen: en-US |
| Relative URLs | Full https:// URLs |
| Missing return links | Put the full set on every version |
| All canonicals pointing to the English page | Self-referencing canonicals |
Worked example
The tool opens with three versions filled in: English at https://example.com/, German at /de/ and Mexican Spanish at /es-mx/. Add https://example.com/ as the x-default and the HTML output is:
<link rel="alternate" hreflang="en" href="https://example.com/" />
<link rel="alternate" hreflang="de" href="https://example.com/de/" />
<link rel="alternate" hreflang="es-MX" href="https://example.com/es-mx/" />
<link rel="alternate" hreflang="x-default" href="https://example.com/" /> One warning stays: Spanish is targeted only with a region, so Spanish speakers outside Mexico have no match. Add a plain es row (or accept that they'll get the x-default) and the warning clears. Those four or five lines go into the <head> of all three pages, unchanged.
Language vs. region targeting
Target a language (es) when one version serves all speakers. Add a region (es-MX, es-ES) only when versions differ by country: prices, spelling, legal text. A good pattern is regional versions plus a generic language fallback: es-MX, es-ES and es for every other Spanish speaker.
What it doesn't do
- It doesn't crawl your site. It can't confirm the URLs load, return 200, or carry the matching tags. Check that in Search Console or a crawler after you deploy.
- It builds the set for one page at a time. For a whole site, template the same logic in your CMS or generate the sitemap from your database.
- The language list covers 35 common languages and 49 regions. For anything else, or a script subtag like
zh-Hant, edit the output by hand. - In the sitemap format, the x-default URL is listed as an alternate but doesn't get its own
<url>block. If your x-default is a separate page (a language picker, say), add a<url>entry for it with the same set.
What the warnings mean
- "… is listed twice." Two rows have the same language-region code. Google can't pick between them; keep one.
- "… is used for both …" Two codes point to the same URL. Usually a copy-paste slip. If one page really serves both, use the plain language code instead.
- "… isn't an absolute URL." Add
https://and the domain. - "Some URLs use http and others https." Use the protocol your canonical tags use.
- "No x-default." Optional. Add one if you have a sensible page for everyone else.
Related tools
Once the tags are live, check how each version's title and description will look in results with the SERP snippet preview. The schema generator writes JSON-LD for the same pages, the robots.txt tester confirms the language folders aren't blocked, and the llms.txt generator covers AI crawlers.
Privacy
Everything is generated in your browser; nothing is uploaded.
Last checked and updated: . Everything on this page runs in your browser; nothing you enter is sent anywhere.
Frequently asked questions
What is hreflang?
Where do hreflang tags go?
<link rel="alternate" hreflang="…"> tags in the HTML <head>, xhtml:link entries in your XML sitemap, or an HTTP Link header (useful for PDFs). Google says the three are equivalent.Does every page need to list itself?
What is x-default?
Is it en-GB or en-UK?
Can I use just a country code, like hreflang="de" for Germany?
Do hreflang tags have to be absolute URLs?
Does hreflang work on Bing?
<meta http-equiv="content-language" content="de-de"> as well.How do I target Traditional or Simplified Chinese?
zh-Hant for Traditional and zh-Hans for Simplified Chinese, or a region such as zh-TW or zh-CN. This generator offers region codes; write a script code by hand if you need one.