If your website has versions for different countries or languages, such as an English site for the US and the UK, or English and French versions for Canada, you've probably run into hreflang. It has a reputation for being confusing, and a small mistake can mean it doesn't work at all.

It doesn't have to be a headache. This guide explains what hreflang does, when you need it and how to set it up step by step.

What is hreflang?

Hreflang is an attribute that tells search engines a page has alternative versions for different languages or regions, and which version is meant for whom. When a French-speaking searcher in Canada looks for your product, hreflang helps Google show them your French Canadian page rather than your US English one.

It doesn't make pages rank higher on its own. It makes sure the right version of a page appears to the right people, which improves clicks and conversions and avoids your own pages competing with each other.

When do you need it?

You need hreflang if:

  • You have the same content translated into different languages.
  • You have the same language for different regions with differences that matter, such as currency, spelling, shipping or prices (for example US, UK and Australian English).
  • Searchers are landing on the wrong country or language version of your site.

You don't need it if your site is in one language for one market.

Getting the codes right

Hreflang values use a language code, optionally followed by a region code:

  • Language: ISO 639-1 format, such as en, fr, de, es.
  • Region (optional): ISO 3166-1 alpha-2 format, such as us, gb, ca, in.

So en-gb means English for the United Kingdom, and fr-ca means French for Canada. A common mistake is using en-uk. The correct region code for the United Kingdom is gb. You can't target a region on its own: a language code is always required.

Three ways to add hreflang

1. In the HTML head

Add a link element for every version in the <head> of each page:

<link rel="alternate" hreflang="en-us" href="https://example.com/us/" />
        <link rel="alternate" hreflang="en-gb" href="https://example.com/uk/" />
        <link rel="alternate" hreflang="fr-ca" href="https://example.com/ca-fr/" />
        <link rel="alternate" hreflang="x-default" href="https://example.com/" />

This is the most common method and works well for most websites.

2. In your XML sitemap

For large sites, it's often easier to list the alternate versions in your sitemap rather than in every page's code. It does the same job and keeps page templates lighter.

3. In HTTP headers

For non-HTML files such as PDFs, you can send hreflang in the HTTP response header. Most businesses won't need this.

Choose one method and use it consistently. Mixing methods makes errors harder to find.

The rules that make it work

  • Return links: if page A says page B is its French version, page B must say page A is its English version. Without these return links, Google may ignore the annotations.
  • Self-reference: each page should include an hreflang entry pointing to itself.
  • Use full, absolute URLs, including https.
  • Point to canonical, indexable pages. Don't reference URLs that redirect, return errors or are canonicalised elsewhere.
  • Add x-default for a fallback page, such as a language selector or your main international page, for visitors who don't match any target.

Common mistakes

  • Missing return links between versions.
  • Wrong codes, such as en-uk or using a country code without a language.
  • Hreflang pointing to redirected or non-canonical URLs.
  • Automatically redirecting visitors based on their location, which can stop search engines from seeing all your versions. Suggest the right version with a banner instead.
  • Translating pages with machine translation and no review. Hreflang helps the right page appear, but the page still has to be good.

How to check it's working

  1. Use a crawler or hreflang testing tool to check every page has return links and valid codes.
  2. In Google Search Console, compare performance by country to see whether the right version is getting traffic from the right market.
  3. Search from different countries, using a VPN or Google's location settings, to see which version appears.

Hreflang is one part of international SEO. Each market also needs content written for local searchers, local links and a fast site. Speed matters everywhere. Read Core Web Vitals Explained for a plain-English overview.

About the author

Huzaifa Younas

Huzaifa Younas is the founder and lead SEO strategist at RankWellToday. He has around five years of hands-on SEO experience across local service businesses, e-commerce stores, cybersecurity, medical billing and travel brands, working with clients in the US, Canada, India and beyond. He writes about practical, white-hat SEO and AI search.