Skip to content
Back to log

How to use hreflang on multilingual sites

Chainabit's Chao · · 7 min read

In short

Learn how to use hreflang to tell Google Search about language and regional versions of your pages, which code formats to use, and which common mistakes to avoid.

What does hreflang tell Google?

According to Google Search Central, hreflang tells Google about versions of the same content intended for different languages or regions. Google Search uses this information to help users find the page version that best matches their language or region. Google Search Central: Localized versions of pages

You can use this markup for pages whose content has been fully translated into multiple languages. It also works for versions in the same language that share similar content but differ in regional details. Google also gives the example of pages where the main content stays in the same language and only template elements such as navigation and footers are translated.

According to Google, localized page versions are considered duplicates only when the main content remains untranslated. Google uses algorithms to determine a page's language and does so independently of hreflang and the HTML lang attribute.

URLs for language versions

Google recommends giving each language version of a page its own URL. This avoids relying on cookies or browser settings to change the language of the content at a single URL. With separate URLs, hreflang annotations help Google Search results link to the appropriate language version. Google Search Central: Multi-regional and multilingual sites

If you change content dynamically based on language settings or redirect users to another URL, Google may miss some versions when it discovers and crawls your pages. Googlebot typically crawls from the United States and leaves the Accept-Language header unset in HTTP requests.

Google also recommends avoiding automatic redirects between versions based on a user's presumed language. These redirects can prevent users and search engines from seeing all versions of the site. Links to the other language versions of a page let users choose the version they prefer.

Three markup methods

Google supports three ways to indicate language and regional versions: HTML, HTTP headers, and sitemaps. Google treats these methods as equivalent, so you can choose whichever suits your site. Using all three offers no additional benefit in Search and can make the implementation harder to manage.

Whichever method you use, each language version must list itself and the other language versions. Alternate URLs must be fully qualified, including http or https. The alternate versions can be on different domains.

If two pages fail to point to each other, Google ignores those annotations. If maintaining a complete set of reciprocal links becomes difficult, you can omit some languages on some pages. Google will still process the versions that point to each other. Google emphasizes adding reciprocal links between newly added language pages and the corresponding versions in the original or dominant language.

hreflang in HTML

With the HTML method, add a set of <link> tags to the <head> of each page version. The set includes a link to every version, including the page itself. Use the same set of links on every version of the page. Google says this method is useful when you have no sitemap or cannot set HTTP response headers.

Each link includes the rel="alternate", hreflang, and href attributes. The hreflang attribute contains a supported language or region code or the x-default value. The href attribute contains the full URL of the corresponding version. Google shows the following format:

<link rel="alternate" hreflang="lang_code" href="url_of_page" />

The <link> tags must appear inside a well-formed HTML <head> section. If you're unsure, Google suggests pasting the generated page HTML into an HTML validator to confirm that the links are inside the <head>. Google also advises against combining hreflang annotations with other attributes such as media in the same <link> tag.

Google's example includes generic English, UK English, US English, and German versions, along with a default page that targets no specific language or region. Every page in the example includes the same links in its <head>:

<head>
 <title>Widgets, Inc</title>
  <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>

Google does not use the language-specific subdomain names in the example to determine each page's intended audience. You must specify which audience each version targets. The default page in the example lets users choose their language and region.

Turn this insight into action.

Use the mobile app to continue with guided workflows.

hreflang in HTTP headers

You can also specify language and regional versions in the HTTP Link header returned in a page's GET response. Google says this method is useful for non-HTML files such as PDFs.

The header includes a URL, rel="alternate", and a hreflang value for each version. The set includes the requested version itself. A comma separates each entry, and every page version returns the same Link header. Each URL must be fully qualified and enclosed in < and >.

Google's example lists three versions of a PDF: one for English speakers, one for German speakers in Switzerland, and one for other German speakers:

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"

hreflang in sitemaps

With the XML sitemap method, create a separate <url> element for each page URL. The <loc> inside each <url> element specifies that page's URL. The child <xhtml:link> entries list all language and regional versions, including the page itself.

For example, if a page has three versions, the sitemap contains one entry for each URL, and each entry contains the same three child links. The order of the child <xhtml:link> elements doesn't matter. Google notes that keeping them in the same order can make errors easier to spot.

Declare the xhtml namespace in the sitemap as follows:

xmlns:xhtml="http://www.w3.org/1999/xhtml"

Upload the sitemap to a directory on the site where it applies. According to Google, a sitemap can include only URLs under the directory where it is hosted. The general sitemap rules also apply to sitemap extensions.

Language, region, and script codes

In the format Google specifies, a hreflang value can include a language code and an optional region code. Use ISO 639-1 for the language code and ISO 3166-1 Alpha 2 for the region code. Separate the codes with a hyphen. Google supports only the language and region codes listed in these standards.

You can use a language code on its own. For example, de indicates German-language content without a regional target. en-GB indicates English-language content for users in the United Kingdom, while de-ES indicates German-language content for users in Spain.

The first code must specify the language, so a region code alone is invalid. In Google's example for Belgium, de-BE specifies German, nl-BE specifies Dutch, and fr-BE specifies French. On its own, be is the language code for Belarusian and does not refer to Belgium.

The hreflang value is case-insensitive. Google accepts both uppercase and lowercase. Writing the region code in uppercase, as in en-GB, follows ISO 3166-1 Alpha 2 notation. Google Search ignores the region portion of the annotation when you use codes reserved for other purposes, such as EU, UN, or UK.

You can explicitly specify the script using an ISO 15924 code. In Google's examples, zh-Hant means Traditional Chinese and zh-Hans means Simplified Chinese. You can add an optional region code after the script code, as in zh-Hans-US. Google can also infer the script from the region. For zh-TW, it infers Traditional Chinese.

Unmatched languages and limitations

x-default is a reserved value for cases where a user's browser settings do not match any other language or region value. Google recommends using it to designate a fallback page for users whose language settings do not match the site's localized versions. You can use it on any page, though it was designed for language selector pages.

In HTML, add a link tag for x-default alongside the existing hreflang annotations and specify the fallback page's URL in href. The x-default value needs no additional language code.

If you have separate regional URLs for users who speak the same language, Google recommends also providing a generic language URL for users outside the specified regions. For example, you can provide a generic en page alongside en-IE, en-CA, and en-AU. One of the regional pages can also serve as the generic page.

Google identifies missing return links and incorrect codes as common mistakes. If page X points to page Y, page Y must also point to page X. Google may ignore or misinterpret annotations when they lack reciprocal links across pages.

Ready to start?

Download the app and continue from your phone.

End of Entry