Back to blog
Hreflang Validator8 min readApril 18, 2026

What Is Hreflang and How to Implement It Correctly

Hreflang tells Google which version of your content to show based on the user's language and country. Learn how to implement it, the correct attributes, and the mistakes that can invalidate your entire configuration.


If you have a website in multiple languages or targeting different countries, hreflang is the most important signal you can give Google to ensure it shows the correct version of each page to each user. Without proper hreflang implementation, Google may serve your English version to Spanish-speaking users, or your Spain-targeted version to users in Mexico. This guide covers everything you need to know to implement it correctly.

What is the hreflang attribute?

Hreflang is an HTML attribute added in the <head> section of a page to tell search engines that alternate versions of that content exist in other languages or for other regions. Google and Yandex recognize it; Bing does not support it (it uses the Content-Language header instead).

html
<!-- On the Spanish version for Spain -->
<link rel="alternate" hreflang="es-ES" href="https://example.com/es/page/" />
<link rel="alternate" hreflang="es-MX" href="https://example.com/mx/page/" />
<link rel="alternate" hreflang="en"    href="https://example.com/en/page/" />
<link rel="alternate" hreflang="x-default" href="https://example.com/page/" />

The hreflang tag is bidirectional: every page must include tags pointing to ALL variants in the cluster (including itself). If page A points to B but B does not point back to A, Google may ignore the signal entirely.

Correct hreflang attribute values

The hreflang attribute value follows the ISO standard: a language code (ISO 639-1) optionally followed by a hyphen and a country code (ISO 3166-1 alpha-2). The language code should be lowercase and the country code uppercase.

Targethreflang valueExample
Generic Spanisheshreflang="es"
Spanish for Spaines-EShreflang="es-ES"
Spanish for Mexicoes-MXhreflang="es-MX"
Generic Englishenhreflang="en"
English for the USen-UShreflang="en-US"
English for the UKen-GBhreflang="en-GB"
Default page (fallback)x-defaulthreflang="x-default"

Use language-only (without country) when the content is the same for all countries speaking that language. Add the country code only when the content or offer is region-specific (local pricing, different products, culturally adapted content).

What is x-default and when to use it?

The x-default value tells Google which page to show when none of the hreflang variants match the user's language or country. It typically points to the language selection page or to the main language version of the site.

  • If you have a language selection page, x-default should point to it.
  • If you have no language selector, x-default usually points to the English version (the broadest-reach language).
  • x-default is not required, but it is a best practice for sites with a global audience.
  • x-default does not need to be a different URL — it can match one of the existing hreflang variants.

The 3 methods for implementing hreflang

Method 1: Tags in the HTML <head> (most common)

This is the most widely used and compatible method. Tags are added in the <head> of each page. Make sure the tags appear before the closing </head> and that they include all variants in the cluster, including the current page's own URL.

Method 2: HTTP headers (for PDFs and non-HTML content)

If you need to implement hreflang on non-HTML resources (PDFs, feeds), you can add it as an HTTP header in the server response. The syntax is equivalent to the HTML tags but in header format.

Method 3: XML sitemap

For large sites, adding hreflang to every page can be complex. The XML sitemap allows you to centralize all hreflang configuration in one place. With this method, the sitemap contains the relationships between language variants and there is no need to add tags to the HTML of every page.

xml
<url>
  <loc>https://example.com/es/page/</loc>
  <xhtml:link rel="alternate" hreflang="es" href="https://example.com/es/page/"/>
  <xhtml:link rel="alternate" hreflang="en" href="https://example.com/en/page/"/>
  <xhtml:link rel="alternate" hreflang="x-default" href="https://example.com/page/"/>
</url>

How to verify that your hreflang is working correctly

After implementing hreflang, verify your configuration is correct using iRankly's Hreflang Validator. Enter the URLs of all variants in a cluster and the validator checks bidirectionality, the validity of language/country codes, and whether any URL returns an error.

Try the tool for free

Hreflang ValidatorAnalyze your URLs with {tool} by iRankly. No sign-up, no credit card.

Use tool for free

You can also check in Google Search Console → Enhancements → International → Hreflang whether Google has detected errors in your configuration. The most common errors are: missing return tag, invalid language code, and URL returning an error.


Try the tool for free

Analyze your URLs with Hreflang Validator by iRankly. No sign-up, no credit card.

Use tool for free