Sari la conținutul principal
← 📄 HTML & the platform·Modul A6 · Lecția 9
SarcinăAdd 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 limbi, o ierarhie URL

100 XP8 min
Teorie

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.

🔒

Înregistrează-te pentru a începe să programezi

Teoria e accesibilă tuturor. Editorul, previzualizarea live și verificarea se deblochează cu o probă gratuită de 7 zile — card necesar, anulabilă oricând.

Înregistrare — probă gratuită →

Primele 10 lecții din fiecare traseu sunt gratis. Fără card.

← AnterioarăLecția următoare →

Primește un sfat Python sau web pe zi — prin email

Scurt, scris de mână, fără spam. Dezabonare cu un click.