Developer and Text Tools

Hreflang Explained: Codes, Return Links and x-default Without the Headache

How hreflang tells search engines which language version to show, the rules every set must follow, the usual mistakes and how to validate your tags.

Saizul Amin
Saizul Amin3 Nov 2026 · 4 min read
Hreflang Explained: Codes, Return Links and x-default Without the Headache

A site with the same page in several languages or for several countries has a problem: search engines may show the wrong version. A reader in Germany lands on the English page, a Canadian sees prices in pounds. Hreflang annotations solve this by telling search engines that a group of URLs are equivalent pages for different audiences, and which audience each one is for.

The idea is simple. The details are where most sites fail.

The rules of a valid set

Think of each page and its translations as a set. For a pricing page in English, British English, German, Canadian French and Latin American Spanish, the set has five URLs. Every one of those five pages must list all five URLs, including itself. That self-reference is required, and so is the return link: if the English page points to the German page, the German page must point back. When a return link is missing, search engines may ignore the pair.

Each entry has a code and an absolute URL. The code is a language from ISO 639-1, such as en, de or fr, optionally followed by a region from ISO 3166-1, such as gb, ca or at. The special region 419 means Latin America. Scripts can be added when needed, for example zh-Hant for traditional Chinese.

Finally, x-default names the page to use when no version matches the reader's language. It is often the main language or a language chooser.

The mistakes that keep appearing

The single most common error is en-uk. The ISO code for the United Kingdom is GB, so the correct value is en-gb. Close behind come country codes used as languages, such as jp for Japanese (it should be ja) or se for Swedish (sv), underscores instead of hyphens as in en_US, relative URLs, tags placed in the body instead of the head, and sets that differ from page to page because one template was updated and another was not.

Another quiet problem is canonical tags. Each language version should have a canonical pointing to itself. If the German page canonicalises to the English one, search engines treat it as a duplicate and the hreflang set loses its meaning.

Three places to put the tags

Hreflang can live in three places. Link elements in the HTML head are the most common. An HTTP Link header works for files without a head, such as PDFs. An XML sitemap can carry the whole set under each URL with xhtml:link elements, which suits large sites where changing templates is hard. Pick one method per URL to keep maintenance simple.

Building sets with the generator

The Hreflang Tag Generator and Validator keeps each page as a set of rows, one per version. Type a code and URL per row, or generate a whole set from a pattern such as https://example.com/[code]/pricing plus a list of codes. Every code is checked as you type and labelled in plain words, for example English (United Kingdom) or Spanish (Latin America), so a wrong code stands out immediately. It warns about en-uk and similar traps, missing x-default, relative URLs and duplicate codes, and it suggests adding a plain language version when only regional ones exist.

Output is available as HTML link elements, as an HTTP Link header or as a sitemap that covers all your sets.

Validating what is live

On the validation tab, paste the source of several pages, each after a line with three equals signs and its URL, or paste a sitemap that already contains hreflang entries. The validator checks codes, duplicate codes pointing to different URLs, relative hrefs, tags in the body, missing self-references, sets that differ between versions and missing return links between the pages you pasted. The result can be opened in the builder, fixed and exported again.

Codes are checked against the language and region names built into your browser, plus a short list of common mistakes, so no big code tables are involved.

An example

A software company has a pricing page in five versions. The validator, given the English and German page sources, finds three problems: the English page uses en-uk, the German page's set leaves out the British URL, and the German x-default is a relative path. All three are template issues, so one fix repairs every page.

Limits

The tool cannot fetch pages, because browsers block reading other sites, so it checks what you paste. Return links to pages you did not paste are reported as unchecked. Hreflang is a hint rather than an order: blocked pages, wrong canonicals or strong signals elsewhere can still lead search engines to show another version.

Completely freeNo cost, no sign-up
Files stay privateEverything runs in your browser
Easy in your languageAvailable in many languages