What you need
The URLs of every language or regional version of a page, and the ability to edit the <head> of each page (or your XML sitemap).
The same page in the three output formats
For an English page with Spanish and Canadian French versions, the HTML form is:
<link rel="alternate" hreflang="en" href="https://example.com/pricing" />
<link rel="alternate" hreflang="es" href="https://example.com/es/pricing" />
<link rel="alternate" hreflang="fr-CA" href="https://example.com/fr-ca/pricing" />
<link rel="alternate" hreflang="x-default" href="https://example.com/pricing" />
The sitemap form carries the same information in one url entry:
<url>
<loc>https://example.com/pricing</loc>
<xhtml:link rel="alternate" hreflang="en" href="https://example.com/pricing" />
<xhtml:link rel="alternate" hreflang="es" href="https://example.com/es/pricing" />
<xhtml:link rel="alternate" hreflang="fr-CA" href="https://example.com/fr-ca/pricing" />
<xhtml:link rel="alternate" hreflang="x-default" href="https://example.com/pricing" />
</url>
(The sitemap needs the xmlns:xhtml="http://www.w3.org/1999/xhtml" namespace on the root element.) Files such as PDFs have no head, so send the same annotations in an HTTP Link header instead.
Rules that decide whether the tags work
| Rule | Why |
|---|---|
| Every version lists every version, itself included | The annotations must be reciprocal or they are ignored |
| Use absolute URLs | Relative URLs are easy to get wrong |
Language first, optional region second (en-GB) |
A region alone, such as GB, is not valid |
x-default names the fallback |
It serves visitors whose language you do not cover |
| Canonical points to the version's own URL | A canonical pointing to another language cancels the annotation |
Common pitfalls
- One-way links. If the English page lists Spanish but the Spanish page does not list English, both are ignored.
- Wrong codes.
en-UKshould been-GB;jpshould beja. - Pointing at redirects. Every URL in the set should return a normal page.
- Mixing methods inconsistently. If the head and the sitemap disagree, you are asking search engines to guess.
Going further
The role of titles, descriptions and canonical URLs is covered in How SEO Meta Tags Work.