Blog · SEO

Hreflang: How to Set Up Language and Country Versions Correctly

hreflang tells Google which language or country version of a page to show each searcher. This guide covers the three ways to declare it, the code rules Google actually enforces, return links, x-default, how canonicals interact with it, and step-by-step fixes for the errors an hreflang checker finds.

Searvia · 10/24/2026 · 11 min read

In short: hreflang tells Google which language or country version of a page to show each searcher. Every version lists every version, including itself, with an ISO 639-1 language code and an optional ISO 3166-1 alpha-2 region (en, de, en-GB, pt-BR), plus an optional x-default fallback. Links must be absolute and must point both ways, or Google ignores them. Each version needs a self-referencing canonical; a canonical that points to another language cancels the setup. Google detects the page language from the content, so the translation itself has to be real.

International sites lose traffic in a quiet way. The English page ranks in Germany, the Spanish page shows up in Mexico when you built a Mexican one, or the UK store appears for American searchers with prices in pounds. Nothing is broken on the site; Google simply guessed which version to show. hreflang is how you stop it guessing.

This guide explains how hreflang works according to Google's documentation, the code rules that trip most sites, how canonicals interact with it, what our free hreflang checker tests, and how to fix each problem.

What hreflang does, and what it doesn't

hreflang annotations describe a set of pages that are versions of each other: the same content in another language, or the same language adapted for another country. Google uses them to show the matching version in its results.

What it does not do:

The three ways to add hreflang

Google says the three methods "are equivalent from Google's perspective." Use one per page; mixing them just adds places for errors.

1. HTML link elements in the <head>, the most common choice. On https://example.com/en/pricing:

<link rel="alternate" hreflang="en" href="https://example.com/en/pricing" />
<link rel="alternate" hreflang="de" href="https://example.com/de/preise" />
<link rel="alternate" hreflang="fr" href="https://example.com/fr/tarifs" />
<link rel="alternate" hreflang="x-default" href="https://example.com/en/pricing" />

The German and French pages carry exactly the same four lines. Google requires the tags to be "inside a well-formed <head> section"; a stray element that the browser moves into the body, such as an image or an unclosed tag above the links, can break the head early.

2. HTTP Link headers, the only option for non-HTML files such as PDFs:

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

Google says the header must be identical for every version.

3. XML sitemap, convenient for large sites because no template changes are needed:

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
        xmlns:xhtml="http://www.w3.org/1999/xhtml">
  <url>
    <loc>https://example.com/en/pricing</loc>
    <xhtml:link rel="alternate" hreflang="en" href="https://example.com/en/pricing"/>
    <xhtml:link rel="alternate" hreflang="de" href="https://example.com/de/preise"/>
  </url>
  <url>
    <loc>https://example.com/de/preise</loc>
    <xhtml:link rel="alternate" hreflang="en" href="https://example.com/en/pricing"/>
    <xhtml:link rel="alternate" hreflang="de" href="https://example.com/de/preise"/>
  </url>
</urlset>

Each <url> lists every version, including itself.

The rules Google enforces

Return links and self-reference

"If two pages don't both point to each other, the tags will be ignored." This is the rule behind most broken setups. If the English page lists the German page but the German page does not list the English one, Google drops the pair. Google also says "each language version must list itself."

Language and region codes

"Only language codes listed in ISO 639-1 and region codes listed in ISO 3166-1 Alpha 2 are supported." The language comes first; the region is optional. Google also supports script subtags for languages written in more than one script, such as zh-Hant and zh-Hans, and combinations like zh-Hans-US.

CodeValid?Why
enYesEnglish, any region
en-GBYesEnglish for the United Kingdom
pt-BRYesPortuguese for Brazil
zh-HantYesChinese, Traditional script
es-419No for GoogleRegion must be an ISO 3166-1 alpha-2 code; 419 (Latin America) is not one
en-UKNo effectThe ISO code is GB; Google says UK, EU and UN have no effect
beMeans BelarusianA country code alone is invalid; be is the Belarusian language, not Belgium
en_USNoUse a hyphen, not an underscore
engNo for GoogleThree-letter ISO 639-2 codes are not supported; use en

For Spanish across Latin America, either use es for one shared Spanish version, or list the specific countries you target (es-MX, es-AR, es-CO) pointing to the same URL.

x-default

"The reserved x-default value is used when no other language/region matches the user's browser setting." Point it at a language selector or your main international version. It is optional but useful: without it, a searcher in a language you do not offer gets whichever version Google picks.

Absolute URLs

"Alternate URLs must be fully-qualified, including the transport method." https://example.com/de/ works; /de/ and //example.com/de/ do not.

hreflang and canonical tags

The two must agree. Each version should have a canonical pointing to itself, not to the English or main version. Google's canonicalization guide says to "specify a canonical page in the same language," or "the best possible substitute language if a canonical page doesn't exist for the same language," and notes that hreflang clusters influence canonical choice, favoring URLs that link to each other reciprocally.

The classic mistake: every language version carries <link rel="canonical" href="https://example.com/en/...">. That tells Google the other versions are duplicates of the English page, and they drop out of the index along with their hreflang annotations.

Two more conflicts to avoid: hreflang URLs that redirect (list the final URL) and hreflang URLs that carry noindex (a version Google cannot index cannot be shown).

Site structure and automatic redirects

Google's multi-regional guide compares the URL structures:

StructureExampleNotes from Google
Country domainexample.deClear geotargeting; expensive, one country per domain
Subdomainde.example.comEasy to set up; users may not recognize the targeting from the URL
Subdirectoryexample.com/de/Low maintenance, same host
URL parameterexample.com?loc=deNot recommended

