SEO

Canonical and hreflang: how to implement them properly (and the mistakes that cancel them)

What the canonical tag does, what hreflang does, how to combine them on a multilingual site with x-default, and the mistakes that make Google ignore them.

The rel="canonical" tag tells search engines which URL is preferred when the same content is reachable from several addresses. The hreflang attributes tell them which versions in other languages or regions exist for the same page. They do not compete: canonical consolidates duplicates within one language and hreflang relates equivalents across languages. Every language version must have its own self-referencing canonical and a complete set of hreflang links pointing to all the others, itself included.

This article explains how to implement both correctly, what x-default is for and which concrete mistakes make Google ignore them.

What the canonical URL is

The same page is usually reachable from several URLs: with and without a trailing slash, with tracking parameters (?utm_source=...), with www and without it, over HTTP and HTTPS. To search engines those are different addresses. If you do not say which one you prefer, they will choose one on their own and split the signals among all of them.

<link rel="canonical"> resolves that ambiguity from the <head>:

<link rel="canonical" href="https://blog.aimran.es/en/articles/canonical-and-hreflang-how-to-implement/" />

Basic rules, according to Google’s documentation:

  • Use absolute URLs, with protocol and domain.
  • A single canonical tag per page. If there are several, Google ignores them all.
  • Point to a URL that returns 200 and is indexable. A canonical to a noindex page or to a redirecting page is contradictory.
  • The self-referencing canonical (the page pointing to itself) is correct and recommended: it states explicitly which is the right version.

Google treats the canonical as a strong signal, not a directive. If the content of the canonical URL does not resemble that of the page declaring it, it may choose another one. That is why canonical does not work to “redirect” different pages; that is what 301 is for.

What hreflang is

hreflang states that a page has equivalent versions in other languages or regions, so the search engine can show each user the one that matches their language. It is declared in the <head> with one tag per version:

<link rel="alternate" hreflang="es" href="https://example.com/es/guia/" />
<link rel="alternate" hreflang="en" href="https://example.com/en/guide/" />
<link rel="alternate" hreflang="x-default" href="https://example.com/es/guia/" />

Values use ISO 639-1 language codes (es, en) and, optionally, ISO 3166-1 alpha-2 regions (es-MX, en-GB). There is no region-only code: hreflang="mx" is invalid.

The two rules almost everyone breaks

  1. Reciprocity. If the Spanish page links to the English one with hreflang, the English one must link back to the Spanish one. Google calls these “return links”; without them, the annotations are ignored.
  2. Self-reference. Every page also includes a hreflang pointing to itself. The set of tags must be identical across all versions.

x-default

x-default indicates which version to show when no declared language matches the user’s (or when you have a language selector). It usually points to the site’s main language. It is not mandatory, but it is recommended.

Where to declare it

There are three equivalent places; pick one and be consistent:

  • <link> tags in the <head> (the usual choice for HTML pages).
  • The HTTP Link: header (for PDFs and other non-HTML files).
  • The XML sitemap, with <xhtml:link> elements inside each <url>. This is the most convenient option when there are many pages, because a generator can keep reciprocity automatically.

How canonical and hreflang combine

This is the part that causes the most confusion. The rule is simple: each version’s canonical points to itself, and hreflang points to all versions.

Page canonical hreflang
/es/guia/ /es/guia/ es → /es/guia/, en → /en/guide/, x-default → /es/guia/
/en/guide/ /en/guide/ es → /es/guia/, en → /en/guide/, x-default → /es/guia/

The serious mistake is to set the Spanish URL as the canonical of the English version. That tells Google the English page is a duplicate of the Spanish one and should not be indexed, which cancels hreflang entirely. They are two different pages (different languages); each one is canonical of itself.

Checklist

  1. A single canonical tag per page, absolute, pointing to a 200, indexable URL.
  2. Each language’s canonical points to its own URL.
  3. hreflang with valid codes (language, or language-REGION).
  4. The same set of hreflang tags on every version, self-reference included.
  5. x-default pointing to the default version.
  6. hreflang URLs match the canonicals exactly (same trailing slash, same protocol).
  7. If a version is removed, it is removed from the hreflang of all the others.

Common mistakes

  1. Relative URLs in canonical or hreflang. Google recommends absolute ones; relative ones are easily misinterpreted.
  2. Canonical to the home page on every page due to a template error. More common than it seems, and it deindexes the whole site.
  3. hreflang without return links. The number one cause of “no return tags” in Search Console.
  4. Mixing languages in one URL. If /guide/ shows Spanish or English depending on the browser, there is no URL per language and hreflang cannot work. Each language needs its own URL.
  5. Canonical to a URL with parameters or without HTTPS. Always point to the clean, secure version.

How to check

In Search Console, the URL inspection tool shows which URL Google has chosen as canonical against the one you declare. If they differ, review duplicate content, redirects and internal links: Google tends to pick the URL that receives the most internal links. For hreflang, any validator that checks reciprocity between versions will save you hours; you can also generate the tags from a single source of routes (as this blog does) so they can never drift apart.

Conclusion

Canonical answers “which of these duplicate URLs do you want indexed?” and hreflang answers “which language versions of this page exist?”. Implement the first as self-referencing and absolute, the second as a complete, reciprocal set with x-default, and never use canonical to join different languages. If you can, generate both automatically from the same source of truth: most mistakes appear when they are maintained by hand.

Sources and references

  1. Google Search Central: How to specify a canonical with rel="canonical" and other methods developers.google.com
  2. Google Search Central: Tell Google about localized versions of your page developers.google.com
  3. Google Search Central: Managing multi-regional and multilingual sites developers.google.com
  4. sitemaps.org: Sitemaps protocol sitemaps.org

Related tools

Herramientas gratuitas de AIMRAN Tools que funcionan en tu navegador, sin registro.

Ver todas las herramientas
  • Meta tags generator

    Generate title, meta description, Open Graph and Twitter Cards for a page.

Articles in SEO