Question

Hreflang Implementation for Multilingual Websites

8 min read

Short answer

Hreflang tells Google which URL is the right version of a page for a given language, or for a language in a given region, so it can show searchers the version that fits them. Three rules decide whether it works: every version lists itself and all the others, every pair of pages points to each other, and every code is a valid ISO language code with an optional ISO region code. Hreflang doesn't translate anything, doesn't tell Google what language a page is in, and isn't checked by any Search Console report today, so validation is your job.

Sources

  1. 1developers.google.com
  2. 2developers.google.com

Ask next

What Hreflang Does and Doesn’t Do

Google’s guide to localized versions of a page says the purpose is to “help Google Search point users to the most appropriate version of your page by language or region.” It recommends hreflang when:

  • only the template is translated and the main content stays in one language, which Google says forums with user-generated content typically do;
  • content in one language has small regional variations, such as English pages for the US, Great Britain and Ireland;
  • the site is fully translated into several languages.

What it doesn’t do:

  • It doesn’t detect language. “Google doesn’t use hreflang or the HTML lang attribute to detect the language of a page; instead, we use algorithms to determine the language.”
  • It doesn’t make translated pages duplicates or unique. “Localized versions of a page are only considered duplicates if the main content of the page remains untranslated.”
  • It isn’t required for discovery. Google says it “might still find alternate language versions of your page,” but that “it is usually best for you to explicitly indicate your language- or region-specific pages.”

Language and Region Codes

A value is a language code, optionally followed by a region code: en, en-GB, de-CH. Google’s rules:

  • “Only language codes listed in ISO 639-1 and region codes listed in ISO 3166-1 Alpha 2 are supported”. Codes outside those lists, “such as es-419, aren’t supported.”
  • “You can’t specify the country code by itself.” be is Belarusian, not Belgium; Belgian pages in German, Dutch and French use de-BE, nl-BE and fr-BE.
  • Reserved region codes don’t work: “using EU, UN, or UK in hreflang annotations doesn’t have an effect on Google Search.” The United Kingdom is GB, so en-GB, not en-UK.
  • Values are case-insensitive, though uppercase regions such as en-GB follow the ISO convention.
  • Scripts can be derived or stated. With zh-TW, “the language script is automatically derived” as Traditional Chinese. To name the script explicitly, use zh-Hant or zh-Hans, optionally with a region, as in zh-Hans-US.

zh-CN is valid: Chinese for users in China, with the script derived from the region.

x-default

x-default names the page for users whose language settings match none of your versions. Google says it “was designed for language selector pages and so it will work best with those”, though it can point at any page, including one of your localized versions. It needs no language code of its own.

Google also suggests a generic version when several pages target one language in different regions. If you have en-IE, en-CA and en-AU pages, add a plain en page “for searchers in the US, UK, and all other English-speaking locations”, which can be one of the regional pages.

Three Ways to Implement It

Google says: “The three methods are equivalent from Google’s perspective and you can choose the method that’s the most convenient for your site.” Using more than one is allowed but brings “no benefit in Search”, and three implementations are harder to keep in sync than one. Pick one per set of pages.

HTML link elements, in the <head> of every version, identical on every version:

<head>
  <link rel="alternate" hreflang="en-GB" href="https://en-gb.example.com/page.html" />
  <link rel="alternate" hreflang="en-US" href="https://en-us.example.com/page.html" />
  <link rel="alternate" hreflang="en" href="https://en.example.com/page.html" />
  <link rel="alternate" hreflang="de" href="https://de.example.com/page.html" />
  <link rel="alternate" hreflang="x-default" href="https://www.example.com/" />
</head>

The links “must be inside a well-formed <head> section”, and shouldn’t be combined with other attributes such as media in one <link> tag.

HTTP headers, for files without an HTML head, such as PDFs:

Link: <https://example.com/file.pdf>; rel="alternate"; hreflang="en",
      <https://de-ch.example.com/file.pdf>; rel="alternate"; hreflang="de-CH",
      <https://de.example.com/file.pdf>; rel="alternate"; hreflang="de"

