Hreflang Tags: Syntax, Placement and the 5 Errors to Fix

by | Dec 5, 2026 | SEO | 0 comments

hreflang tags tell search engines which language or regional version of a page to show to which user. You add them in one of three places: <link> elements in the HTML head, HTTP headers, or your XML (Extensible Markup Language) sitemap, the file that lists your URLs for search engines.

Every page in a set must list itself and every alternate, with valid language-region codes such as en-GB, and every alternate must link back. Get one of those rules wrong and Google may ignore the whole set.

Hreflang is one of those technical SEO (search engine optimization) jobs that looks like a single line of code and turns into a project. The syntax is short.

The hard part is keeping dozens or thousands of URLs pointing at each other correctly as pages get added, moved and retired. This guide covers when you actually need hreflang, how to write the codes and where to place the tags. It then shows the setup on WordPress and Shopify, and the five hreflang mistakes that break most implementations, each with its fix. The piece All About Hreflang Tags & International SEO makes a good next read.

What hreflang tags do, and what they don’t

The hreflang attribute (pronounced “h-ref-lang”, from href plus lang) marks pages as equivalents of each other for different audiences. Google introduced it in 2011. Think of it as a routing instruction rather than a ranking signal.

Here’s the mechanism. A crawler visits your US (United States) English page and finds a list of alternates: a UK English version, a German version and a French version. It visits each one and checks that they list the same group of pages.

If the links confirm each other, the search engine treats the URLs as one cluster. When someone in Germany searches, it can swap in the German URL in the search results instead of the English one.

This is what helps search engines understand near-identical pages. Without it, a UK page and a US page with the same text look like duplicate content, and Google may show only one of them everywhere. Hreflang doesn’t remove duplicate content issues by itself, but it tells Google the pages are deliberate alternates for different audiences, which also improves the user experience.

That’s useful in two situations. The first is translated content, where a French speaker should land on the French page. The second is regional content in the same language, where a UK shopper should see prices in pounds and UK delivery terms rather than the US page. The second case is where hreflang earns its keep, because the pages are near-identical and a search engine can’t easily tell them apart on its own.

Hreflang doesn’t do several things people expect from it:

  • It doesn’t translate anything. You need real, localized pages first.
  • It doesn’t boost rankings. It helps the right version appear where a version already ranks.
  • It doesn’t tell Google what language a page is in. Google’s documentation on multi-regional sites says it detects the language from the visible content, not from code-level signals such as the lang attribute.
  • It isn’t a command. Google treats hreflang as a hint, so a broken or contradictory set is simply ignored.

Hreflang vs the lang attribute vs canonical tags

Three pieces of markup get confused all the time.

The lang attribute on the <html> element declares the language of the current page for browsers and screen readers. The canonical tag (rel="canonical") names the preferred URL among duplicates. Hreflang annotations name equivalent pages for other audiences. A well-built multilingual page usually carries all three, and they must agree with each other, which we cover further down.

multilingual website code

Do you need hreflang tags? A decision table

Plenty of sites add hreflang because an audit tool or a new manager says they should. A company that sells in three US states, in English only, has no use for it. Hreflang requires a set of alternate pages to point to, and a single-language, single-country site doesn’t have one. The table below sorts the common cases.

Your situation What to do Avoid
One language, one country Skip hreflang. Set the lang attribute correctly. Adding tags that point only to themselves “just in case”
Same language, several countries (en-US, en-GB, en-AU) Use language-region codes on every equivalent page. This is the strongest case for hreflang. Language-only codes (en) on all three, which tells Google nothing about the country
Several languages, no regional variants (/en/, /fr/, /de/) Use language-only codes plus an x-default. Inventing a region you don’t actually target
Separate country domains (.de, .ch, .fr) Hreflang works across domains. Link the equivalent pages of each domain. Linking every page to every domain’s homepage
Two blogs in the same language with a few shared posts Leave them alone, or use a canonical tag if posts are true duplicates. Hreflang between pages that aren’t equivalents for different audiences
Large site, 1,000+ URLs per language Generate tags from templates or the sitemap. Hand-editing the head of each page

