Skip to content

Glossary hreflang

What Is Hreflang? Definition, Code Example and Common Mistakes

Definition

Hreflang is an HTML attribute that tells search engines which language and which geographic region a specific URL is meant for. Sites with several language versions use it to signal which version should be shown to a visitor in London, Berlin or Madrid.

Two identically shaped enamel plaques, one blue one green, both blank — beside the title hreflang
Two identical plaques so nobody takes the wrong one
On this page 6
  1. How hreflang works, with a full code example
  2. hreflang vs. canonical: different jobs that still have to line up
  3. The redirect mistake: why an hreflang link must never point to a redirect
  4. Other common hreflang mistakes
  5. Best practices for implementing hreflang
  6. Common mistakes at a glance
In brief

The hreflang attribute, written in full as rel="alternate" hreflang="x", links several language or country versions of a page together. Google uses that link to pick the right version in search results, instead of showing, say, the Spanish page to someone searching in English. Technically it can be implemented three ways: as a link tag in the head, as an HTTP header, or as an entry in the XML sitemap. For most sites, the head is the most practical option. Important: hreflang does not replace translation or the canonical tag, it complements both, and it only works reliably when the two signals agree.

Two identically shaped enamel plaques, one blue one green, both blank — beside the title hreflang
Two identical plaques so nobody takes the wrong one

How hreflang works, with a full code example

A website with several language versions runs into a problem search engines cannot solve on their own: how does Google know that the German, Spanish and English versions of a page are the same content, just in a different language? Without an explicit signal, a search engine treats those three URLs as three separate, possibly even competing pages. That is exactly what hreflang addresses. The attribute groups every language version of a page together and, at the same time, states which language and, optionally, which country each version is meant for.

The value of the hreflang attribute follows a fixed syntax: first the language code in ISO 639-1 format, for example "en" for English or "de" for German, optionally followed by a hyphen and the region code in ISO 3166-1 Alpha-2 format, such as "en-GB" for English aimed at the United Kingdom or "es-MX" for Spanish aimed at Mexico. The order is mandatory: language first, region second, never the other way round. A value like "GB-en" is invalid and gets ignored. There is also a special value, "x-default", which marks the version shown when none of the defined language versions match a visitor's language or region, usually the international or English homepage.

The most common way to implement hreflang is as a group of link tags in the head of every page involved. That group must be identical across all versions: every page lists itself and every other version. Here is a complete block for a glossary entry with three language versions plus x-default, using our own domain as the example. The figure below shows the complete block for all three language versions.

This exact block, with the same four hreflang lines and the same canonical tag, needs to sit in the head of all three pages involved, not just the English one. The only thing that changes from page to page is the page's own canonical URL. On sites with many language versions, the head section quickly becomes hard to maintain; in that case, the XML sitemap is the better route, with each URL referencing its alternates through xhtml:link entries. For non-HTML documents such as PDFs, the correct method is the HTTP Link header with rel="alternate", since a PDF has no head section to place tags in.

Which of the three methods to pick depends mostly on the number of pages involved. A site with a few dozen multilingual pages can manage hreflang through link tags in the head without trouble, because mistakes can still be checked by hand. With several hundred or thousand URLs per language, the sitemap approach becomes far easier to maintain, since the mapping can be generated from a single data source instead of being kept in every template. Whichever method is used, the rule stays the same: the group has to be complete and internally consistent, or Google ignores the whole signal for those URLs.

One block, three pages — only the canonical line changes

hreflang vs. canonical: different jobs that still have to line up

Hreflang and the canonical tag are often confused because both live in the head and both work with URLs. Their jobs, though, are fundamentally different. The canonical tag says: out of several technically similar or identical URLs, this is the one version that should be indexed, for example when the same page is reachable both with and without tracking parameters. Hreflang, on the other hand, says: these pages are deliberately distinct language versions of the same content, all of them should be indexed, but each shown to the audience it is meant for.

Even so, the two signals have to work together. Every language version needs its own canonical tag pointing to itself. If the German version's canonical tag points to the Spanish URL, Google reads that as a signal that only the Spanish page should be indexed, and the entire hreflang group is effectively invalidated, because one of the supposedly equivalent language versions is marking itself as non-canonical. A common and easy-to-miss mistake is that the URL used in the hreflang attribute does not exactly match the URL used in that same page's own canonical tag, for instance because one has a trailing slash and the other does not. To Google those are two different URLs, even if a browser lands on the same page either way. The canonical URL and the hreflang self-reference need to match character for character.

