skip to content

A shop serves the same product page at /en-gb/kettle and /de-de/wasserkocher. How should `<link rel="alternate" hreflang="…">` be set up across those pages, and how does it interact with each page's canonical?

level: seniorimportance: nice to knowfreq 22%

answer

  1. equivalents, not duplicates
  2. every page names the whole set
  3. include a link to yourself
  4. language code, optional region
  5. each localisation canonicals to itself

basics

~20 s

Every page in the language set lists the full set of alternates, including a link to itself, using matching language-region codes plus an optional x-default. Each page keeps a canonical pointing at itself — canonicalising one localisation to another collapses the set.

solid answer

~50 s

Each localised page carries a `<link rel="alternate" hreflang="…" href="…">` for every version in the set, including one pointing at itself, and the values must agree across all of them — the annotation is only trusted when it is reciprocal, so if the German page claims the English one but the English page does not claim back, the pair is ignored. The code is an ISO 639-1 language, optionally with an ISO 3166-1 Alpha-2 region, as in `en`, `en-gb`, `de-de`; you can add `hreflang="x-default"` for the fallback shown when nothing matches. The critical interaction is with the canonical: each localised page must self-canonicalise. If the German page canonicalises to the English URL, you have told the engine the German page is a duplicate that should not be indexed at all, which destroys the alternate set you just declared. The same annotations can also be delivered in a sitemap, which is easier to keep consistent for a large set.

code

html · 14 lines
html
<!doctype html>
<html lang="de">
  <head>
    <meta charset="utf-8">
    <title>Wasserkocher</title>
    <link rel="canonical" href="https://shop.example/de-de/wasserkocher">
    <link rel="alternate" hreflang="en-gb" href="https://shop.example/en-gb/kettle">
    <link rel="alternate" hreflang="de-de" href="https://shop.example/de-de/wasserkocher">
    <link rel="alternate" hreflang="x-default" href="https://shop.example/en-gb/kettle">
  </head>
  <body>
    <h1>Wasserkocher</h1>
  </body>
</html>

go deeper

for a junior

Know that <link rel="alternate" hreflang="…"> marks language or region versions of the same page, and that the value is a language code optionally followed by a region, such as en-gb.

for a middle

Explain reciprocity — every page lists the whole set including itself, or the annotation is dropped — and be able to write a correct block for a two-locale example with valid codes and absolute URLs.

for a senior

Demonstrate the canonical interaction: each localisation self-canonicalises, and a cross-locale canonical or a noindex removes that page from the set entirely. Be ready to say how you would audit a live set and what a broken return tag looks like.

for a principal

Own the delivery decision for scale: head links versus a generated sitemap for a large locale matrix, who owns locale URLs, and how the set is validated automatically so a new market cannot ship a half-wired locale.

## What hreflang is for When the same content exists in several languages or regional variants, you do not want them treated as duplicates of one another, and you do not want a British visitor landing on the German page. `rel="alternate"` with an `hreflang` attribute annotates the set: it says "these URLs are equivalents of each other, targeted at these audiences". A search engine uses it to swap in the right version for the right user, not to change how any of them rank. ## The markup On `https://shop.example/en-gb/kettle`: ```html <link rel="alternate" hreflang="en-gb" href="https://shop.example/en-gb/kettle"> <link rel="alternate" hreflang="de-de" href="https://shop.example/de-de/wasserkocher"> <link rel="alternate" hreflang="x-default" href="https://shop.example/en-gb/kettle"> <link rel="canonical" href="https://shop.example/en-gb/kettle"> ``` On `https://shop.example/de-de/wasserkocher` the alternate block is **identical** — the same list, in the same values — and only the canonical differs, pointing at the German URL. ## The three rules that make or break it **1. Reciprocity.** Every page in the set must list every member of the set, itself included. The self-referencing alternate is the part people forget. If page A names page B but B does not name A, the annotation is treated as unconfirmed and dropped — one page's claim about another is not evidence, since anyone could point at anyone. **2. Valid codes.** The value is an ISO 639-1 language code, optionally followed by a region as an ISO 3166-1 Alpha-2 code: `de`, `de-at`, `pt-br`. Region alone is invalid — `hreflang="uk"` means Ukrainian, not the United Kingdom, and there is no way to say "United Kingdom, any language" other than by naming the language too. `x-default` is the one special value, marking the page to show when no listed audience matches. **3. Self-canonicalisation.** This is the interaction interviewers actually probe. hreflang says "these are equivalent alternatives, all of which should be indexable"; a canonical says "this one is a duplicate, index that one instead". Pointing the German page's canonical at the English URL asks the engine to drop the German page — and a page that is not indexed cannot be served as an alternate. The two annotations must agree: each localisation self-canonicalises, and the alternate set does the cross-linking. For the same reason, a page in the set must not be `noindex`. An excluded page cannot be an alternative to anything. ## Where to put the annotations Three delivery mechanisms carry the same information: - `<link>` elements in the head — the form you write by hand and the one that shows up in interviews. - Response headers, for non-HTML resources such as PDFs. - An XML sitemap, where each URL entry lists its alternates. The head form grows quadratically: with twenty locales, every one of twenty pages carries twenty links, and a single mistake breaks reciprocity for a pair. The sitemap form keeps the whole matrix in one generated file, which is why large multilingual sites usually prefer it. Whichever you choose, generate it — hand-maintained hreflang blocks drift within weeks. ## Common failures - **Missing self-reference.** The most frequent cause of a set being ignored entirely. - **Relative or non-absolute URLs**, or URLs that redirect. Point at the final, canonical URL of each localisation. - **Region-only codes** and invented values like `en-uk` (the correct code is `en-gb`). - **Alternates pointing at pages that 404, redirect, or are noindexed.** - **Language-switcher UX confused with hreflang.** The annotation helps search results; it does not automatically redirect a visitor, and auto-redirecting by IP on top of it can prevent alternates from being crawled at all. - **Assuming it affects ranking.** It affects which version is shown to whom, not how well the content ranks. ## How to check it Fetch each page's raw HTML and diff the alternate blocks — they should be identical across the set apart from the canonical. Confirm every `href` returns 200 without a redirect. If you deliver via sitemap, validate that every URL entry lists the full set. Search Console reports hreflang problems for a verified property, with "no return tag" being the standard name for a broken reciprocity pair.

  • What does `hreflang="x-default"` do?
    It marks the URL to serve when none of the listed language or region targets matches the user — typically a global English page or a country-selector landing page. It is optional, only one page in the set should claim it, and it does not replace the need for each real locale to be listed.
  • Why can hreflang annotations be delivered in a sitemap instead of the head?
    Because the annotation is a matrix: n locales means n links on each of n pages, and one omission breaks a pair. A sitemap holds the whole matrix in a single generated file, which is far easier to keep reciprocal and to validate. The semantics are identical either way.
  • Does hreflang improve how a page ranks?
    No. It influences which localisation is shown to a given user and stops equivalents being treated as duplicates of each other. Rankings come from the content and its signals; a correct hreflang set mainly prevents the wrong-language result and the self-competition, rather than lifting the set.

saying these in an interview costs you the question

  • Omits the self-referencing alternate from each page
  • Canonicalises every localisation to the English version
  • Uses region-only codes such as hreflang="uk"
  • Points alternates at URLs that redirect
  • Claims hreflang boosts rankings in each market

context