One practical shortcut for multi-country groups: you don’t have to annotate everything on day one. If German visitors land on your Swiss pages, start with the German-language cluster (de-DE, de-CH, de-AT) where the pages compete with each other. Add the other languages when you have the capacity to maintain them.

Hreflang syntax: language and region codes

A hreflang annotation in HTML is a <link> element with three parts:

<link rel="alternate" hreflang="en-gb" href="https://example.com/uk/pricing/" />
  • rel="alternate" says the URL is an alternate version of the current page.
  • hreflang="en-gb" names the audience: language first, then an optional region.
  • href gives the full URL of that version.

The value follows strict standards.

Google’s documentation on localized versions requires a language code in ISO (International Organization for Standardization) 639-1 format, the two-letter language list. A region code in ISO 3166-1 Alpha 2 format is optional. You can also add a script variation in ISO 15924 format when the same language uses two alphabets, for example zh-Hant for traditional Chinese. Codes aren’t case-sensitive, but en-GB is easier to read. A step-by-step version exists if you prefer that format.

Code Valid? Why
en Yes English, any region
en-GB Yes English for the United Kingdom
en-UK No “UK” isn’t the ISO 3166-1 code for the United Kingdom; use GB (Great Britain)
fr-CA Yes French for Canada
be Yes, but probably not what you meant It means the Belarusian language, not Belgium
-US or us alone No A region can’t stand without a language
pt-BR and pt-PT Yes Portuguese for Brazil and for Portugal, a classic regional dialect pair
x-default Yes Reserved value for the fallback page

Here are three hreflang tag examples for the most common setups. A simple English, Spanish and French site, placed in the head of each of the three pages:

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

A regional English setup, where pricing and currency differ by country:

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

And a mixed set, which is allowed: a broad de page for all German speakers alongside a specific de-CH page for Switzerland. Google then sends Swiss German speakers to the Swiss page and other German speakers to the general one.

three ways to implement hreflang html head http

Three ways to implement hreflang: HTML head, HTTP headers, XML sitemap

Google reads hreflang from three places, and each fits a different kind of site. Pick one primary method. Mixing them is technically possible, but it gives you two sets of annotations to keep identical, and a mismatch between them is a common source of conflicts.

Method Best for Effort Avoid when
HTML <head> Small and mid-size sites, most CMS (content management system) setups Low with a plugin, moderate by hand You have dozens of languages: every page carries one line per version
HTTP headers PDFs and other non-HTML files Needs server access Your team can’t edit server or CDN (content delivery network) rules
XML sitemap Large sites, many languages, page weight concerns Best when generated automatically Your sitemap is hand-maintained or rarely regenerated

1. Link elements in the HTML head

Place the full set of <link> elements inside the <head> of every page in the cluster, as in the examples above. They must be in the head: tags printed in the body are ignored. If your site renders content with JavaScript, make sure the tags appear in the HTML the server sends, or in the rendered head if you use server-side rendering. Tags injected late by a script can be missed during crawling.

2. HTTP headers for PDFs and other files

A PDF has no head section, so the annotation travels in the HTTP response header (the metadata the server sends before the file itself). The format puts each URL in angle brackets, separated by commas:

Link: <https://example.com/guide.pdf>; rel="alternate"; hreflang="en",
      <https://example.com/de/guide.pdf>; rel="alternate"; hreflang="de"

On Apache you can set this with a Header add Link rule in the server configuration or .htaccess. On Nginx, the equivalent is an add_header Link directive in the location block. Check the result with curl -I https://example.com/guide.pdf.

3. The XML sitemap

