Free GA4 auditCheck

Hreflang

Definition

Hreflang is an attribute that tells a search engine about the language and regional versions of the same page. It lets Google show users the version that matches their language or country, e.g. Polish instead of English. Hreflang is used on multilingual sites and in online stores operating in several markets. The attribute value consists of a language code and, optionally, a region code, e.g. pl or en-GB.

Hreflang is not used to detect the language of a page. Google states that it uses neither hreflang nor the HTML lang attribute for that, but its own algorithms. The attribute only indicates which URLs are equivalents of each other in other languages.

How to implement hreflang?

Hreflang is implemented in one of three ways, which according to Google are equivalent. The choice depends on what is easiest on a given site and CMS.

MethodWhere the annotation goesWhen it works best
<link> elements in HTMLIn the <head> section of each page versionRegular HTML pages
HTTP Link headerIn the server responseNon-HTML files, e.g. PDF
XML sitemapxhtml:link elements for each URLLarge sites with many versions

HTML example

Each page version contains a full set of <link> elements, one for every variant, including itself. Google stresses that this set is identical on all versions.

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

With many language versions it is easier to keep the annotations in the XML sitemap. The page code then does not grow by dozens of links in every <head> section.

How to implement hreflang?

Which codes and rules apply to hreflang?

The hreflang value is a language code in ISO 639-1 format, optionally followed by a region code in ISO 3166-1 Alpha 2 format. The two codes are separated by a hyphen. Google supports only codes from these two standards. A code outside them, e.g. es-419 for Latin America, is not supported.

ValueMeaning
plContent in Polish, regardless of country
deContent in German, regardless of country
en-GBContent in English for users in the United Kingdom
fr-BEContent in French for users in Belgium
x-defaultFallback page for unmatched languages

The first code always denotes the language. Google gives an example of a mistake: be is the code for the Belarusian language, not for Belgium.

The x-default value

The reserved x-default value points to the page for users whose language settings do not match any version. Google recommends it especially for language selector pages and home pages with automatic redirection. No language code is given with x-default.

Each language version must point to itself and to all other versions. If page X links to page Y, page Y must link back to X. According to Google, annotations without this reciprocity may be ignored. URLs must be fully qualified, with the protocol, e.g. https://example.com/foo, not /foo.

Which errors most often break hreflang?

Hreflang most often stops working because of missing return links, wrong codes or incomplete URLs. Each of these errors follows directly from the requirements in Google's documentation. That is why checking hreflang annotations is a standard part of an SEO audit of multilingual sites.

  • a missing return link, when page Y does not point to page X, so the annotations may be ignored;
  • no self-reference in the set of versions;
  • a region code alone without a language code, or a country code in place of the language code;
  • codes outside the ISO 639-1 and ISO 3166-1 Alpha 2 standards;
  • relative URLs instead of full URLs with the protocol.

What doesn't hreflang do?

Hreflang does not detect the language of the content and does not replace translation. Google determines a page's language with its own algorithms, independently of this attribute. Hreflang only indicates the relationships between versions. When adding new languages to a site, Google recommends that new versions link bidirectionally at least to the main version. Other pairs that point to each other are still processed by Google.

Frequently asked questions

Q.Is hreflang needed on a single-language site?

No, hreflang only makes sense when the same content exists in several language or regional versions. A page available only in Polish has no equivalents to point to. The attribute connects different versions of the same page. Without a second version there is nothing to connect.

Q.Which hreflang implementation method is best?

According to Google, the three methods are equivalent: <link> elements in HTML, the HTTP header and the XML sitemap. The choice depends on how the site is built. The HTTP header works for PDF files, and the XML sitemap for a large number of versions. What matters is applying the chosen method consistently.

Q.What happens when a return link is missing?

Google may then ignore the hreflang annotations for that pair of pages. The documentation requires page Y to point to page X if X points to Y. Pairs that link to each other are still processed by Google. That is why an error on one page does not disable the whole implementation.

Q.What is x-default for?

The x-default value points to a fallback page for users whose language does not match any version of the site. Google designed it with language selector pages in mind. It also works on home pages with automatic redirection. No language code is given with this value.

Contact

Let's talk growth

Send a brief or drop your contact. We'll reply within 24h.

Get a quote
Paweł Strzelecki and Karol Majewski, co-founders of Zest