Hreflang Tag Generator

Build hreflang annotations for every language and region version of a page, as HTML tags, an HTTP header, or an XML sitemap. It checks your codes as you type and flags the mistakes Google says will make the tags be ignored.

LanguageRegionURL of that version

Language codes use ISO 639-1 and region codes use ISO 3166-1 Alpha 2. Leave the region blank to target a language everywhere. The same generated set belongs on every version of the page, including the page it is generated from.

What hreflang actually does

Hreflang tells a search engine that several pages are the same content in different languages or for different regions, and which one to show to which audience.

It is not a redirect and it is not a ranking boost. A visitor in France still reaches whichever URL they clicked. What the annotation changes is which version Google chooses to put in front of them in the first place.

It also helps with a quieter problem. Three near-identical English pages for the US, UK and Australia look like duplicate content. Hreflang tells Google they are deliberate alternates rather than the same page published three times.

The three ways to implement it

Google supports three methods and states that “the three methods are equivalent from Google’s perspective”. Pick one. Using all three gives no benefit in Search and makes maintenance harder.

  • HTML tags in the <head> of each page. Easiest to read and to debug, and the usual choice for a handful of versions.
  • HTTP headers, which is the only option for non-HTML files such as PDFs.
  • XML sitemap entries. Best at scale, because you maintain one file instead of editing every page.

Source: Google Search Central. The generator above outputs all three, so you can see the same set in each shape before choosing.

The rule that breaks most setups: return links

This is the one that silently wastes everyone’s time. Google is blunt about it: “If two pages don’t both point to each other, the tags will be ignored.”

Every version must reference every other version, and each version must also list itself. The result is that the annotation set is identical on all of them, which is why the generator produces one block rather than a different block per page.

So if your German page points at the English one and the English page does not point back, you do not have a partially working setup. You have one that Google ignores.

The practical check after you deploy: open two different language versions and confirm the hreflang block is byte-for-byte the same on both.

Getting the codes right

Most broken hreflang is a bad code rather than bad logic, and Google names the specific failures.

  • Language is ISO 639-1, region is ISO 3166-1 Alpha 2. Google says only codes from those lists are supported.
  • A region on its own is invalid. In Google’s words, “You can’t specify the country code by itself.” It is en-GB, never GB.
  • UK is not a country code. Google states that using EU, UN or UK in hreflang annotations has no effect on Google Search. The United Kingdom is GB, and this is the single most common mistake in the whole feature.
  • Case does not matter. Google says the hreflang value is case insensitive, so en-gb and en-GB behave the same. Pick one style for readability.
  • Script codes use ISO 15924 where you need them, such as zh-Hant and zh-Hans.

The generator flags the region-only and UK cases as you type, because both produce annotations that look right and do nothing.

What x-default is for

Google describes x-default as the value “used when no other language/region matches the user’s browser setting”. It is your fallback for everyone you have not explicitly covered.

It does not take a language code, and it is particularly suited to a language selector page or a global homepage that redirects people onward.

It is optional, and worth adding whenever your set does not cover the whole world, which is almost always.

Which method to choose

If you have a few language versions and can edit templates, use the HTML tags. They are visible in the page source, which makes problems obvious.

If you have many pages, use the sitemap. Editing a hundred page templates every time you add a language is how sets drift out of sync, and a drifted set means missing return links, which means ignored tags.

Use HTTP headers when the file is not HTML. A PDF has no head to put a tag in.

Common mistakes

  • Missing return links. The tags are then ignored entirely rather than partially applied.
  • Forgetting the self-reference. Each version must list itself as well as the others.
  • Using UK instead of GB, or EU, which Google says has no effect.
  • A region code on its own, which is invalid.
  • Pointing at URLs that redirect, or at pages that are noindexed, which sends contradictory signals.
  • Mixing methods. Tags in the head and entries in the sitemap doubles the maintenance for no gain.
  • Relative URLs. Use the full absolute URL for every version.

Hreflang problems are rarely visible on the page, so they survive for months. It belongs on the list of things to verify after any migration, alongside the rest of your technical SEO checklist, and it is worth re-checking whenever pages stop being indexed as you expect, which our note on crawled, currently not indexed covers.

Frequently asked questions

What is an hreflang tag?

An hreflang annotation tells search engines that several URLs are the same content in different languages or for different regions, and which version suits which audience. It does not redirect anyone and it does not raise rankings. It changes which version Google chooses to show, and it stops near-identical regional pages from looking like duplicate content.

Do I need return links for hreflang to work?

Yes, and this is the most common reason a setup does nothing. Google states that if two pages do not both point to each other, the tags will be ignored. Every version must reference every other version and must also list itself, which means the same annotation set appears on all of them.

Should I use UK or GB in hreflang?

GB. Google states that using EU, UN or UK in hreflang annotations has no effect on Google Search, because region codes must come from ISO 3166-1 Alpha 2 and UK is not in that list. The correct annotation for English in the United Kingdom is en-GB.

Can I use a country code on its own?

No. Google says you cannot specify the country code by itself, so an annotation of just GB or FR is invalid. You need either a language on its own, such as en, or a language and region pair, such as en-GB.

What does x-default do?

It is the fallback used when no other language or region in your set matches the visitor's browser setting. It does not take a language code and is well suited to a language selector page or a global homepage. It is optional, but worth adding whenever your versions do not cover every audience.

Which hreflang method is best: tags, headers or sitemap?

Google says the three are equivalent, so choose on maintenance rather than effectiveness. HTML tags suit a small number of versions and are easy to debug in the page source. A sitemap suits many pages, because you edit one file instead of every template. HTTP headers are for non-HTML files such as PDFs.

This tool runs entirely in your browser. Nothing you type is sent anywhere or stored. The rules it checks against come from Google Search Central's documentation on localized versions of a page.