The sitemap method keeps your pages light and puts all annotations in one file. Each <url> entry lists every alternate, including itself, using xhtml:link elements. Declare the xhtml namespace at the top, or the entries won’t parse:

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
        xmlns:xhtml="http://www.w3.org/1999/xhtml">
  <url>
    <loc>https://example.com/en/services/</loc>
    <xhtml:link rel="alternate" hreflang="en" href="https://example.com/en/services/" />
    <xhtml:link rel="alternate" hreflang="fr" href="https://example.com/fr/services/" />
    <xhtml:link rel="alternate" hreflang="x-default" href="https://example.com/en/services/" />
  </url>
  <url>
    <loc>https://example.com/fr/services/</loc>
    <xhtml:link rel="alternate" hreflang="en" href="https://example.com/en/services/" />
    <xhtml:link rel="alternate" hreflang="fr" href="https://example.com/fr/services/" />
    <xhtml:link rel="alternate" hreflang="x-default" href="https://example.com/en/services/" />
  </url>
</urlset>

The file grows fast, so plan for it. Example: 500 pages in 6 languages means 3,000 <url> entries, each with 7 alternate lines including x-default. Google’s sitemap documentation caps a single sitemap at 50,000 URLs or 50 megabytes (MB) uncompressed, so split large sets with a sitemap index file.

The cluster rules: self-referencing, return tags and x-default

Most hreflang failures come from three rules about how pages refer to each other. They apply whichever method you use.

Every page lists itself. Google’s documentation says each language version must list itself as well as all other versions. The English page’s set includes an hreflang="en" line pointing to its own URL. A self-referencing tag looks redundant, yet leaving it out is a classic audit warning.

Every link needs a return link. If page A names page B as its French alternate, page B must name page A back. Google states that annotations without a return link may be ignored, because a one-way claim could come from anyone. This is why one forgotten page can break a whole cluster.

URLs are absolute. Google requires fully qualified URLs, including the https:// part. A relative path such as /fr/services/ isn’t valid in hreflang, even though it works in normal links.

x-default names the fallback. The reserved value x-default tells search engines which page to show when no version matches the user’s language or region. Point it to a language selector page, or to the version you’d want a visitor from an unlisted country to see, often your main English page. It isn’t mandatory, but it closes a gap that most sites leave open.

One more rule follows from the others: only annotate true equivalents. A UK pricing page should point to the US pricing page, not to the US homepage. If a page has no translation, leave it out of the set rather than pointing to a loosely related page.

a screen displaying code is presented in a close-up shot

How to add hreflang tags on WordPress and Shopify

These two platforms power a large share of small business and agency sites, so here are the exact routes. Custom stacks follow the same logic: generate the tags from your page templates, never by hand. For the wider picture, see What is Hreflang Tag.

WordPress with a multilingual plugin

Don’t count on a general SEO plugin to output hreflang for you. In practice, the tags come from multilingual plugins like WPML (WordPress Multilingual) or Polylang, which add them automatically once translations are linked. With Polylang, the route is:

  1. Go to Languages > Languages and add each language with its locale (for example English, en_GB).
  2. In Languages > Settings > URL modifications, choose how the language appears in the URL, such as a directory (/en/).
  3. Open each post or page and use the Languages box to link it to its translations.
  4. View the page source of a translated page and search for “hreflang” to confirm the set is complete.

Step 3 is the one people skip. An unlinked translation is just another page to the plugin, so it gets no hreflang at all.

WordPress site already in two languages, no plugin

Say you inherited a site where the languages are already built, with Dutch at the root and English under /en/. Installing a multilingual plugin on top can clash with that existing setup. A small snippet in a child theme’s functions.php, or in a code snippets plugin, can print the tags instead. This version assumes every page exists in both languages with the same slug:

add_action( 'wp_head', function () {
    if ( is_404() || is_search() ) { return; }
    $base = 'https://www.example.com';
    $path = strtok( $_SERVER['REQUEST_URI'], '?' );
    $nl   = preg_replace( '#^/en(/|$)#', '/', $path );
    $en   = '/en' . $nl;
    printf( '<link rel="alternate" hreflang="nl" href="%s" />' . "\n", esc_url( $base . $nl ) );
    printf( '<link rel="alternate" hreflang="en" href="%s" />' . "\n", esc_url( $base . $en ) );
    printf( '<link rel="alternate" hreflang="x-default" href="%s" />' . "\n", esc_url( $base . $nl ) );
} );

