Skip to content
FreeToolsKit.app

Marketing & SEO guide

How to Add Hreflang Tags for Two Language Versions of a Page

7 min read · Updated 20 November 2026 · Uses Hreflang Tag Generator & Validator

Quick answer

Give each language version of the page the same set of hreflang tags in its <head>. For an English and a Spanish page with a fallback page, that's three <link rel="alternate"> tags: one for English, one for Spanish and one for x-default. Each page lists itself as well as the other version, so the two point to each other.

Both halves matter. Google says "Each language version must list itself as well as all other language versions", and "If two pages don't both point to each other, the tags will be ignored" (Google Search Central: Tell Google about localized versions of your page).

To check the tags before you publish, paste each page's tags, with that page's URL, into a validator that compares the pages with each other. In FreeToolsKit's Hreflang Tag Generator & Validator, add every page in the set, including the x-default page, until Return links reads "Verified among the supplied pages".

The example pages used in this guide

The test used a fictional pricing page in two languages, plus a language selector for everyone else:

  • English: https://www.example.com/en/pricing/, code en.
  • Spanish: https://www.example.com/es/precios/, code es.
  • Fallback (x-default): https://www.example.com/, a page where visitors pick their language.

The codes are plain en and es because the pages are for all English and all Spanish speakers, not one country. W3C's rule for language tags is to "keep the tag as short as possible" and add a region only when it makes a distinction you need (W3C: Language tags in HTML and XML).

Hreflang Tag Generator & ValidatorFree to use · No account required · Runs in your browserOpen Hreflang Tag Generator & Validator

Generate the tags

  1. On the Generate tags tab, in the first row, type en in Language/region and the English page's full URL in URL.
  2. In the second row, type es and the Spanish page's URL. For a third language, choose Add language version.
  3. Type the selector page's URL in x-default fallback URL (optional).
  4. Check the summary line and the error list. Here it read "2 language versions + x-default · 3 pages to annotate · limit 200", with no errors.
  5. Under Output, keep HTML tags, then choose Copy ("HTML tags copied to the clipboard.") or Download. The download was hreflang-tags.html.txt, 242 bytes.

The output was three tags, one per line. Each had rel="alternate", a code and a full URL:

  • hreflang="en": https://www.example.com/en/pricing/
  • hreflang="es": https://www.example.com/es/precios/
  • hreflang="x-default": https://www.example.com/

The Install on page menu listed all three pages, and the tags were identical for each. Paste the same three lines inside the <head> of the English page, the Spanish page and the selector page.

That matches Google's rules. The set of links "is identical for every version of the page", the tags "must be inside a well-formed <head> section", and Google's own example puts the same set on its language selector page as well (Google Search Central: Tell Google about localized versions of your page).

Or put them in your sitemap

If you'd rather not edit page templates, choose XML sitemap under Output instead. The test gave hreflang-sitemap.xml, 1,153 bytes. It has one <url> entry for each of the three pages, and every entry carries the same three xhtml:link lines, including a link to itself. The file declares the xhtml namespace that Google requires for this method.

Use one method, not both. Google says the HTML, HTTP header and sitemap methods are equivalent, and using several gives "no benefit in Search" (Google Search Central: Tell Google about localized versions of your page).

Check the tags before you publish

  1. Open the Validate hreflang tab and keep HTML <link> tags selected.
  2. Under Page 1, type the English page's URL in Page URL (recommended). Paste its tags, or its whole <head>, into HTML (the <head> or the <link> tags).
  3. Choose Add another page and do the same for the Spanish page, then again for the selector page.
  4. Choose Validate.

With only the English and Spanish pages, the verdict was "No errors or warnings found by the local checks", but Return links read "Unverified — not all pages supplied". A note explained that "1 alternate URL wasn't supplied, so its return links can't be checked here". That URL was the selector page.

With all three pages, Return links read "Verified among the supplied pages", and the note said "every alternate that was supplied links back". The downloaded sitemap, pasted into the XML sitemap option, gave the same verdict for its three entries.

The page URL matters. Without it, the tool can't check that a page lists itself or whether the other pages link back to it.

What the validator caught

