TapCub is live — analytics, insights and live chat, free on one platform
Glossary

Hreflang: what it is and how to set it up correctly

Hreflang links the language and regional versions of a page. Valid codes, the reciprocal rule, x-default, three implementation methods, a six-language size example and a validation checklist.

Lucas Hayes Reviewed by Xu An Also called hreflang tags Last updated Dec 3, 2026 Glossary

Quick answer

Hreflang is an annotation that connects the language and regional versions of a page so search engines can show each searcher the right one. Every version lists all versions, itself included, as language or language-region codes with full URLs, in HTML, HTTP headers or a sitemap.

What is hreflang?

Hreflang is an annotation that connects the language and regional versions of one page, so that a search engine can show a searcher the version meant for them. Each annotation has two parts: a language code, optionally with a region, and the full URL of that version. A German page, its English twin and its Japanese twin each carry the same list.

The word comes from the hreflang attribute on web links, which is a hint about the language of the page being linked to. In search engine work it almost always means the combination rel="alternate" plus hreflang, as described in Google's documentation on localized versions.

Two limits are worth knowing first. Hreflang does not translate anything, and Google does not use it, or the HTML lang attribute, to detect what language a page is written in. It only tells Google which pages belong together and who each one is for.

Hreflang syntax and language codes

The basic element goes in the <head>:

<link rel="alternate" hreflang="en-GB" href="https://example.com/uk/pricing" />

The value is a language code from ISO 639-1, optionally followed by a region code from ISO 3166-1 alpha-2, joined by a hyphen. A script code from ISO 15924 can be written for Chinese. Google reads the value without regard to case, though regions are conventionally upper case. The URL must be fully qualified, including https://.

ValueValid for Google?Meaning or problem
enYesEnglish, any region
en-GBYesEnglish for users in the United Kingdom
de-CHYesGerman for users in Switzerland
zh-HansYesChinese in simplified script
zh-Hans-USYesSimplified Chinese for users in the United States
x-defaultYesFallback when no listed language or region matches
en-UKRegion ignoredUK is a reserved code; the United Kingdom is GB
jpNojp is a country code; the Japanese language is ja
be aloneWrong targetbe is the Belarusian language, not Belgium
US aloneNoA region cannot be given without a language
es-419NoNumeric regional codes are not supported

Belgium shows why the order matters: nl-BE, fr-BE and de-BE are three audiences in one country.

The reciprocal rule and self-reference

Google states two requirements for every method. Each language version must list itself as well as all other versions. And if two pages do not point to each other, the tags are ignored. The second rule stops a stranger from declaring their page to be the French version of yours.

Sample data: a pricing page exists in English, German, French and Japanese. A crawl returns these annotations:

PageLists enLists deLists frLists ja
enYes (self)YesYesYes
deYesYes (self)YesYes
frYesYesNo (self missing)No
jaYesYesYesYes (self)

Four versions form 4 × 3 ÷ 2 = 6 pairs. Five pairs link in both directions: en–de, en–fr, en–ja, de–fr and de–ja. The pair fr–ja fails, because Japanese points to French but French does not point back. The French page also leaves itself out. Both errors sit in one template, so the fix is to generate the same complete list for all four pages from one table of URLs.

If keeping a full set across many languages gets hard, Google says you may omit some languages on some pages, and the pairs that do point to each other are still processed. Link new language versions both ways with your main language first.

What is x-default?

x-default is a reserved value for the page to use when a searcher's language settings match none of your versions:

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

Google says it was designed for language selector pages and works best with them, although any page can carry it. The same URL may appear twice in a set, for instance as both en and x-default, when the English page is your fallback. It needs no language code of its own.

A rule for picking it: if you have a page where visitors choose a country or language, point x-default there. If you do not, point it at the version a stranger is most likely to be able to use. If you serve several regions in one language, such as en-IE, en-CA and en-AU, Google also advises a generic en page for everyone else who reads English.

Three ways to implement hreflang

Google treats three methods as equivalent. Pick one; using several brings no benefit in Search and is harder to keep consistent.

MethodWhereBest forCost
HTML <link> elements<head> of every versionSmall sites, CMS templatesEvery page grows with each new language
HTTP Link headerServer responsePDF and other non-HTML filesNeeds server configuration; invisible in page source
XML sitemap with xhtml:linkSitemap fileLarge sites, many languagesA build step must keep the file complete

A header version for a PDF looks like this:

Link: <https://example.com/guide.pdf>; rel="alternate"; hreflang="en",
      <https://example.com/de/guide.pdf>; rel="alternate"; hreflang="de"

In a sitemap, add the namespace xmlns:xhtml="http://www.w3.org/1999/xhtml", create one <url> entry per URL, and give each entry the full list, itself included:

<url>
  <loc>https://example.com/de/pricing</loc>
  <xhtml:link rel="alternate" hreflang="en" href="https://example.com/pricing"/>
  <xhtml:link rel="alternate" hreflang="de" href="https://example.com/de/pricing"/>
</url>

The English URL then gets its own entry with the same two child lines.

Worked example: how big does a six-version site get?

Sample data: 1,200 pages, each published in six language versions, plus an x-default annotation.

