hreflang for English and Spanish versions of a site

How to tell search engines about your English and Spanish pages: hreflang links, language and country codes, x-default, pairs that link back, and mistakes.

IntermediateHow-to6 min readUpdated October 30, 2026

In this guide
  1. What hreflang does
  2. The three ways to declare it
  3. The rule that matters most: every version points to every version
    1. x-default
  4. Codes: language and, optionally, country
  5. Also set the page's own language
  6. Canonical links and language
  7. Keep the pair consistent
  8. A language switch for visitors
  9. Speed and language versions
  10. How to check
  11. Mistakes to avoid
  12. Check your own page
  13. Sources

What hreflang does

Lighthouse's documentation explains it. Many sites provide different versions of a page based on language or region. hreflang links tell search engines the addresses of all the versions of a page, so they can show the right version for each language or region.

For an English and Spanish site, the English page says "this is the English version, and the Spanish one is over there", and the Spanish page says the same in return. Without it, search engines have to guess which pages belong together and which to show to whom.

hreflang is a signal for search engines, not for the browser. It does not translate anything or redirect anyone.

The three ways to declare it

Lighthouse lists three, and says to choose the easiest for your situation.

1. Links in the head of each page:

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

2. A `Link` header in the HTTP response, useful for files that have no HTML head, such as PDFs.

3. Language information in your sitemap, with an xhtml:link entry for each version.

The 2025 Web Almanac found hreflang on about 20% of pages, roughly double the 9 to 10% of the year before. Almost all of it is in the page, not in a header: the header form was on 0.1 to 0.2% of pages. Raw and rendered numbers differed by less than 1%, which suggests that most sites that use it do so in a way that survives rendering.

The rule that matters most: every version points to every version

Lighthouse says each version of a page must link to all the other versions, including itself. Otherwise search engines may ignore the links or interpret them incorrectly.

So the English page carries three links: to the English page, to the Spanish page, and x-default. The Spanish page carries the same three. If the English page lists the Spanish one but the Spanish one does not list the English one, the pair is incomplete.

The examples in the documentation use full addresses, with https and the host, and so should you.

x-default

For a page where users select their language, Lighthouse says to use the x-default keyword:

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

It names the version to show when no language matches. The Almanac found x-default on about 7% of home pages, nearly as often as en.

Codes: language and, optionally, country

Lighthouse's guidelines:

Two consequences for a Spanish version:

Lighthouse checks the language codes in your hreflang links and reports invalid ones. It does not check region codes, and it does not check your sitemap.

Also set the page's own language

The lang attribute on the html element names the language the page is written in. MDN says to always specify it, and notes that WCAG success criterion 3.1.1 requires a page's language to be programmatically determined, and 3.1.2 requires parts in a different language to be marked. The purpose, MDN says, is mainly to let assistive tools such as screen readers use the right pronunciation.

<html lang="es">

A Spanish page with lang="en" is read aloud with the wrong voice, and sends mixed signals to anything that reads the attribute. A short passage in another language gets its own lang, for example <span lang="en">checkout</span>.

Each language version should have a canonical link that points to itself. Lighthouse's canonical audit fails a page whose canonical points to a page for a different region or language. If your Spanish page's canonical points to the English page, you are telling search engines that the Spanish page is a duplicate of the English one, which contradicts your hreflang links. See canonical tags.

Keep the pair consistent

A language switch for visitors

hreflang is for search engines. Visitors need a visible switch between languages, on every page, that takes them to the same page in the other language. Remember their choice. Avoid sending people to a language from their browser's setting with no way back, because the guess is sometimes wrong. Mark the switch link itself with hreflang and lang attributes for the language it leads to.

Speed and language versions

A second language doubles the number of pages. A few things matter for speed:

How to check

  1. View the source of an English page and look for the three links. Open the Spanish address and check that it carries the same three.
  2. Check the `lang` attribute on each page.
  3. Check each canonical points to its own page.
  4. Run Lighthouse and read the hreflang finding.
  5. Test the switch from several pages, to be sure it lands on the matching page and not the home page.

Mistakes to avoid

Check your own page

Run the free audit and read the hreflang finding. Then open one English page and its Spanish partner in the page source, and confirm that each has three matching links, its own lang and its own canonical.

Sources

Start here

Free website audit

Live Google data for any public page: mobile and desktop.

Mobile + desktop · Lighthouse lab test · Real-user Chrome data when Google has it

Rather have this done for you? Technical SEO · Book a call

Related guides

All guides →