Hreflang Tags Explained

Hreflang tells search engines which URL to show for each language or region. Every version of a page lists itself and all its alternates with link rel="alternate" hreflang="code" and a full URL. Codes are an ISO 639-1 language, optionally followed by an ISO 3166-1 region such as en-GB, and x-default covers everyone else.

Valid and invalid codes
CodeValid?Meaning
enYesEnglish, any region
en-GBYesEnglish for users in the United Kingdom
zh-HantYesChinese in Traditional script (ISO 15924 script code)
es-419No (for Google)Numeric regions are not supported
x-defaultYesFallback when no other version matches
GBNoRegion alone is not allowed
en-UKNoThe region code for the United Kingdom is GB

Updated

Most hreflang problems are bookkeeping: one page forgets to link back, a code uses the wrong region, or URLs are relative. The generator below builds the full, symmetrical set for every version at once, so each page carries the same complete list.

Hreflang generator

Add each version's code and full URL. The generator checks the codes and writes the tag set and sitemap block for all versions at once.

The three ways to declare alternates

HTML link tags in the head

The same five lines go on the English, British English, German and selector pages.

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

HTTP Link header for a PDF

Sent by the server with the file, since a PDF has no head to put tags in.

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

Sitemap entries

Each url element lists every version, including itself. The xhtml namespace must be declared on urlset.

<?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://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>

Errors and their fixes

What goes wrong most often
ProblemFix
Missing return linkAdd the full set of tags to every version
Region without language, such as hreflang="US"Use a language plus region, such as en-US
Wrong region code, such as en-UKUse the ISO 3166-1 code GB
Relative hrefWrite the full URL with https and host
Alternate URL redirects or returns 404List only live, final URLs

When hreflang is worth adding

Use it when the same content exists in more than one language, or in one language with real regional differences such as prices, spelling or delivery terms. It helps Google send a searcher in Mexico to the Mexican Spanish page instead of the Spanish one from Spain.

A site in one language for one market does not need hreflang. Adding it there only creates something else to maintain.

Common mistakes

Relative URLs are not accepted; the href must include https and the host. Underscores are wrong in hreflang: write en-GB, not en_GB, which is the Open Graph locale style.

Listing a URL that redirects or returns an error wastes the annotation. Keep the set to live, final addresses and update it whenever a translated page is added or removed.

How it works

  1. Add a row for each language or regional version with its code and full URL.
  2. Optionally mark one URL, often a language picker or your main version, as x-default.
  3. Copy the link tags into the head of every version, or use the sitemap output instead.
  4. After the next crawl, inspect a few of the URLs in Search Console to confirm Google picked up the set.

Tips

Frequently asked questions

Do I need a self-referencing hreflang tag?

Yes. Google's documentation says each version should list itself as well as all the other versions. Without the self reference the set is incomplete.

What is x-default for?

x-default names the page to show when a searcher's language or region matches none of your listed versions. A language selector page or your international homepage is the usual choice.

What happens if page B does not link back to page A?

Google requires the links to go both ways. If A points to B but B does not point back to A, the annotation can be ignored. Return links stop third parties from claiming to be an alternate of your page.

Should I use HTML tags, HTTP headers or the sitemap?

Google treats all three as equivalent. HTML tags suit most sites. HTTP Link headers are the option for PDFs and other non-HTML files. A sitemap keeps the markup out of your pages and is easier for large sites with many languages.

Can I target a country without a language?

No. A region code on its own is invalid. To target Canada in English and French, use en-CA and fr-CA.

Related: Hreflang generator, Canonical tag checker, Sitemap and robots.txt examples, Next.js SEO checklist, Open Graph tags explained.

Start for free or see all free tools. We.Inc is free to start, with no card needed. AI building is on paid plans from $20 a month.

More in Guides

We.Inc is an AI-powered website builder you can resell under your own brand. Launch a branded client dashboard, bill on Stripe Connect, and deliver AI-generated websites in minutes. White-label plans start at $99 a month for 25 client sites, with a 7-day free trial and no per-site fees.

Product

Who It's For

Features

Resources

Company

View Sitemap