QuantityCalculationResult
URLs1,200 × 67,200
Annotations per URL6 versions + x-default7
Annotations in total7,200 × 750,400
Version pairs that must link both ways, per page6 × 5 ÷ 215
Pairs across the site1,200 × 1518,000
Sitemap size at about 101 bytes per annotation line plus the URL entriescomputed on sample URLsabout 5.7 MB uncompressed

The sitemap protocol allows 50,000 URLs and 50 MB (52,428,800 bytes) uncompressed per file. Google notes that the xhtml:link children do not count toward the URL limit, so these 7,200 entries fit in one file, although splitting by section makes errors easier to locate. In HTML, the same site adds 7 lines to each head, about 650 bytes at this URL length. With 30 languages plus x-default it would be 31 lines on every page, which is the point where many teams move to the sitemap.

The 18,000 pairs also explain why hand editing fails: one language template that leaves out one other language breaks 1,200 pairs at once.

How to validate hreflang: a checklist

Work through these in order, on a sample of templates rather than random pages:

  1. Self-reference. Every version lists its own URL.
  2. Return links. For every A → B there is a B → A.
  3. Codes. Language from ISO 639-1, region from ISO 3166-1 alpha-2; no UK, EU or UN.
  4. Full URLs. Scheme and host included, no relative paths.
  5. Targets. Each URL returns 200, is allowed to be indexed and is not a redirect.
  6. Canonicals. Each version's canonical is in its own language. A German page that declares the English URL as canonical sends a contradictory signal.
  7. Placement. Elements sit inside a well-formed <head>, and hreflang is not combined with a media attribute in one tag.
  8. One method. HTML, header or sitemap, not a mixture that can disagree.
  9. Fallback. x-default exists where visitors with other languages need a landing place.

To see what one page sends, run curl -s URL | grep -o '<link[^>]*hreflang[^>]*>' for HTML and curl -sI URL | grep -i '^link:' for headers. A site-wide check needs a crawler that stores every annotation and then joins the pairs, as in the four-language table above.

Hreflang vs canonical vs the lang attribute

Hreflangrel="canonical"lang attribute
Question it answersWhich versions belong together, and for whom?Which of several copies is preferred?What language is this content?
RelationshipMany pages, all listing each otherDuplicates pointing at one targetDescribes a document or element
Read bySearch engines, for choosing a versionSearch engines, for choosing a representativeBrowsers and assistive technology
Typical errorMissing return linkTranslation pointing at the original languageLeft at the template default

Hreflang and canonical work together when each language version names itself as canonical and lists the others as alternates. Google counts localized versions as duplicates only when the main content stays untranslated, for example a translated menu around the same English body. For URL structure, localization and a full audit of a three-language site, see multilingual SEO.

Hreflang and visitor data in TapCub

Hreflang itself is checked with a crawler and Search Console; TapCub does not read or validate the tags. What it can show is whether people end up on the version meant for them. Suppose the French template above is fixed.

  1. Group the versions. In Web analytics › Pages, use Page groups with a prefix rule for each language folder, such as /fr/, to see pageviews and bounce rate per version.
  2. Compare language and country. Web analytics › Audience breaks visitors down by country and browser language. To see which version one country reaches, click that country in the geography list on Web analytics › Overview; the page list on the same screen is then filtered to it.
  3. Check search. With Google Search Console connected, Monitoring › Search performance splits clicks, impressions and position by page, query and country, usually one to three days late. Impressions from France that keep going to an English URL point back to a broken pair.
  4. Mark the release. Add a date note in Configuration › Annotations so that the before and after periods are easy to separate.

Sources

Was this explanation clear?

We use your answers to fix and expand this page.

Lucas Hayes

Data Engineer

Writes about event design, data quality, and collection workflows, with verifiable implementation methods for reliable analytics.

FAQ

Questions people ask

Short answers to the follow-up questions that come up most.

Still have a question?

Chat with the team behind TapCub — we usually reply within a few hours on business days.

Is hreflang a ranking factor?

Google describes it as a way to point searchers to the most appropriate language or regional version of a page, not as a way to raise rankings. It helps the right URL appear for the right audience. Content quality, links and relevance still decide whether any version ranks at all.

Do I need hreflang if my site has one language?

Only if you publish regional variants, for example separate English pages for the United States and the United Kingdom with different prices. A single page for one language needs no hreflang. The HTML lang attribute is still worth setting for browsers and assistive technology.

Why are my hreflang tags ignored?

The most common cause is a missing return link: page A names page B, but B does not name A. Others are invalid codes such as a country code used alone, relative URLs, targets that redirect or are noindexed, and tags that ended up outside the head.

Should hreflang go in the HTML or the sitemap?

Google treats both as equivalent, as well as HTTP headers. HTML suits a few languages on a CMS template. A sitemap suits large or many-language sites because pages stay light and one build step can generate every pair. Pick one method and keep it complete.

See this number on your own site

Add one script tag for web and apps, and the first reports fill in within minutes.

See your data clearly. Find your growth.

Every click, backed by data. Install one line of code and see your first numbers in a minute.

No credit card · Free plans for analytics and chat · Cookieless analytics