Hreflang Tags for International SEO: How to Use Them and Avoid the Common Mistakes
In this article
Hreflang tags tell Google which language and country each version of a page is for. When you have the same page in German, in British English and in American English, hreflang is how Google knows to show the German page to someone searching from Berlin. The same tag tells it to show the en-GB page to someone searching from Leeds. Without it, Google guesses, and it often guesses wrong.
The tag is simple to write and easy to get wrong at scale. Three rules decide whether it works. Every version of a page must list every version including itself, and every link must be returned by the page it points to. One version should be marked x-default as the fallback. Break any of those and Google quietly ignores the whole set.
Hreflang does not make a page rank. It chooses between pages you already rank with. This guide covers when you need it, how to write it, and the mistakes we see on audits. It also covers how we generate the tags in Django so the return-link rule cannot be broken by hand.
What a hreflang tag is and what it does
A hreflang annotation is a link element in the <head> of a page. One line per language or region version, and the page itself is included in the list:
<link rel="alternate" hreflang="en-GB" href="https://example.com/uk/" />
<link rel="alternate" hreflang="en-US" href="https://example.com/us/" />
<link rel="alternate" hreflang="de" href="https://example.com/de/" />
<link rel="alternate" hreflang="x-default" href="https://example.com/" />
The value has two parts. The language code comes from ISO 639-1 (en, de, fr). The optional region code comes from ISO 3166-1 alpha-2 (GB, US, AU). You can give a language on its own, but never a region on its own: hreflang="GB" is invalid and Google drops it. A script code from ISO 15924 can sit between them where it matters, as in zh-Hant for traditional Chinese.
Google treats hreflang as a signal rather than a directive. When several versions of a page could appear for a query, it swaps in the version that matches the searcher's language and location. It also stops two English pages for different countries being folded together as duplicates with only one ever showing. Bing has said it pays less attention to hreflang and leans on signals such as the content-language meta tag, so on a multi-country site set that as well.
When you need hreflang and when you do not
Google's guidance lists three situations where hreflang applies. The first is the same content translated into several languages. The second is the same language with regional variations (pounds on one page and dollars on another, spelling, delivery terms). The third is a site where only the template is translated and the main content stays in one language. Match any of those and you need the tags on every page that has more than one version.
You do not need hreflang just because you sell abroad. The shops we build show prices in the shopper's own currency on a single set of pages, which is a different problem with a different answer. Stamp and Bake, a cookie cutter shop run from Bristol, ships to the UK, Europe, the USA, Canada and Australia. It shows prices in 22 currencies, all from one English site. One page per product, one URL, no hreflang. The tags only matter once you create separate URLs for separate audiences.
If you are creating separate URLs, decide the structure before you write a tag, because the tags point at URLs and changing the structure later means redirecting everything:
| Structure | Example | Country signal to Google | Cost and effort | Authority |
|---|---|---|---|---|
| Country domain (ccTLD) | example.de | Strong, fixed to that country | A domain per country to buy, host and maintain | Each domain starts from zero |
| Subdirectory | example.com/de/ | Hreflang only | One site, one deployment | Shared with the main domain |
| Subdomain | de.example.com | Hreflang only | Separate DNS and certificate entries | Mostly shared |
| URL parameter | example.com/?lang=de | None; Google advises against it | Trivial | Shared, but messy to crawl and link |
For most UK businesses expanding into two or three markets, subdirectories on the existing domain win: one codebase, one set of backlinks, one certificate, and hreflang does the targeting.
The three rules that make or break it
Every page lists every version, including itself
A page with three versions carries four annotations: the three versions plus x-default. The self-referencing line feels redundant, but Google asks for it and treats the set as incomplete without it. Add a fourth language next year and every existing page needs a new line.
Return links in both directions
If the UK page says the German page is its German version, the German page must say the UK page is its UK version. Google calls these return links and ignores any annotation that is not confirmed from the other side. This is the rule that breaks when tags are maintained by hand: someone adds a translation, annotates the new page and forgets to update the three pages that already existed.
One x-default for the fallback
x-default is the version to show when no language or region in the set matches the searcher. On a site with a language selector, point it at the selector. On a site whose main market is the UK, point it at the en-GB page. Do not leave it out: a searcher in Japan has to land somewhere, and without x-default Google picks for you.
Three more constraints follow. URLs must be absolute, with scheme and host. Every URL in the set must return a 200 status; a redirecting or deleted URL invalidates the annotation that points at it. And every URL must be its own canonical. If /us/ carries a canonical tag pointing at /uk/, you have told Google both that the US page is a separate version and that it is a copy. The canonical wins. The difference between canonical tags and 301 redirects matters here: international versions are neither duplicates to canonicalise nor moves to redirect.
Three places the tags can live
Google reads hreflang from the page head, from an HTTP Link header, or from the XML sitemap. Pick one for the whole site. Using two at once is not safer; it doubles the places where the sets can disagree.
The page head is the link elements shown above, and the usual choice for a Django site because the template that renders the head renders it for every page. The HTTP Link header does the same job for files with no HTML head, such as PDFs. The sitemap route gives each <url> entry an xhtml:link child for every version, including itself, under the xmlns:xhtml="http://www.w3.org/1999/xhtml" namespace. That keeps the HTML lighter on very large sites and lets you regenerate the whole set from the database in one job.
How to use hreflang tags for international SEO, step by step
- Settle the URL structure first. One scheme for the whole site, whether that is a folder such as /de/, a subdomain or a country domain, and a list of the pages that will genuinely be translated. Tags on pages that are not translated do more harm than good.
- Write the codes correctly. A language code from ISO 639-1, optionally followed by a region code from ISO 3166-1: en-GB, de-DE, or plain fr for every French speaker. en-UK is not a code, and uk on its own means Ukrainian.
- Give every page the full set. One line per version, including the page itself, plus one x-default pointing at the language selector or at your main market's page.
- Make the links return. Each version must list every other version. Generate the set from the framework or the database rather than typing it, because hand-maintained sets break the first time a translation is added.
- Put the tags in one place. The page head, an HTTP Link header or the XML sitemap. Not two of them, which doubles the places the sets can disagree.
- Check and recheck. Every URL in a set must return 200, be its own canonical and not redirect. Crawl the site with a tool that lists missing return links, fix what it finds, and look at URL Inspection in Search Console a few weeks later to confirm what Google fetched.
The sections below explain why each step matters and show the mistakes that most often undo them.
The mistakes we find on audits
- Made-up codes.
en-UKis the most common. The ISO code for the United Kingdom isGB;UKis not a country code, andukas a language code means Ukrainian. - Region with no language.
hreflang="FR"says nothing to Google. Writefr-FR, orfrif the page serves every French speaker. - Pointing at redirects. A site moves from
/de/to/de-de/, the redirects go in, and the annotations still name the old URL. Each one now points at a 301 and is discarded. - Redirecting visitors by IP address. Googlebot crawls mostly from US addresses. If the site bounces every US visitor to
/us/, Googlebot never sees the UK or German pages. Offer the local version with a banner instead. - Annotating pages that are not translated. If the German site has no page for a product, do not list a German version that is just the English page at a German URL. Either translate it or leave the German line off that page's set.
Generating the tags in Django
Hand-maintained hreflang fails the return-link rule within months on any growing site. On a Django site with i18n_patterns, the framework already knows every language a URL exists in. So the tags can be generated from that knowledge and never disagree with each other. A small template tag does it:
# seo/templatetags/hreflang.py
from django import template
from django.conf import settings
from django.urls import translate_url
from django.utils.safestring import mark_safe
register = template.Library()
@register.simple_tag(takes_context=True)
def hreflang_links(context):
request = context["request"]
base = request.build_absolute_uri("/").rstrip("/")
lines = []
for code, _name in settings.LANGUAGES:
url = translate_url(request.path, code)
lines.append(f'<link rel="alternate" hreflang="{code}" href="{base}{url}">')
default = translate_url(request.path, settings.LANGUAGE_CODE)
lines.append(f'<link rel="alternate" hreflang="x-default" href="{base}{default}">')
return mark_safe("\n".join(lines))
Put {% hreflang_links %} in the head of the base template and every page gets a complete, self-referencing, reciprocal set from one source of truth. Two refinements make it production-ready. The first is to skip any language the current object is not translated into. The second is to build from the canonical path rather than request.path, so a page reached with tracking parameters still annotates its clean address. Prices, delivery copy and product schema with the right currency then follow the language code through the same templates.
Questions people ask
Does hreflang improve rankings?
No. It changes which of your pages Google shows to a given searcher and stops regional versions competing with each other. If none of the versions rank, the fix is the content and the links, not the tags.
Do I need hreflang for en-GB and en-US pages?
Yes, if they are separate URLs. Without the annotation Google will usually show one of them everywhere, often the wrong one for your main market.
What does x-default actually do?
It names the page to show when the searcher's language and country match none of the versions in the set. It is usually the language selector or the version for your home market.
Where to start
If you are planning your first second-language version, settle the URL structure first, then the list of pages that will genuinely be translated, and only then the tags. Generating them from the framework rather than typing them is the one decision that keeps the return-link rule intact as the site grows. Our guide to planning a custom e-commerce website covers where multi-currency and multi-language decisions sit in the build.
If the tags already exist and you are not sure they work, crawl the site. Search Console no longer has an International Targeting report, so hreflang errors do not arrive by email. Screaming Frog has a hreflang tab that lists missing return links, non-canonical targets and invalid codes in one pass. The crawler script in our technical SEO audit checklist can be extended to compare each page's set against the sets on the pages it names.
URL Inspection in Search Console shows the HTML Google actually fetched. Our website health check confirms the basics around the tags: each version returns 200, serves over HTTPS and declares a canonical. Fix the codes and the return links, make sure nothing points at a redirect, and give Google a few weeks to recrawl.