Aller au contenu principal
← 📄 HTML & the platform·Module A6 · Leçon 9
TâcheAdd hreflang link tags for a 4-language page: en (/post), uk (/uk/post), ru (/ru/post), fr (/fr/post), plus x-default (/post). All absolute URLs starting with https://example.com.

hreflang : 18 langues, une hiérarchie d'URL

100 XP8 min
Théorie

When you have translated pages

Tell Google "here are sibling versions of this page in other languages, route the user to the right one":

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

Rules

  • Every translated page links to ALL siblings (including itself). If you have 18 langs, you have 19 link tags (18 siblings + 1 x-default) on EVERY page.
  • hreflang values are BCP 47: en, uk, en-US, pt-BR, zh-Hans, x-default.
  • `x-default` = the fallback when the user's language doesn't match any explicit hreflang. Usually points to your English URL.
  • Bidirectional confirmation. The UK page must link back to the EN page. If the link is one-way, Google ignores both.

Why it matters

Without hreflang, Google indexes both /post and /uk/post as separate competing pages. They cannibalize each other's rankings. With hreflang, Google knows they're the same content for different audiences — keeps both indexed, shows the right one based on user locale.

Sitemap alternative

For sites with many translations, listing hreflang in the XML sitemap (one entry per URL with embedded alternates) is more maintainable than emitting 19 link tags per page.

CodeMentor uses both

Our buildHreflangLanguages() helper on every page emits the 18 link tags, AND the sitemap includes hreflang for each URL. Belt + suspenders. Google reads either.

🔒

Inscris-toi pour coder

La théorie est ouverte à tous. L'éditeur, l'aperçu live et le check se débloquent avec un essai gratuit de 7 jours — carte requise, annulable à tout moment.

S'inscrire — essai gratuit →

Les 10 premières leçons de chaque parcours sont gratuites. Pas de carte requise.

← PrécédentLeçon suivante →

Recevez une astuce Python ou web par jour — par email

Court, écrit à la main, sans spam. Désabonnement en un clic.