Hreflang Tag Generator

List each language or regional version of a page and get the hreflang tags for it, in HTML or XML sitemap form — with the code mistakes that quietly break the whole set caught as you type.

Language versions

Where to send visitors whose language matches none of your versions. Usually your main or language-picker page.

What the generator checks, and the rules behind it

Each row becomes one hreflang annotation. The language must be a real ISO 639-1 code and the region must be two letters, so most of the usual mix-ups get flagged before they ship: cn for Chinese (that's not a language code, you want zh-CN) and jp for Japanese (the language is ja) are rejected with the code you probably meant, while a bare uk raises a warning because it is valid but means Ukrainian, not the United Kingdom (you want en-GB). Duplicate language-region pairs and relative URLs are rejected too, since both invalidate the set. The region is only checked for being two letters, not looked up in the ISO list, so en-UK is not caught; the table below shows what is and isn't.

The output is written for you to paste onto every page in the group, unchanged. That's deliberate: the block lists every version in the set, so each page carries a tag pointing at itself as well as at the others, which is what makes the annotations reciprocal and therefore valid. Everything runs in your browser and nothing is uploaded.

The rules a valid hreflang set follows

Hreflang is only trusted where the references agree with each other. These are the conditions that matter:

  • Every page lists itself. Each page in the set carries a tag for its own URL, not only for its translations.
  • Every pair points both ways. If page A names page B as an alternate, B must name A back. One-way references are ignored.
  • The set is identical on every page. Same codes, same URLs, in whichever method you use.
  • Language first, region optional. An ISO 639-1 language (en), optionally followed by an ISO 3166-1 alpha-2 region (en-GB). A region can never stand alone.
  • Every URL is absolute, canonical and live. A full https:// address that returns 200, can be indexed, and is its own canonical rather than a redirect, a noindex page or a page canonicalised to another language.
  • x-default is optional. It names the fallback page for visitors who match none of your versions.

Worked example: a site with three versions

A site has a US English home page, a UK English version and a German version. These are the rows to enter, with the home page as the x-default:

LanguageRegionURL for that version
enUShttps://example.com/
enGBhttps://example.com/uk/
de(blank)https://example.com/de/
x-defaultn/ahttps://example.com/

The HTML head tab produces this block:

<link rel="alternate" hreflang="en-US" href="https://example.com/" />
<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/" />

Paste it unchanged into the <head> of all three pages. Each page now has a tag for itself and a tag for each of the others, so every pair points both ways. The XML sitemap tab produces a single entry, built around the first row:

<!-- Requires xmlns:xhtml="http://www.w3.org/1999/xhtml" on the <urlset> element -->
<url>
  <loc>https://example.com/</loc>
  <xhtml:link rel="alternate" hreflang="en-US" href="https://example.com/" />
  <xhtml:link rel="alternate" hreflang="en-GB" href="https://example.com/uk/" />
  <xhtml:link rel="alternate" hreflang="de" href="https://example.com/de/" />
  <xhtml:link rel="alternate" hreflang="x-default" href="https://example.com/" />
</url>

For a sitemap, add one <url> entry per version (here /, /uk/ and /de/), changing only the <loc> and keeping the xhtml:link lines identical. The set describes one page: the pricing page and its translations are different URLs, so run the generator again for them.

Choosing an implementation method

MethodBest whenTrade-off
HTML <link> tags in the headYou control the page templates and the site has a manageable number of pages.Adding a language means editing every existing version, and each page carries one tag per version.
XML sitemap with xhtml:linkThe site is large, or you cannot edit page heads in your CMS or hosting.Each version needs its own entry, and one sitemap file holds at most 50,000 URLs, so three versions of every page cap a file at roughly 16,600 pages. The markup is also invisible in view source.
HTTP Link headerThe files have no head, mainly PDFs.Set in the server or CDN configuration. This generator produces only the HTML and XML forms, not the header.

Pick one method per set of URLs: two sources that disagree are worse than one. The hreflang guide has a sitemap and a header example.

Common hreflang mistakes, and what this generator does about them

MistakeWhy it breaksThis generator
Missing return linkThe pair is ignored.Cannot see it: it builds a set but fetches no pages. Check each live version with the Hreflang Validator.
Page leaves itself out of the setEach version is expected to list itself as well as the others.Not checked. Include the page you are pasting onto as one of the rows.
en-UK instead of en-GBUK is not the ISO code for the United Kingdom, so the region is not recognised.Not caught. Any two-letter region is accepted.
jp, cn, gb, us or dk as a languageThese are country codes, not language codes.Rejected, with the code you probably meant. A bare uk gets a warning.
es-419 or a region on its ownA language is required, and the region must be a country code.Rejected: a blank language and a region that is not two letters are both errors.
Relative URLs, or the same code twiceAlternates must be fully qualified and unambiguous.Rejected.
Alternate that redirects, returns 404, is noindex or is canonicalised elsewhereGoogle can ignore those annotations.Not checked. Test each URL with the Redirect Chain Checker and the Canonical URL Analyzer.
Script subtags such as zh-HantValid in hreflang, but the region slot only takes two letters here.Cannot be produced. Use zh-TW or write that tag by hand.
& inside a URL in the XML outputAn unescaped ampersand makes the sitemap invalid XML.Not escaped for you. Write &amp; yourself in the XML.
Redirecting visitors by IP or browser languageCrawlers may never reach the other versions.Out of scope. Offer a language picker or a banner instead of redirecting.

Frequently asked questions

Does every page need the full set of tags, or just the main one?

Every page in the set needs the complete block, including a tag pointing at itself. Hreflang annotations have to be reciprocal: if your Spanish page claims the English page as an alternate but the English page doesn't claim the Spanish one back, Google ignores the whole relationship. This is by far the most common reason hreflang silently does nothing.

What is x-default actually for?

It's the fallback for visitors whose language and region match none of your versions. A Japanese speaker hitting a site that only has English, Spanish, and German versions gets the x-default page. Most sites point it at their main English page or a language-picker landing page. It's optional, but without it search engines guess.

Can I use a region code on its own, like just GB?

No. Hreflang always needs a language, and the region is optional on top of it. "en-GB" is valid, plain "en" is valid, plain "GB" is not. A related trap: the language part is ISO 639-1 and the region is ISO 3166-1, and they disagree in places. The United Kingdom is GB, not UK, and "uk" on its own is the language code for Ukrainian.

Should these go in the HTML or the sitemap?

Either, but pick one and use it consistently. HTML tags in the head are easier to reason about and to spot-check by viewing source. The XML sitemap form keeps the markup out of your templates entirely and scales better across thousands of URLs, at the cost of being invisible unless you go looking at the sitemap. Don't do both, as conflicting sets are worse than one.

Do hreflang tags help my rankings?

Not by themselves. What they do is make sure the right version of a page gets shown to the right audience, which improves click-through and reduces the bounce that comes from landing on a page in the wrong language. They also stop your regional variants from being treated as duplicate content competing with each other.

Do I run the generator once for the whole site?

No, once per page. Hreflang describes the equivalents of one specific page, so your home page and its translations are one set, and your pricing page and its translations are another with different URLs. For the HTML option, paste the output unchanged into the head of every page in that set. For the XML sitemap option, the tool prints one <url> entry whose <loc> is the first row you entered; repeat that entry once per version, changing only the <loc> and leaving the xhtml:link lines the same.

Will the generator warn me if I type en-UK?

No. It checks that the language is a real ISO 639-1 code and that the region is two letters, but it does not look the region up in the ISO 3166-1 list, so en-UK is accepted and output as written. The United Kingdom's code is GB, so the correct tag is en-GB. The tool does reject the common language mix-ups such as jp and cn, and it warns on a bare uk, which is valid but means Ukrainian.

Can the alternate versions live on different domains or subdomains?

Yes. A set can mix a country domain such as example.de, a subdomain such as de.example.com and a subfolder such as example.com/de/. Every URL still has to be absolute, and the reciprocal rule still applies: each version must list all the others, on whichever domain it lives. The generator accepts any absolute http or https URL in each row, so you can enter them exactly as they are.

What if a page has no translation in one of my languages?

Leave that language out of that page's set. Hreflang should only point at real, equivalent pages, so do not send a missing translation to the home page or to a redirect. If the pricing page exists in English and German but not Spanish, its set contains the English and German URLs only, while a page that exists in all three lists all three. Add the missing entry, on every page in the set, when the translation is published.

Related tools

We use cookies to analyze site usage and improve your experience. You can decline non-essential cookies. Privacy Policy