How to use the hreflang generator tool
- In the Locale and absolute URL, one pair per line box, write a language tag, a space, then the full URL of that version.
- Add one line per language or region version, plus an x-default line for the fallback page if you have one.
- Select Generate tags, or select Example to load three sample lines.
- Select Copy and paste the link elements into the head of every page in the set.
What hreflang tags tell search engines
A link element with rel alternate and an hreflang attribute says: this URL holds the same content for another language or region. Search engines use the set to send a searcher to the matching version. The value x-default marks the page to use when no listed language fits.
The annotations only work as a complete, mutual set. Google's documentation states that each version must list itself and all other versions, and that tags are ignored when two pages do not point to each other. That is why the same block goes on every page in the group.
A worked example of the hreflang generator
Four lines go in and four link elements come out, in the same order. Note the casing: en-us and en-gb were typed in lowercase and are written as en-US and en-GB. Google treats hreflang values as case-insensitive, so this is a matter of convention, with the region code in capitals.
Input:
en-us https://example.com/us/
en-gb https://example.com/uk/
de https://example.com/de/
x-default https://example.com/
Result:
<link rel="alternate" hreflang="en-US" href="https://example.com/us/">
<link rel="alternate" hreflang="en-GB" href="https://example.com/uk/">
<link rel="alternate" hreflang="de" href="https://example.com/de/">
<link rel="alternate" hreflang="x-default" href="https://example.com/">Validation and normalization rules
Every line is checked before any output is produced. The first problem found stops the run with a message.
- A line needs exactly two parts separated by spaces or tabs. Otherwise you see Use one locale and URL per line.
- Blank lines are skipped.
- Language tags are checked with the Intl.getCanonicalLocales function of the browser, which accepts well-formed BCP 47 tags (RFC 5646) and fixes their casing, so zh-hans-cn becomes zh-Hans-CN.
- Underscore forms are not valid. en_US gives Invalid language tag: en_US.
- x-default is accepted in any letter case.
- The same tag on two lines, compared after normalization, is reported as a duplicate.
- URLs must be absolute http or https addresses without a user name or password. An ampersand in a URL is written as & inside the href.
What the tool does not check
Well-formed is not the same as supported. Google reads a language code from ISO 639-1, optionally followed by a region code from ISO 3166-1 Alpha 2, and says other codes such as es-419 are not supported. A region on its own, like us, is not a valid way to target a country either. This tool accepts es-419, and it accepts any tag with a correct shape, even a made-up one.
Canonicalization can also replace a tag. Deprecated codes are mapped to their current form, so iw is written as he, and the exact mappings depend on the browser. Finally, the tool never requests your URLs. It cannot tell whether a page exists, redirects or carries the matching return tags.
Frequently asked questions
Where do I put hreflang tags?
In the head element of each page in the language set. The same information can also be sent as an HTTP Link header or listed in an XML sitemap. This tool produces the HTML link elements only.
What is x-default in hreflang?
It is a reserved value for the fallback page, shown to users whose language or region matches none of the other entries. A language selector page or the main international version is the usual choice. Add it as a line like x-default https://example.com/.
Should I write en-US or en_US?
Use a hyphen. Language tags follow BCP 47, which separates subtags with hyphens. The underscore form comes from operating system locale names and is rejected by this tool as an invalid language tag.
Do I need a tag that points to the page itself?
Yes. Each page lists every version including its own URL. Generate the block once with all versions in it and place the identical block on all of the pages.
Does the generator check that my URLs exist?
No. It runs entirely in your browser and makes no network requests. It verifies the format of each URL, not whether the page loads, so test the live pages separately.