Before you rely on it, crawl the site and check that every generated English URL returns a 200 status. Any page that exists in only one language needs an exception, or the snippet will point to a 404.

Shopify

Shopify adds hreflang tags automatically for the languages you publish, and for the domains or subfolders you assign to each market. Add and publish languages under Settings > Languages, then set up your country markets and their domains under Settings > Markets. Your job is mostly to check the output. View the source of a product page in each market and confirm the codes match the country, not just the language.

Hreflang and canonical tags: keep the signals aligned

Hreflang and canonical tags answer different questions, and they clash more often than any other pair of signals. The rule is simple. Each language version’s canonical tag points to itself, and hreflang links those self-canonical URLs together.

The common mistake is to canonicalize every translation to the English original. That tells Google the French page is a duplicate of the English one and shouldn’t be indexed, while hreflang says it’s an alternate worth showing. Google’s guidance on canonicalization says to specify a canonical in the same language, or the best possible substitute language if a same-language canonical doesn’t exist. In practice, the conflicting French page simply drops out of the index.

The same logic extends to every indexing signal you send. Hreflang should only point to URLs that are:

  • indexable, with no noindex tag;
  • live, with a 200 status rather than a redirect or a 404;
  • allowed in robots.txt;
  • listed in your sitemap and linked internally.

If those signals disagree, Google picks one, and it may not be the one you wanted. So yes, a broken hreflang setup can cause indexing problems, mostly by pulling localized pages into a duplicate cluster.

The five most common hreflang errors, and the exact fix for each

Mistakes are the norm, not the exception. A 2023 Ahrefs study, reported by Greenlane, found that 67% of domains using hreflang had at least one issue. The most frequent was a missing x-default (56.3% of domains), which is a gap rather than a breakage. The five below actually stop annotations from working.

1. Missing return tags

Symptom: your crawler reports “missing return links”, and the wrong country version keeps appearing in results. Cause: page A lists page B, but page B doesn’t link back to page A. It often happens after a new language reaches only part of the site, or when separate teams run separate country sites.

Fix: make the links reciprocal by generating the full set from one source of truth, such as a URL mapping sheet or the CMS translation links. Then output the identical set on every page of the cluster. Ahrefs found this on 15.3% of domains.

2. Invalid language or country codes

Symptom: audit warnings about an “incorrect language and region code”. Cause: codes like en-UK, or a country on its own.

Some wrong codes even pass validation: es-LA, meant for Latin America, actually targets Spanish speakers in Laos. Fix: check each code against ISO 639-1 for the language and ISO 3166-1 Alpha 2 for the region. Replace en-UK with en-GB. If you don’t target a specific country, drop the region rather than guessing one.

3. No self-reference

Symptom: the page lists every other version but not itself. Cause: a template that loops over “other languages” only. Fix: change the loop so it outputs the current page too. Ahrefs measured this on 18% of domains.

4. Hreflang pointing to redirected, broken or noindexed URLs

Symptom: alternates returning 301, 404 or 5xx status codes. Cause: URLs changed during a migration or slug edit, but nobody updated the hreflang mapping.

Fix: point every annotation to the final URL that returns 200. Re-crawl after each migration. Ahrefs counted broken or redirected targets on 16.9% of domains.

5. Conflicts between hreflang and canonical

Symptom: localized pages show as “Duplicate, Google chose different canonical than user” in Search Console’s page indexing report. Cause: hreflang points to a URL whose canonical points elsewhere, or all versions canonicalize to one language. Fix: make every version self-canonical and use only canonical URLs in hreflang. Ahrefs found non-canonical targets on 8% of domains.

How to check hreflang tags after Search Console’s report was retired

Many older guides still tell you to open the International Targeting report in Google Search Console. Google retired that report in 2022, and Search Console no longer lists hreflang errors directly. You now check hreflang in three layers.

