← Back to all posts Guide

Hreflang tags explained: when and how to use them

May 25, 2026·7 min read

If you publish the same page in multiple languages or for multiple regions, you need hreflang tags. They tell search engines which version to show to which user. Without them, a French visitor might land on your English page, or worse, search engines might decide one of your language versions is duplicate content and drop it from the index.

What hreflang does (in plain terms)

The hreflang attribute is a hint to search engines that two or more pages are language or regional alternatives of each other. When a Spanish speaker in Mexico searches, hreflang helps search engines decide between your example.com/ (English), example.com/es/ (Spanish), and example.com/es-mx/ (Spanish, Mexico) versions and serve the one that fits.

It does NOT translate your page. It does NOT block other languages from being shown. It's just a hint about which version is the right match for a given language and country combination.

The format

<link rel="alternate" hreflang="LANG" href="URL" />
<link rel="alternate" hreflang="LANG-REGION" href="URL" />

Where:

So hreflang="en-GB" means "English, United Kingdom." hreflang="fr" means "French, any region." hreflang="es-419" is the unusual one: UN M.49 region code for Latin America.

The x-default tag

There's one special value: hreflang="x-default". It marks the fallback page shown to users whose language and region don't match any of your other versions.

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

Usually this points to your English version or to a language-picker page. x-default is recommended but not strictly required.

A full real-world example

Imagine you sell a product with three versions: English (default), Spanish for Spain, and Spanish for Mexico. On every one of those pages, you include the same set of tags:

<link rel="alternate" hreflang="en" href="https://example.com/product" />
<link rel="alternate" hreflang="es-ES" href="https://example.com/es/producto" />
<link rel="alternate" hreflang="es-MX" href="https://example.com/es-mx/producto" />
<link rel="alternate" hreflang="x-default" href="https://example.com/product" />

Critical: every page references every other page, including itself. This is called a "reciprocal" set. Without reciprocal references, search engines ignore the hreflang signal entirely.

The reciprocal rule

If page A says "page B is my Spanish alternative" but page B does not say "page A is my English alternative," search engines treat both as broken hreflang and ignore them. Always include the full set on every page in the group.

Where the tags can go

Three places. Only one method is used per page (they aren't mixed on the same page):

  1. In the HTML <head>: most common for HTML pages. The link tags go before </head>.
  2. In the sitemap.xml: useful for sites with many language versions. Each <url> entry gets a set of <xhtml:link> children for its alternates.
  3. In the HTTP response header: mainly for PDFs and other non-HTML files. Format: Link: <url>; rel="alternate"; hreflang="es"

When you don't need hreflang

Common mistakes

Generate your hreflang set in 60 seconds

Pick languages, paste URLs, get HTML or sitemap XML output. Validates ISO codes automatically.

Open the generator →

How to verify hreflang is working

  1. Search-engine webmaster tools: under Indexing → International Targeting, the dashboard lists hreflang errors and warnings if any are found.
  2. View page source: open one of your alternate pages, find the <link rel="alternate"> tags, and click each href. They should all load with HTTP 200.
  3. Crawl your site with a site-auditing tool. Most major SEO crawlers flag hreflang errors (missing reciprocals, broken links, invalid codes) across the entire site.

Related reading