Whichever you choose, do not redirect visitors automatically by IP or browser language. Google says this "could prevent users (and search engines) from viewing all the versions of your site," and that Googlebot "usually originates from the USA." Show a suggestion banner instead and let hreflang handle search results.

How the Searvia hreflang checker works

The hreflang checker runs the same engine as our website SEO checker: you enter a domain or a page address, it audits that page (your home page if you enter only a domain) and the site files around it with 38 checks in about 20 seconds, and puts the three checks this tool is about first. This is exactly what they test.

Language versions, hreflang (low priority). The checker reads every <link rel="alternate" hreflang="..." href="..."> element in the HTML of that page, after following redirects to its final address.

Page language (low priority). Passes when the <html> element has a lang attribute and shows its language; warns when it is missing.

Canonical URL (medium priority). Passes when the canonical tag points to the page itself; warns when it is missing or points to another address, showing that address.

What it does not test

Reading the result

MessageMeaningFix
No language versions are declared (fine for a single-language site).No hreflang links on the pageNothing for single-language sites; see step 1 otherwise
N language versions are declared correctly.Codes valid and self-reference present; the message notes it if there is no x-default fallback (optional)Still check return links by hand
The language versions do not include this page itself.The page lists others but not itselfStep 2
Some language codes are not valid.At least one row has a red crossStep 3
The page does not declare its language.No lang on <html>Step 4
The canonical URL points to another address.The canonical names a different pageStep 5

The overall A+ to F grade covers all 38 checks, weighted by priority (high 10, medium 5, low 2; warnings earn half), with a "Fix these first" list and a shareable report.

How to fix every hreflang problem

1. No language versions are declared, but you have them

2. The language versions do not include this page itself

Add a line for the current page with its own code. In a template, this usually means the loop over languages skips the current language; remove that condition. Make sure the self URL is the canonical URL, with the same protocol, host and trailing slash convention.

3. Some language codes are not valid

4. The page does not declare its language

Add the language to the root element, for example <html lang="en"> or <html lang="pt-BR">. Google does not use it to detect language, but browsers, translation tools and screen readers do, as MDN describes.

5. The canonical points to another address

On a multilingual site this is often the cross-language canonical problem. Change each version's canonical to its own URL. If the canonical points to the same page in another form (http instead of https, or without www), make it match your final address exactly.

6. Return links are missing (not tested by the checker)

Open two versions side by side and compare their hreflang lists: they must be identical sets. If they differ, the cause is almost always the template or plugin that generates them, so fixing the generator once fixes every page.

Worked example (hypothetical)

The following is a hypothetical example, not real data. Kestrel Gear, an invented outdoor brand, runs example.com in English with /de/, /fr/ and /es/ versions. German searchers keep landing on English pages. The hreflang checker reports:

RowURLOK
en-UKhttps://example.com/No (→ en-GB)
de-DEhttps://example.com/de/Yes
frhttps://example.com/fr/Yes
es_EShttps://example.com/es/No

Canonical: "The canonical URL points to the page itself." Page language: en.

The cross on es_ES is a format error. The cross on en-UK comes with the note "→ en-GB": Google does not accept UK as a region, so the English page had no usable annotation. Viewing the German page's source finds a third: its canonical points to the English home page, so Google treated /de/ as a duplicate. The fixes:

A 20-minute hreflang checklist

How Searvia helps

The free hreflang checker validates the hreflang links, page language and canonical of the page you enter in one shareable report, alongside the other checks of the website SEO checker. In a Searvia account, connect Search Console to see clicks and positions by country for each language version, and run the site audit every week to catch canonicals pointing elsewhere, duplicate titles across language versions and broken pages. If you publish apps as well as websites, our App Store localization guide covers the same problem on the store side. For the full technical checklist, see the technical SEO audit guide.

Frequently Asked Questions

What is hreflang?
hreflang is an annotation that tells Google about the language and country versions of a page, so it can show the right version to each searcher. It is written as rel="alternate" links with an hreflang attribute, in the HTML head, in an HTTP Link header or in an XML sitemap. Each version lists every version, including itself, with a code such as en, de or en-GB, and optionally an x-default fallback.
Does hreflang help rankings?
hreflang does not make a page rank higher. It helps Google pick which version of a page to show in a given language or region, so a German searcher sees the German page instead of the English one. Without it, Google may still work out the right version, but mistakes such as the wrong language in results are more likely when versions are similar.
What is x-default in hreflang?
x-default is a reserved hreflang value for the page to show when no other language or region in the set matches the user's browser settings. It is often a language selector page or the main international version. Google recommends it for the fallback page but does not require it.
Is en-UK a valid hreflang code?
No. hreflang region codes must be ISO 3166-1 alpha-2 country codes, and the code for the United Kingdom is GB, so use en-GB. Google says that using UK, EU or UN in hreflang annotations has no effect in Google Search. A country code on its own is also invalid: hreflang must start with an ISO 639-1 language code.
Do I need hreflang if I use the lang attribute?
Yes, if you have several language or country versions. Google says it does not use the HTML lang attribute or hreflang to detect the language of a page; it reads the visible content. The lang attribute helps browsers and screen readers, while hreflang tells Google how your versions relate to each other. Set both.

Sources

  1. Tell Google about localized versions of your page – Google Search Central
  2. Managing multi-regional and multilingual sites – Google Search Central
  3. How to specify a canonical URL – Google Search Central
  4. Redirects and Google Search – Google Search Central
  5. HTML lang global attribute – MDN Web Docs
  6. ISO 639 language codes – Library of Congress

Keep Reading