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
- 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.
- 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
- Open the hreflang Tag Generator.
- Add a row for each version (code plus URL), and set the x-default.
- 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.
Related tools
- Building the rest of the head? Use the Meta Tags Generator.
- Confirming each version is indexable? Try the Indexability Checker.
- Listing all your URLs for a sitemap? See the XML Sitemap Generator.
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.