On a single page. Open the page, view the source and search for “hreflang”. Browser developer tools show the rendered head, which matters for JavaScript sites. For PDFs, run curl -I on the file and read the Link header.

Across the whole site. A crawler does the heavy lifting. In Screaming Frog SEO Spider, enable hreflang crawling in the spider configuration, run the crawl, then open the Hreflang tab.

Its filters flag missing return links, incorrect codes, missing self-references and non-canonical targets. Semrush and Ahrefs site audits report similar checks. For a quick test of a few URLs, an online hreflang tester works fine.

In Google’s own data. Use the URL Inspection tool on a localized page to see which canonical Google selected. If it picked another language’s URL, you have a conflict. Then open the Performance report, filter by country, and check that the pages getting impressions there are the right local versions.

To measure whether hreflang works, compare before and after:

  • the share of impressions in each country that go to the matching local URL (Search Console Performance, filtered by country and page);
  • sessions by country and language on each localized landing page (Google Analytics 4, in the user attributes reports);
  • the bounce rate and conversion rate of visitors from each country, since fewer people should land on a version that isn’t theirs.

Re-crawl after every release that adds pages or languages, and run a full hreflang audit at least monthly on large sites. Hreflang rarely breaks loudly: it decays as pages change.

Hreflang implementation checklist

  1. Confirm you have equivalent pages for different languages or regions. If not, stop here.
  2. Build a mapping sheet: one row per page, one column per language-region version.
  3. Pick codes: ISO 639-1 language, optional ISO 3166-1 Alpha 2 region (en-GB, not en-UK).
  4. Choose one method: HTML head, HTTP headers for files, or XML sitemap.
  5. Output the full set on every page, including a self-reference.
  6. Use absolute URLs that return 200 and are indexable.
  7. Add an x-default tag pointing to a selector or your main fallback page.
  8. Make each version self-canonical.
  9. Crawl the site and clear return-link, code and canonical errors.
  10. Check URL Inspection and country filters in Search Console a few weeks later.
  11. Re-crawl after each release, migration or new language.

Where to start

If you’re launching a new language or country version, build the URL mapping sheet before writing a single tag. It’s the source of truth that makes return links, self-references and x-default automatic instead of manual. If your site already has hreflang, run one crawl this week to validate it.

Fix the return links and canonical conflicts first, because those are the errors that make Google discard the whole cluster. For a digital marketing team, that single mapping sheet also becomes the brief for translators, developers and whoever reports on international traffic.

Want more practical guides on technical SEO and content for international audiences? Browse the rest of our blog for the next step in your multilingual strategy.

Frequently asked questions about hreflang tags

Is it a hreflang tag or a hreflang attribute?

Strictly, hreflang is an attribute of the <link> element, so “hreflang attribute” is the precise term. Most people say “hreflang tag” for the whole <link rel="alternate" hreflang="..."> line. Both mean the same thing in practice.

Can I add hreflang after my multilingual site has launched?

Yes. Search engines pick up the annotations as they recrawl your pages, so there’s no penalty for adding them late. On a large site, pages deep in the structure get recrawled less often, so expect the full set to take effect gradually.

Does every page need hreflang tags?

No. Only pages that have equivalents in another language or region need them. A blog post that exists only in English needs no hreflang, and forcing one by pointing to an unrelated page does more harm than good.

Do hreflang tags slow down my site?

A handful of link elements adds almost nothing. With dozens of languages, though, every page carries dozens of extra lines in its head. At that point, moving the annotations to the XML sitemap keeps pages lighter.

Do other search engines use hreflang?

Support varies by engine, and Google’s documentation only describes Google’s behavior. Keep the HTML lang attribute accurate on every page, because some engines and browsers rely on it, and check each engine’s webmaster documentation if a market depends on it.

Search Keywords

Recent Posts

How to Set Up Google Search Console: Your First 30 Days

In short: to set up Google Search Console, sign in with a Google account at search.google.com/search-console and add your site as a Domain property. Prove you own it with a DNS record (Domain Name System, the directory that points your domain to your server). Then...

Subscribe

Subscription Form

Follow Us