Cadmeo

Hreflang Tag Generator

Where users whose language matches nothing should land.

Tags
<link rel="alternate" hreflang="en" href="https://example.com/" />
<link rel="alternate" hreflang="fr" href="https://example.com/fr/" />
<link rel="alternate" hreflang="x-default" href="https://example.com/" />

The hreflang tag generator builds a set of alternate link tags for a page that exists in several languages or regions, and checks it against the rules most often broken: invalid locale codes, relative URLs, duplicate locales, and a missing x-default.

How it works

hreflang tells a search engine which version of a page to show a given user. It does not affect ranking directly. It swaps which URL is shown, so a French user gets the French page rather than the English one competing with it.

  • The value is a language code, optionally with a region: en, en-GB, pt-BR. Language is ISO 639-1, region is ISO 3166-1 Alpha 2.
  • Region alone is invalid. There is no such thing as hreflang="uk" meaning the United Kingdom. Uk is the language code for Ukrainian.
  • URLs must be absolute, including the protocol. Relative URLs are ignored.
  • x-default names the fallback for users whose language matches none of the listed versions.

The set must also be reciprocal: every page in the group needs the same complete set of tags, including one pointing at itself. A page that lists alternates but is not listed by them is ignored.

Examples

A two-language set

Locales

en → https://example.com/, fr → https://example.com/fr/

x-default

https://example.com/

Result

<link rel="alternate" hreflang="en" href="https://example.com/" />
<link rel="alternate" hreflang="fr" href="https://example.com/fr/" />
<link rel="alternate" hreflang="x-default" href="https://example.com/" />

Three tags for two languages. The same three go on both pages, unchanged, including on the French page, which must still list the English version and itself.

A common invalid code

Locale

uk

Result

Flagged: "uk" is the language code for Ukrainian, not a region code for the United Kingdom

The correct value for English as used in the United Kingdom is en-GB. This mistake silently sends UK users to a Ukrainian-targeted page.

Frequently asked questions

Why does every page need to list itself?

Because hreflang annotations must be reciprocal, and the self-reference is what confirms a page belongs to the group. A page that names alternates without naming itself is treated as unconfirmed, and the whole set is likely to be ignored.

What is x-default actually for?

It names the page to show users whose language matches none of your versions. Without it, someone browsing in Japanese on a site offering English and French gets whichever version the search engine guesses. It is usually the language-selector page or the primary version.

Can I use a region code on its own?

No. The first part must be a language. "uk" is Ukrainian, not the United Kingdom; "en-GB" is what you want. This is the single most common hreflang error and it fails silently.

Should hreflang go in the head, the HTTP header or the sitemap?

Any of the three works, but pick one. Head tags are the most visible and easiest to audit; sitemap annotations scale better for very large sites; HTTP headers are for non-HTML files like PDFs. Mixing methods leads to sets that disagree with each other.