Hreflang step by step: how to mark it up without mistakes
Hreflang is an annotation that tells Google which pages are versions of the same page in other languages or regions. It works if each version lists all of them, itself included, and they all link back to each other. Here is how to do it on a Swiss website and how to check it’s right.
What hreflang does and doesn’t do
Hreflang tells Google that two or more URLs are the same page in different languages or regions, so it can show each person theirs. Someone searching in French from Lausanne should see ejemplo.ch/fr/, not ejemplo.ch/de/.
Hreflang doesn’t tell Google which language a page is in. Google works that out from the visible text and uses neither hreflang nor the lang attribute for it. So the basics come before hreflang: one URL per language and a single language on each page.
Google ignores location meta tags such as geo.position. There’s no need to add them.
The codes: language and, optionally, region
The hreflang value is an ISO 639-1 language code, optionally followed by a hyphen and an ISO 3166-1 alpha-2 region code. For a Swiss website, these are the usual ones:
| Code | Who it’s for |
|---|---|
| de-CH | German readers in Switzerland |
| fr-CH | French readers in Switzerland |
| it-CH | Italian readers in Switzerland |
| rm-CH | Romansh readers in Switzerland |
| en | English readers, in any country |
| de | German readers, in any country |
| x-default | Anyone who doesn’t fit any of the above |
Worth knowing about the codes:
- A country on its own doesn’t work. “CH” is not a valid value.
- Lower-case “ch” isn’t Switzerland either: it’s the language code for Chamorro, a language of the Mariana Islands.
- Upper or lower case doesn’t matter (de-ch works), but the region in capitals is the usual form.
- Google ignores the region part if you use codes that aren’t countries, such as EU, UN or UK. For the United Kingdom it’s en-GB.
The three ways to mark it up
You can declare hreflang in the HTML, in the HTTP header or in the XML sitemap. For Google the three are equivalent, and using several at once adds nothing. Choose the one that suits your website best and stick to it.
| Method | When to use it | Watch out for |
|---|---|---|
| Link tags in the HTML head | Small or medium-sized websites; each page carries its own block | Every new version means editing all the others |
| HTTP Link header | Files that aren’t HTML, such as a PDF price list | It’s configured on the server |
| XML sitemap | Large websites or ones with many versions | It has to be kept up to date and submitted to the search engines |
Step by step with tags in the HTML
Here is a typical case: a .ch website with four languages in subfolders. Each page carries a block with all the versions in its head.
- List the versions of each page. For example, the prices page exists at /de/preise/, /fr/tarifs/, /it/tariffe/ and /en/prices/.
- Choose the code for each version: de-CH, fr-CH, it-CH and en.
- Decide which page gets x-default. Google suggests it for language selectors; if you don’t have one, point it at the version that best serves visitors from elsewhere.
- Write the block with full URLs, including https://, and include the page itself.
- Put the same block on all four versions. The page content changes; the list doesn’t.
<link rel="alternate" hreflang="de-CH" href="https://ejemplo.ch/de/preise/" />
<link rel="alternate" hreflang="fr-CH" href="https://ejemplo.ch/fr/tarifs/" />
<link rel="alternate" hreflang="it-CH" href="https://ejemplo.ch/it/tariffe/" />
<link rel="alternate" hreflang="en" href="https://ejemplo.ch/en/prices/" />
<link rel="alternate" hreflang="x-default" href="https://ejemplo.ch/en/prices/" />
If the block comes from a template that reads the list of versions, it’s almost impossible to forget a return link. Written by hand on every page, it’s easy.
With a sitemap or an HTTP header
In the sitemap, each URL carries its versions as xhtml:link elements. The full block is repeated inside each entry, including the URL itself.
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xhtml="http://www.w3.org/1999/xhtml">
<url>
<loc>https://ejemplo.ch/de/preise/</loc>
<xhtml:link rel="alternate" hreflang="de-CH" href="https://ejemplo.ch/de/preise/" />
<xhtml:link rel="alternate" hreflang="fr-CH" href="https://ejemplo.ch/fr/tarifs/" />
<xhtml:link rel="alternate" hreflang="it-CH" href="https://ejemplo.ch/it/tariffe/" />
<xhtml:link rel="alternate" hreflang="en" href="https://ejemplo.ch/en/prices/" />
<xhtml:link rel="alternate" hreflang="x-default" href="https://ejemplo.ch/en/prices/" />
</url>
<!-- Repeat the block in the entries for /fr/tarifs/, /it/tariffe/ and /en/prices/ -->
</urlset>
A PDF has no head to put tags in. For those files, use the HTTP Link header, which the server sends along with the file:
Link: <https://ejemplo.ch/docs/tarife.pdf>; rel="alternate"; hreflang="de-CH", <https://ejemplo.ch/docs/tarifs.pdf>; rel="alternate"; hreflang="fr-CH"
Self-references, return links and x-default
Three rules hold the whole system together, and they’re worth going through one by one.
- Self-reference: the /fr/tarifs/ page includes its own link with fr-CH. Without it, the list is incomplete.
- Return links: if /de/preise/ points to /fr/tarifs/, then /fr/tarifs/ has to point to /de/preise/. If either one is missing, Google ignores that pair.
- x-default: the option for people searching in a language that isn’t on your list. Google suggests it for language selectors and for home pages that redirect based on the visitor.
Not every page has to exist in every language. If an article is only in German and French, its block lists those two versions, plus x-default if you like. Google processes the pairs that do link to each other.
When you publish a new version, link it first, both ways, with the version it comes from; usually the one in your main language. That’s what Google recommends.
Hreflang and canonical, together
Each version needs a canonical in its own language, usually itself. If every language points its canonical to the German version, you’re telling Google the French is a copy of the German, and that clashes with the hreflang.
Google puts it this way: the canonical has to be in the same language or, if there isn’t one, in the closest substitute. And a canonical tag with an hreflang attribute doesn’t work for canonicalisation. For the versions, use rel="alternate".
There is one special case: two versions in the same language for different countries, such as de-CH and de-DE. If they’re almost identical, Google recommends choosing a preferred version and using canonical and hreflang so each person sees the URL for their region. Better still: make them genuinely different, with each country’s prices, contact details and vocabulary.
How to check it’s right
Search Console no longer has the International Targeting report, so the checking is up to you. Google still uses hreflang, but today it has no dedicated report to warn you about mistakes.
- Open the source code of each version and look for the rel="alternate" links. The list has to be the same on all of them.
- For PDFs or headers, look at the server response in your browser’s developer tools or with curl -I.
- Open each URL on the list. It should respond without redirecting and be its own canonical.
- Check the codes one by one: no country on its own, no “ch” and no “UK”.
- If you use a sitemap, check that it has been submitted in Search Console and Bing Webmaster Tools, and that each entry repeats the full block.
- On large websites, run a crawler that cross-checks the versions and lists the links with no return link.
Arrampa’s audit, which we use in-house today, runs 14 hreflang checks on every crawl, including the HTTP header and the sitemap, and flags any page that doesn’t declare the lang attribute. It will open to clients later.
The most common mistakes
These mistakes appear in Google’s documentation or break the logic of the pairs:
| Mistake | Consequence | Fix |
|---|---|---|
| Missing return link | Google ignores that pair | The same block on every version |
| Missing self-reference | The list doesn’t follow Google’s rule | Always include the page itself |
| Relative URLs (/fr/tarifs/) | Not valid: they have to be full URLs | https://ejemplo.ch/fr/tarifs/ |
| Country only (“CH”) | Invalid code | fr-CH |
| “en-UK” | Google ignores the region | en-GB |
| Canonical pointing to another language | The signals contradict each other | Canonical in the same language |
| Hreflang pointing to URLs that redirect | The signals contradict each other | Point to the final URL |
What about Bing?
Bing’s webmaster guidelines don’t mention hreflang. What they do ask for works just as well on a multilingual website: sitemaps with canonical URLs only, IndexNow notifications when something changes and a single URL for each piece of content.
So beyond the tag, each version needs its own URL, its own canonical and a clear language in the text itself. Submit the same sitemap to Google and Bing so both see all your versions.
FAQ
Do I have to add x-default?
It isn’t mandatory. It’s for people searching in a language you don’t offer. If you have a language selector or a home page that redirects, that’s where it belongs.
Can I combine tags and a sitemap?
You can, but you gain nothing: for Google they’re equivalent. If you do, both lists have to say the same thing.
Does hreflang replace the lang attribute?
No. Hreflang links versions; the lang attribute declares the page language for browsers and screen readers. Use both.
Which code do I use for English in Switzerland?
If your English version serves anyone who reads English, “en”. If it’s only for Switzerland, with prices in francs and local contact details, you can use “en-CH”.
Sources
- Google Search Central: Localized versions of your pages
- Google Search Central: Managing multi-regional and multilingual sites
- Google Search Central: How to specify a canonical with rel="canonical" and other methods
- Search Console Help: The International Targeting report is deprecated
- W3C: Understanding WCAG 2.2 Success Criterion 3.1.1, Language of Page
Tools that help
- SEO auditChecks your site rule by rule, hreflang included.
- AI-ready websiteWhether AI assistants can read your site, and which questions you’re missing.
- Keyword and page mapWhich page should show up for each search, language by language.
Glossary terms
- HreflangThe annotation that tells Google which version of a page belongs to each language and country.
- x-defaultThe hreflang value that says which version to show when no language or country on the list matches the user.
- Language and region codesThe value that identifies a page’s language and, if needed, its country: de-CH is German for Switzerland.
- Canonical tagA line of code that tells Google which is the main address of a page when copies exist.
- XML sitemapA file listing the addresses on your site you want search engines to find.
- Google Search ConsoleGoogle’s free service that shows you how your site appears in search and what problems it finds.
- IndexingThe step in which Google analyses a crawled page and stores it in its index so it can show it.
Other guides
- SEO for a multilingual website in SwitzerlandA multilingual website ranks in Switzerland when each language has its own URL, copy written for that region and keywords researched in that language. The versions are linked with hreflang and measured separately. Here is the method, with what Google and Bing say.
- German for Switzerland or for GermanyIf your customers are in Switzerland, write in Swiss Standard German: no “ß”, the words people use here and prices in francs. A separate de-DE version only pays off if you also sell in Germany and have demand there. This guide explains the differences that matter for SEO and how to mark them up.
- Keywords in four languagesTo rank in four languages, research each language’s keywords from scratch: seed keywords written by someone from the region, real searches from autocomplete and Search Console, intent and topic groups. In the end, each group has a page in each language. Here is how to do it, step by step.
- Local SEO in Switzerland across languagesTo appear in local searches in Switzerland, each real location needs its own page in every language it serves, with the town’s name as it’s written in that language. Your name, address and phone number have to match on the website, on your Google profile and in directories. This guide explains how, with examples.
- Your multilingual website in AI answersFor an AI to cite your website, it first has to be able to find and read it: indexed in the search engines, open to the robots that search in order to answer, and with clear answers in each language. There is no separate trick, and Google says so in its documentation. This guide separates what works from what is just being sold.
Want to know when we open?
One email to confirm and one on the day we open. Nothing else.