An XML sitemap, with the xhtml namespace and one <url> entry per version, each listing every version including itself:

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
        xmlns:xhtml="http://www.w3.org/1999/xhtml">
  <url>
    <loc>https://www.example.com/english/page.html</loc>
    <xhtml:link rel="alternate" hreflang="en" href="https://www.example.com/english/page.html"/>
    <xhtml:link rel="alternate" hreflang="de" href="https://www.example.de/deutsch/page.html"/>
    <xhtml:link rel="alternate" hreflang="de-CH" href="https://www.example.de/schweiz-deutsch/page.html"/>
  </url>
  <url>
    <loc>https://www.example.de/deutsch/page.html</loc>
    <xhtml:link rel="alternate" hreflang="en" href="https://www.example.com/english/page.html"/>
    <xhtml:link rel="alternate" hreflang="de" href="https://www.example.de/deutsch/page.html"/>
    <xhtml:link rel="alternate" hreflang="de-CH" href="https://www.example.de/schweiz-deutsch/page.html"/>
  </url>
  <url>
    <loc>https://www.example.de/schweiz-deutsch/page.html</loc>
    <xhtml:link rel="alternate" hreflang="en" href="https://www.example.com/english/page.html"/>
    <xhtml:link rel="alternate" hreflang="de" href="https://www.example.de/deutsch/page.html"/>
    <xhtml:link rel="alternate" hreflang="de-CH" href="https://www.example.de/schweiz-deutsch/page.html"/>
  </url>
</urlset>

Google notes that the child <xhtml:link> entries “don’t count towards the URL limit for sitemaps”, and that their order doesn’t matter. On large sites the sitemap method can be generated from one database; sitemap rules in general are in XML sitemaps.

The Rules That Make It Work

  1. List every version, including the page itself. “Each language version must list itself as well as all other language versions.”
  2. Make every pair reciprocal. “If two pages don’t both point to each other, the tags will be ignored.” The reason is protective: otherwise “someone on another site” could claim to be a version of your page. The effect is limited to the pair. Google adds that if a complete set is hard to maintain, “you can omit some languages on some pages; Google will still process the ones that point to each other.”
  3. Use fully qualified URLs. “Alternate URLs must be fully-qualified, including the transport method”, so https://example.com/foo, not /foo. They don’t need to be on the same domain.
  4. Point to canonical, indexable URLs. Google’s canonical guidance says that with hreflang you should “specify a canonical page in the same language”. A German page whose canonical points to the English page asks Google to treat it as a duplicate of the English one; see canonical tags.
  5. Use valid codes. ISO 639-1 language, optional ISO 3166-1 Alpha 2 region, no region alone.

Mistakes to Check For

  • Missing return links, which Google lists first among common mistakes.
  • Region codes in the wrong place or invalid, such as en-UK, en-EU or be used for Belgium.
  • Relative URLs in the href.
  • Hreflang pointing at redirects, 404s or non-canonical URLs. Each target should return 200 and name itself as canonical.
  • Tags outside the <head>, for example injected after a body element, or in a <head> broken by invalid markup.
  • Automatic redirects by language or location. Google’s guide to multi-regional sites says to avoid them, because they “could prevent users (and search engines) from viewing all the versions of your site.” It also warns that “Most, but not all, Google crawls originate from the US,” and that Google doesn’t vary crawl location to detect variations, so IP-based content can hide versions from Google. Offer visible links to other language versions instead.

Validating Without a Search Console Report

Search Console no longer reports hreflang errors. Its help page states: “The International Targeting report has been deprecated”, and adds that “Google will continue to support and use hreflang tags on your pages.”

So validate with other tools:

  • A site crawler that reads hreflang from HTML, headers or sitemaps and reports missing return links, invalid codes, non-200 targets and canonical conflicts.
  • Single-page checkers. Google’s guide lists third-party hreflang generators and testers, noting they “are not maintained or checked by Google.”
  • URL Inspection on a sample of versions, to confirm each is indexed and to see the Google-selected canonical.
  • Search results. Search from the target country, with the target language settings, and see which version appears.

Run the crawl after every release that touches templates or URL structures, because no Search Console report will flag hreflang that breaks.

Language Targeting and Regional Targeting

Target by language when the content is the same for every country that speaks it: en, de, es. Add regions only where the page actually differs, such as prices, currency, shipping, legal terms or spelling: en-US and en-GB for a store with different prices and delivery. Region-specific pages that only swap a few words still need canonicals pointing to themselves, and Google’s canonicalization guide recommends both canonicalization and hreflang for regional variants in the same language.

The URL structure is a separate decision. Google’s multi-regional guide compares country-code domains (example.de), subdomains (de.example.com) and subdirectories (example.com/de/), and says country-code domains are “a strong signal” of the intended country. It also notes that Google ignores “locational meta tags (like geo.position or distribution)”. URL structure choices are covered in site architecture and URL structure, market selection in international SEO fundamentals, and adapting content beyond translation in content localization.

Add a region code only where the regional page actually differs in price, currency, shipping, legal terms or spelling; a regional version that differs only in its code adds a page to every set without serving anyone differently.

Link profile