Skip to content
Tutorials Center
My learning

Topics

Lesson 29 of 36 ยท Local and International SEO

International SEO and hreflang

Learn how to target multiple countries and languages: URL structures, hreflang annotations with return links, x-default, localization and a Python hreflang validator.

If your site serves people in different countries or languages, search engines need to know which version to show to whom. A Spanish speaker in Mexico should see your Spanish page, not the English one, and a UK shopper should see prices in pounds. International SEO is the set of decisions and annotations that make this work.

First distinguish two goals: language targeting (the same content in French, German, Spanish) and country targeting (English content tailored to the US, UK and Australia, with different prices, spelling, shipping and laws). Many sites need both.

Choosing a URL structure

Structure Example Pros Cons
ccTLD example.fr, example.de Strong country signal, clear to users Costly, separate sites to maintain, each starts with its own authority
Subdomain fr.example.com Easy to host separately Treated somewhat separately; weaker shared authority
Subdirectory example.com/fr/ Shares the main domain's authority, simplest to maintain One server location, less obvious country signal
URL parameter example.com?lang=fr Quick to implement Messy and not recommended

For most sites, subdirectories are the best balance. Whatever you pick, each language or country version needs its own crawlable URL. Do not switch languages with cookies, IP detection or JavaScript on the same URL, because crawlers will see only one version and never index the others.

hreflang annotations

hreflang tells search engines which pages are alternates for different languages or regions, so they can serve the right one. A value is a language code, optionally followed by a region: en, en-GB, es-MX, pt-BR, zh-Hant. Use ISO 639-1 language codes and ISO 3166-1 alpha-2 region codes. (The region cannot be used alone, and en-UK is wrong: the code is GB.)

You can add it in three places: the HTML <head>, HTTP headers (useful for PDFs), or the XML sitemap.

HTML
<link rel="alternate" hreflang="en" href="https://example.com/en/shoes">
<link rel="alternate" hreflang="es-MX" href="https://example.com/mx/zapatos">
<link rel="alternate" hreflang="fr" href="https://example.com/fr/chaussures">
<link rel="alternate" hreflang="x-default" href="https://example.com/">

The rules that most often go wrong:

  1. Return links: if page A lists page B as an alternate, page B must list page A back. Without reciprocity the annotation is ignored.
  2. Self-reference: each page lists itself among its alternates too.
  3. Absolute URLs that return 200, are indexable and match the canonical URL of each page.
  4. Valid codes only.
  5. x-default: names the fallback page for users whose language does not match (often a language picker or the main version).
  6. Keep canonicals self-referential per language version; do not point all translations' canonical to the English page.
flowchart LR
  EN["/en/shoes"] <-->|hreflang| ES["/mx/zapatos"]
  EN <-->|hreflang| FR["/fr/chaussures"]
  ES <-->|hreflang| FR
  X["x-default: /"] --> EN

Every version lists every other version, and each links back.

Python hreflang validator

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The English page is fine. The Mexican page forgets the French alternate, and the French page uses the invalid code en-UK and omits the Mexican page. Real validators check much more, but self-references, complete sets, reciprocity and valid codes catch most errors.

Localization, not just translation

  • Translate by people, not by unreviewed machine output. Poorly translated pages harm trust and may be treated as low quality.
  • Localize details: currency, units, date formats, spelling variants (color and colour), examples, legal text, contact details and payment methods.
  • Research keywords per market. People in different countries phrase the same need differently, so do not just translate English keywords (the Keyword Research chapter of this course covers the method).
  • Make language switching visible and manual, and do not auto-redirect users by IP; they may travel or prefer another language.
  • Set <html lang="fr"> for each page; it helps accessibility tools and tells browsers the language.
Language-aware page

Geotargeting settings and other signals

Besides hreflang, engines look at the ccTLD, the language of the content, the currency, local addresses and phone numbers, links from local sites and (to a smaller extent) server location. Country targeting tools in webmaster consoles have been reduced over time, so do not rely on a single setting.

Common international mistakes

  • Serving different languages from one URL.
  • Missing return links or wrong codes in hreflang.
  • Redirecting by IP so crawlers only ever see one version.
  • Translating only the body text and leaving navigation, titles and metadata in the original language.
  • Duplicate English pages for different countries with no hreflang and no real differences.

If two regional versions are nearly identical (for example the US and Canada in English), engines may fold them together. Differentiate with local content or accept that one page serves both.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What is required for hreflang to work between two pages?

    hreflang annotations must be reciprocal; without return links they are ignored.
  2. 2. Which hreflang value is valid for British English?

    The language code is en and the region code is GB, so en-GB.
  3. 3. What does x-default specify?

    x-default points to a general or language-selector page for unmatched users.
  4. 4. Why should language versions have separate URLs?

    If one URL changes language by cookie or script, crawlers will see only one version.

Summary

  • Decide whether you target languages, countries or both.
  • Subdirectories are usually the simplest structure; each version needs its own URL.
  • Use hreflang with return links, self-references, valid codes and x-default.
  • Localize content, keywords and details, not only words.
  • Avoid IP-based redirects and unreviewed machine translation.

Next: E-commerce and Large Site SEO