Each broken set below was pasted in place of the correct tags, with the same page URLs. The quoted text is the tool's message.

  • Missing return link: the Spanish page listed only es and x-default. Page 2 got the error "No return link: English URL (page 1) lists this page as an alternate, but this page doesn't list English URL." The tool printed the full English address where this shows English URL. Return links read "Missing return links found". This is the case where Google ignores the tags.
  • No self-reference: the English page listed only es and x-default. The error: "This page (English URL) isn't in its own hreflang set. Each version must list itself as well as its alternates."
  • Country code on its own: US in place of en gave "“US” is a country code on its own. hreflang needs a language first (e.g. en-US); Google doesn't derive the language from a country." The tool then dropped that line, so the English page also failed the self-reference check.
  • Latin American Spanish, es-419: "Numeric UN M.49 regions such as “419” (e.g. es-419 for Latin America) aren't supported by Google's hreflang. List each country instead, e.g. es-MX, es-AR."
  • en-UK for British English: "“UK” isn't an ISO 3166-1 country code. The United Kingdom is GB — use en-GB." As with US, the self-reference check failed too.
  • Relative URL: /es/precios/ in place of the full Spanish URL gave "/es/precios/: Use an absolute URL that starts with https:// or http://." A URL starting with // got the same message.
  • Same language twice: es pointing to two different URLs was an error: "es points to two URLs on this page: … Each code maps to exactly one URL." The same es line repeated with the same URL was only a warning, "is listed twice".

The code rules come from Google. The language code is ISO 639-1, with an optional ISO 3166-1 Alpha 2 region, and "You can't specify the country code by itself". Codes outside those lists, "such as es-419, aren't supported", and reserved codes such as UK don't "have an effect on Google Search". URLs must be fully qualified: https://example.com/foo, "not //example.com/foo or /foo" (Google Search Central: Tell Google about localized versions of your page).

Google doesn't name the duplicate-code case. Its HTML method asks for "one link for each page variant including itself", so a code with two URLs leaves Google to guess which page is meant. Treat that one as the tool's own rule.

es-419 is still a valid language tag elsewhere. W3C lists it for "Spanish as used in Latin America" in the HTML lang attribute (W3C: Language tags in HTML and XML). It just isn't supported in hreflang. To target Latin America, list each country, or use es for all Spanish speakers, as this example does.

What hreflang doesn't do

  • It doesn't tell Google what language a page is in. "Google doesn't use hreflang or the HTML lang attribute to detect the language of a page; instead, we use algorithms" (Google Search Central: Tell Google about localized versions of your page). Google reads the visible text, so keep each page in one language and avoid side-by-side translations (Google Search Central: Managing multi-regional and multilingual sites).
  • It doesn't promise indexing or rankings. Google describes hreflang as a way to "point users to the most appropriate version of your page by language or region". The tool's own reminder adds that it "doesn't guarantee that pages are indexed or rank well and doesn't replace canonical tags".
  • It doesn't replace the lang attribute. Still set <html lang="es"> on the Spanish page for browsers and screen readers. W3C says "Always use a language attribute on the html tag", and "You should never use a meta element with the http-equiv attribute set to Content-Language to indicate the language of a page" (W3C: Declaring language in HTML).
  • It isn't a redirect. Don't send visitors to a language automatically. Google advises against redirecting "based on what you think the user's language may be", and suggests links to the other versions instead (Google Search Central: Managing multi-regional and multilingual sites).

Hreflang isn't only for Google, either. Bing's webmaster blog gives the same advice, "Use hreflang to define language and regional targeting" (Bing Webmaster Blog: Does Duplicate Content Hurt SEO and AI Search Visibility?).

Before you publish

  1. Same set everywhere: the English page, the Spanish page and the selector page carry the same three tags, in the <head>.
  2. Self and return links: each page's own URL is in its set, and the validator shows "Verified among the supplied pages" with every page added.
  3. Codes: each starts with a language, such as en or es. There's no country on its own, no en-UK and no es-419.
  4. Full URLs: every URL is written in full, starting with https://.
  5. Language attribute: each page has its own <html lang> value.
  6. After you publish: view the source of each live page and check the tags are there. The validator only reads what you paste. It never fetches your pages, so it can't see a template that drops the tags or a URL that redirects.