Other common hreflang mistakes

Besides the redirect mistake, three other error types show up regularly in practice, all three explicitly named in Google's own list of common mistakes.

Missing return links are the single most frequent mistake. If the English version links to the Spanish version via hreflang, the Spanish version must link back to the English one, and both must also reference themselves. Google states this plainly in its official documentation: if two pages don't both point to each other, the tags will be ignored. A one-directional link is not a valid hreflang signal as far as Google is concerned, it simply gets skipped.

Incorrect language codes are the second major bucket. It's common to try using a region code without a language code, for example "GB" instead of "en-GB"; Google treats that as invalid, a region code on its own is not accepted. Equally common is reversing the order, for example "GB-en" instead of "en-GB". Both mistakes cause Google to ignore the affected entry.

Invalid region codes are the third bucket: some sites use codes that sound familiar but do not officially belong to ISO 3166-1 Alpha-2, such as "EU" for Europe, "UN" for the United Nations, or "UK" for the United Kingdom, when the correct code is "GB". Reserved or unassigned codes like these are not recognized by Google.

A fourth, less-discussed mistake involves blocked or excluded target pages: if an hreflang link points to a URL blocked by robots.txt or carrying a noindex tag, Google cannot evaluate that version, even if it returns a 200 status. From a search engine's point of view, a blocked page is not a valid target for a language signal, much like with a redirect, there simply is no reachable, indexable destination page.

Six mistakes that make an hreflang line worthless

Best practices for implementing hreflang

  • Every language version references itself and all other versions, including a consistent x-default for languages or regions not otherwise covered.
  • The URL used in hreflang matches the URL used in that page's own canonical tag character for character, including trailing slashes and letter case.
  • Every hreflang link points to a URL that returns a 200 status directly, never to a redirect and never to a URL carrying noindex.
  • After any URL structure change, every hreflang target URL gets re-checked for its actual status code, not just the new structure itself.
  • Language codes follow ISO 639-1, optional region codes follow ISO 3166-1 Alpha-2, always in the order language before region.
  • With many language versions, manage hreflang through the XML sitemap rather than individual link tags in the head, which keeps the head lean and cuts down on manual errors.

Common mistakes at a glance

  • An hreflang link points to a URL that itself redirects with a 301 or 302, instead of the final destination page.
  • Missing return links: page A links to page B via hreflang, but B does not link back to A.
  • Language and region codes swapped, for example "GB-en" instead of "en-GB".
  • A region code given without an accompanying language code, which Google does not accept.
  • Reserved or invalid region codes such as "EU", "UN" or "UK" used instead of the correct country code.
  • The hreflang URL and the canonical URL of the same page differ slightly, for instance through a missing or extra trailing slash.
Manuel Riveiro Rodriguez CEO & Digital Strategist

A technical audit covers this and everything else in one pass.

Request an audit

Frequently asked

Is hreflang a ranking factor?

No. Hreflang does not affect how well a page ranks, only which language version of an already-ranking page group gets shown to a given user. If hreflang is missing entirely, the wrong language version might get shown, but that does not directly hurt the domain's overall ranking.

Is a single hreflang entry per page enough?

No. Every page in the group has to include the full list of all language versions, including a reference to itself. A page that links to another version but does not appear in that version's own list creates a missing return link, and Google ignores the entire entry.

Does hreflang have to go together with translated content?

In practice, yes. Hreflang marks genuine language versions, not a plain language switch without any content adaptation. If the same page with identical text is simply tagged under a different language code, that is not a meaningful use of hreflang and can be read as a misleading signal.

How do you check whether an hreflang setup is correct?

The most reliable way is a crawling tool that visits every URL listed in hreflang directly and reads its actual status code and its own canonical tag, rather than trusting what the source code claims. Google Search Console adds to this with warnings about missing return links.

What happens if a language version of a page doesn't exist yet?

It simply gets left out of the hreflang group. An hreflang link pointing to a URL that doesn't exist yet, or that returns a 404, is a mistake in its own right and should only be added once that page is live and reachable.