How to Set Up hreflang Tags for a Multilingual Site

How to Set Up hreflang Tags for a Multilingual Site

If your site has versions in different languages or for different regions, hreflang tags tell search engines which one to show each visitor. Done wrong, they are quietly ignored. Done right, they prevent the wrong-language page from ranking. Here is the practical version.

What hreflang does

An hreflang tag points from one page to an equivalent page in another language or region:

<link rel="alternate" hreflang="es" href="https://example.com/es/" />

You add one tag per version, in the <head> of every version.

The two rules that make it work

  1. Reciprocal: every page must link to every version, including itself. If the English page lists the Spanish one, the Spanish page must list the English one back. Missing return links are the number one reason hreflang fails.
  2. Identical set on all versions: the full list of alternates is the same on every page. Do not trim it per page.

Codes and x-default

  • Use a language code (en) or language plus region (en-us, pt-br). The region is optional and only needed when you target specific countries.
  • Add an x-default entry pointing to the page shown when no language matches (often your main or language-selector page).

Invalid codes are silently dropped, so getting them right matters.

Generate the tags

  1. Open the hreflang Tag Generator.
  2. Add a row for each version (code plus URL), and set the x-default.
  3. Copy the block into the <head> of every language version.

The tool validates the codes and warns about duplicates, the two things people get wrong.

Keep the set reciprocal and identical everywhere, use valid codes, add x-default, and paste the same block on every version. That is hreflang done right.

← All posts