This hreflang tags implementation guide is for companies that sell to more than one country or language and want the right version of each page to show in search. If your US pricing page keeps ranking in Australia, or your Spanish pages are being shown to English-speaking buyers, hreflang is usually the fix. It is also one of the easiest technical SEO tasks to get almost right, and an almost-right hreflang set is often ignored.
Below you will find when hreflang is worth the effort, how to plan your URLs and codes, three ways to implement it, platform notes for Next.js, WordPress and Shopify, the errors we see most often in audits, and a checklist you can run before and after launch. Every rule here comes from Google's own documentation, which we link throughout.
What hreflang tags do in SEO (and what they don't)
Hreflang is an annotation that tells Google that a set of URLs are localized versions of the same content. In Google's words, it helps Search "point users to the most appropriate version of your page by language or region" (Google Search Central).
It is easy to expect more from hreflang than it does. According to Google's documentation:
- It does not detect language. Google determines a page's language from its visible content with its own algorithms. It does not use hreflang, the HTML
langattribute or the URL for that (managing multi-regional and multilingual sites). - It is not a ranking boost. It helps Google swap in the right version of a page for a searcher. It does not make a weak page rank.
- It is a hint about relationships. If two pages do not both point to each other, the annotations are ignored, so another site cannot claim to be an alternate of yours.
- Translated pages are not duplicates. Google says localized versions are only considered duplicates if the main content stays untranslated. Same-language regional versions (en-US and en-GB) are very similar by nature, which is exactly why hreflang exists.
Do you need hreflang? A quick decision table
Many US and global B2B sites do not need hreflang at all. If you have one English site that serves buyers everywhere, adding regional copies just to "target" countries usually creates near-duplicates. Microsoft Bing makes the same point: localization creates duplicate content when regional or language pages are nearly identical, and it recommends making meaningful changes such as terminology, examples, regulations or product details, and avoiding multiple same-language pages that serve the same purpose (Bing Webmaster Blog, December 2025).
| Your situation | Hreflang? | Why |
|---|---|---|
| One English site, same offer and prices for every country | No | Nothing to swap. Focus on on-page and technical SEO instead. |
| English pages for the US, UK and Australia with different prices, currency, legal terms or contact details | Yes | Same language, real regional differences. Use en-US, en-GB, en-AU plus a generic en. |
| English site plus a fully translated Spanish version | Yes | Different languages. Use en and es (add regions only if content differs by country). |
| Translated navigation and footer, main content in one language | Yes, per Google | Google lists this as a scenario where indicating alternates is recommended. |
| Country pages that only swap the country name in the headline | Rethink first | Likely near-duplicates. Merge them or add genuinely local content before tagging. |
| Content changed by cookie, IP or browser language on one URL | Not possible | Hreflang needs a separate URL per version. Google recommends different URLs per language. |
That last row matters more than it looks. Google says Googlebot usually crawls from the USA and sends requests without an Accept-Language header, so content that changes by IP or browser settings may never be seen in other versions. Google also advises against automatically redirecting users to a language version based on a guess; let them switch with visible links instead (Google).
Step 1: Plan the URL structure and the cluster map
Each version needs its own URL. Google compares the main options like this:
| Structure | Example | Pros | Cons |
|---|---|---|---|
| Country-code domain | example.de |
Clear geotargeting, easy separation | Expensive, more infrastructure, targets one country only |
| Subdomain | de.example.com |
Easy to set up, separate server locations possible | Users may not know if "de" means language or country |
| Subdirectory | example.com/de/ |
Easy to set up, low maintenance, same host | Single server location, harder to separate |
| URL parameter | example.com?loc=de |
— | Not recommended by Google |
Source: Google, managing multi-regional and multilingual sites. For most B2B companies on a .com, subdirectories (/en-gb/, /es/) are the simplest to run. Note that the folder or subdomain name itself does not tell Google anything; Google says the en-gb in a URL is not used to determine the audience, so you still need hreflang.
Next, build a cluster map in a spreadsheet before anyone writes code. One row per page, one column per version:
| Page | en (x-default) | en-US | en-GB | en-AU | es |
|---|---|---|---|---|---|
| Pricing | /pricing/ | /en-us/pricing/ | /en-gb/pricing/ | /en-au/pricing/ | /es/precios/ |
| Contact | /contact/ | /en-us/contact/ | /en-gb/contact/ | /en-au/contact/ | /es/contacto/ |
| Blog post A | /blog/a/ | — | — | — | /es/blog/a/ |
Rules for the map:
- Every URL must be the final, canonical, 200-status, indexable URL, with the exact protocol, host and trailing slash your server serves.
- Not every page needs every version. A blog post that exists only in English and Spanish forms its own two-page cluster.
- Keep one owner for the map. Most hreflang errors start when someone publishes a new translation and the older versions are never updated to point to it.
Step 2: Choose valid language and region codes
The hreflang value is an ISO 639-1 language code, optionally followed by a dash and an ISO 3166-1 alpha-2 region code. Google only supports codes in those two standards; the value is case-insensitive, though uppercase regions (en-GB) follow the ISO convention (Google). You can look codes up in the Library of Congress ISO 639 list (two-letter column) and the ISO 3166 country codes platform.
| Value | Valid? | Notes |
|---|---|---|
en |
Yes | English, any region. A good catch-all for English speakers. |
en-US, en-GB, en-AU, en-CA |
Yes | English for the US, United Kingdom, Australia, Canada. |
es, es-MX, es-US |
Yes | Spanish; Spanish for Mexico; Spanish for users in the US. |
zh-Hans, zh-Hant |
Yes | Simplified and Traditional Chinese scripts (ISO 15924). |
en-UK |
No effect | UK is not the ISO 3166-1 code for the United Kingdom; use GB. Google says UK, EU and UN have no effect. |
en-EU |
No effect | EU is not a country code. |
es-419 |
Not supported | Google explicitly says codes outside the two standards, such as es-419 (Latin America), aren't supported. |
us, gb alone |
Invalid | A region alone is not allowed. Google also warns be is Belarusian, not Belgium. |
en_US |
Invalid | Use a dash, not an underscore. |
A practical pattern for US and global companies: tag the region-specific English pages (en-US, en-GB, en-AU) and also give one version the generic en value. Google recommends a catch-all URL for speakers of a language whose region you have not listed, and says it can be one of your specific pages.
Hreflang tags implementation guide: the three methods
Google supports three equivalent ways to declare alternates: HTML link elements, HTTP headers and XML sitemaps. Google says there is no Search benefit in using more than one, and that managing several at once is harder (Google). Pick one per page type.
| Method | Best for | Watch out for |
|---|---|---|
HTML <link> in <head> |
Most sites and CMS templates | Tags must be inside a well-formed <head>; adds markup to every page |
HTTP Link header |
PDFs and other non-HTML files | Needs server or CDN configuration |
| Hreflang sitemap | Large sites, many languages, headless setups | Every <url> entry must list all versions including itself |
These rules apply to all three methods:
- Self-reference. Each version lists itself as well as every other version.
- Return links. If page A lists page B, page B must list page A, or the pair is ignored.
- Absolute URLs. Use
https://example.com/en-gb/pricing/, not/en-gb/pricing/or//example.com/.... - Identical sets. The set of annotations is the same on every page in the cluster.
- Cross-domain is fine. Alternates can live on different domains, such as
example.comandexample.de.
Method 1: HTML link elements in the head
Add one link element per version, including the current page, to the <head> of every page in the cluster:
<head>
<link rel="alternate" hreflang="en-US" href="https://www.example.com/en-us/pricing/" />
<link rel="alternate" hreflang="en-GB" href="https://www.example.com/en-gb/pricing/" />
<link rel="alternate" hreflang="en-AU" href="https://www.example.com/en-au/pricing/" />
<link rel="alternate" hreflang="en" href="https://www.example.com/pricing/" />
<link rel="alternate" hreflang="es" href="https://www.example.com/es/precios/" />
<link rel="alternate" hreflang="x-default" href="https://www.example.com/pricing/" />
</head>
Google notes two details here: if in doubt, run the rendered HTML through a validator to confirm the links sit inside the <head>, and do not combine hreflang with other attributes such as media in a single tag.
Method 2: HTTP headers for PDFs and other files
For non-HTML files, return a Link header with every version, including the requested one. This is Google's example for one PDF in three versions:
Link: <https://example.com/file.pdf>; rel="alternate"; hreflang="en",
<https://de-ch.example.com/file.pdf>; rel="alternate"; hreflang="de-CH",
<https://de.example.com/file.pdf>; rel="alternate"; hreflang="de"
Method 3: The hreflang sitemap
An hreflang sitemap keeps annotations out of your templates, which suits large or headless sites. Google's rules: declare the xhtml namespace, give each URL its own <url> element, and inside each one add xhtml:link children for every version of the page, including itself. Those child elements do not count toward the sitemap URL limit.
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xhtml="http://www.w3.org/1999/xhtml">
<url>
<loc>https://www.example.com/en-us/pricing/</loc>
<xhtml:link rel="alternate" hreflang="en-US" href="https://www.example.com/en-us/pricing/" />
<xhtml:link rel="alternate" hreflang="en-GB" href="https://www.example.com/en-gb/pricing/" />
<xhtml:link rel="alternate" hreflang="x-default" href="https://www.example.com/pricing/" />
</url>
<url>
<loc>https://www.example.com/en-gb/pricing/</loc>
<xhtml:link rel="alternate" hreflang="en-US" href="https://www.example.com/en-us/pricing/" />
<xhtml:link rel="alternate" hreflang="en-GB" href="https://www.example.com/en-gb/pricing/" />
<xhtml:link rel="alternate" hreflang="x-default" href="https://www.example.com/pricing/" />
</url>
<!-- ...and a matching <url> entry for https://www.example.com/pricing/ -->
</urlset>
If you have three versions of a page, you need three <url> entries, each with the same three (or four, with x-default) child links. Submit the sitemap in Search Console and Bing Webmaster Tools as usual.
Hreflang x-default: the fallback page
The reserved x-default value tells Google where to send people whose language or region does not match any version you list. Google recommends it, says it was designed for language and country selector pages, and notes that it needs no language code because it targets "everyone else" (Google).
How to choose the x-default URL:
- You have a country or language selector page: point x-default there.
- You have no selector: point it at the version most visitors from unlisted regions should see, usually your main English page. It is fine for x-default and
ento share a URL. - Your homepage redirects by location: Google specifically suggests x-default for auto-redirecting home pages, but it also advises against automatic language redirects. Prefer a page that loads for everyone and offers clear links to other versions.
Canonical vs hreflang: how they work together
Canonical tags and hreflang answer different questions. A canonical says "this is the preferred URL among duplicates"; hreflang says "these URLs are versions of each other for different audiences." Use both, like this:
- Each localized page has a self-referencing canonical. Google recommends self-referential canonicals in general (Google canonical guide).
- Every hreflang URL is that canonical URL, never a parameter, HTTP, redirecting or non-www variant. Google specifically says not to put HTTP versions in sitemaps or hreflang annotations.
- Never canonicalize all regional versions to one "master" page. The others stop being indexed, and their hreflang entries point at URLs that are not in the index.
There is also a useful tie-break: for canonicalization, Google prefers URLs that are part of hreflang clusters. In Google's example, if /de-de/ and /de-ch/ pages point to each other but not to /de-at/, the first two are preferred as canonicals. If you have duplicate same-language content across regions, Google's advice is to pick a preferred version and use rel="canonical" and hreflang so the right regional URL is shown.
Platform notes: Next.js, WordPress and Shopify
Most hreflang problems come from templates and plugins, not from the rules. Here is what to check on the platforms our clients use most.
Hreflang in Next.js (App Router)
Next.js generates hreflang from the alternates.languages field in the Metadata API. With metadataBase set, relative paths become absolute URLs (Next.js generateMetadata docs):
// app/[locale]/pricing/page.tsx (locale = "en-us" | "en-gb" | "en-au")
import type { Metadata } from "next";
// One shared map: the same full set on every version, including the current page.
const languages = {
"en-US": "/en-us/pricing",
"en-GB": "/en-gb/pricing",
"en-AU": "/en-au/pricing",
en: "/en-us/pricing", // generic English catch-all (can reuse a regional page)
"x-default": "/en-us/pricing", // fallback for unmatched languages
};
export async function generateMetadata(
{ params }: { params: Promise<{ locale: string }> }
): Promise<Metadata> {
const { locale } = await params;
return {
metadataBase: new URL("https://www.example.com"),
alternates: {
canonical: `/${locale}/pricing`, // self-referencing canonical
languages,
},
};
}
Three things to check in Next.js projects:
- Include the current page in
languages. The localized sitemap example in the Next.js sitemap docs lists only the other languages (es,de) for each URL. Google requires every entry to list itself as well, so add the page's own locale (andx-default) to the object. - The TypeScript type accepts codes Google ignores. Next.js types allow
x-defaultand many locale strings, including values such asen-029that are outside ISO 3166-1 alpha-2. A code that compiles is not automatically a code Google supports. - Set
metadataBase. Next.js raises a build error if a URL-based metadata field uses a relative path without it, and absolute URLs are what Google requires. - Match your trailing-slash setting. If hreflang URLs end in
/but your site serves them without one (or the reverse), every entry points at a redirect. Copy the exact URL your server returns with a 200.
For large sites, generating hreflang in app/sitemap.ts with alternates.languages is often cleaner than per-page metadata. Pick one, not both.
Hreflang tags in WordPress
WordPress core does not output hreflang. Multilingual plugins do: WPML states that it automatically inserts hreflang tags and updates them as you make changes (WPML documentation). Before launch, check:
- Only one plugin or theme outputs hreflang. Two sources produce conflicting sets.
- Each translation's canonical points to itself, not to the default-language page.
- Draft, private or noindexed translations do not appear in the hreflang set.
- If your SEO plugin moves hreflang into the XML sitemap, the in-page tags are not duplicated with different values.
Shopify hreflang tags
On Shopify, Markets adds hreflang tags to your theme automatically through content_for_header, keeps them in sync with each page's canonical, and updates them when you change market domains or languages (Shopify developer docs). Shopify warns that adding your own tags on top of the automatic ones can create duplicate or conflicting annotations. If a theme or app already outputs hreflang, turn off Automatic hreflang tags under Online store > Preferences so only one source remains. Our Shopify SEO checklist covers the other store-level settings.
Hreflang tags example: a US B2B company expanding abroad
Here is how the pieces fit for a typical case: a US software company with a .com site that adds UK and Australian pricing pages and a Spanish version of its main service pages.
- Decide what really differs. UK and Australian pages show local currency, tax wording and contact details. The Spanish pages are full translations, not machine-translated templates.
- Pick the structure. Subdirectories:
/(US and global English),/en-gb/,/en-au/,/es/. - Assign codes. The root English pages take both
en-USand the genericen; UK pagesen-GB; Australian pagesen-AU; Spanish pageses. x-default points to the root English page. - Choose one method. HTML tags generated by the site template, with the same set on every version.
- Map clusters per page. Pricing has four versions; blog posts that exist only in English get no hreflang at all.
- Ship and verify. Crawl the site, test a sample of pages in a hreflang checker, inspect the key URLs in Search Console, and submit the updated sitemap.
Notice that one URL can carry more than one hreflang value (here, en-US and en), but each value should map to only one URL within a cluster.
Common hreflang errors and how to fix them
| Error | What happens | Fix |
|---|---|---|
| Missing return link | The pair is ignored | Generate tags from one shared map so every version lists every other |
| Missing self-reference | Breaks Google's rule that each version lists itself | Include the current page in its own set |
Invalid code (en-UK, en-EU, es-419, en_US) |
That annotation has no effect | Use ISO 639-1 + ISO 3166-1 alpha-2 with a dash |
Region-only code (gb, us) |
Invalid, read as a language or ignored | Always start with the language code |
| Relative or protocol-relative URLs | Not fully qualified | Use absolute https:// URLs |
| Hreflang to redirecting, 404 or noindex URLs | Entry points to a URL that is not indexed | Point to final 200, indexable URLs |
| Canonical points to another version | That version is not indexed | Self-referencing canonical on each version |
| Two sources (plugin + theme, or HTML + sitemap with different values) | Conflicting sets | Keep one source of truth |
| Same URL for two different regions in one set | Ambiguous mapping | One URL per value; give each region its own page or merge |
| Language of content doesn't match the tag | Google trusts the visible content | Translate the main content, not just the template |
| Auto-redirect by IP or browser language | Crawlers and users can't reach other versions | Let users choose; show links to other versions |
The return-link and code errors come straight from Google's troubleshooting section, and the URL rules from its guidelines for all methods (Google). They also tend to appear after redesigns and migrations, which is why we include hreflang in every website redesign checklist review.
How to test hreflang: checkers, crawlers and Search Console
Search Console no longer has an International Targeting report. Google deprecated it, but says it will continue to support and use hreflang tags (Search Console Help). So testing needs three layers:
- Single-page hreflang checker. Google's documentation names third-party tools including Aleyda Solis's hreflang tags generator and the Merkle hreflang tag testing tool for validating a live page. Google notes it does not maintain these tools.
- Full-site crawl. Use an SEO crawler that validates return links, codes, status codes and canonicals across every page, not just a sample. Export the issues and match them to your cluster map.
- Search Console URL Inspection. For your most important localized URLs, confirm they are indexed and that the Google-selected canonical is the URL itself, not another regional version.
Two more checks are worth a few minutes. Search from the target region (or with a VPN) for a branded query and confirm the right version appears. And because AI search tools draw on search indexes, clean clusters matter there too: Bing notes that AI systems tend to group near-duplicate URLs and pick one to represent the set, which may not be the one you want. Our guide to generative engine optimization covers the rest of that picture.
Hreflang audit checklist
Run this before launching a new language or region, and again after any template change:
- Each version has real, meaningful differences (language, currency, legal terms, contact details).
- Each version has its own URL; no cookie, IP or Accept-Language switching on one URL.
- A cluster map exists with one owner, listing every page and its versions.
- All codes are ISO 639-1 language + optional ISO 3166-1 alpha-2 region, with a dash.
- No
en-UK,en-EU,es-419, region-only values or underscores. - A generic language version (such as
en) exists where you have several regional versions. -
x-defaultpoints to a selector page or your main fallback version. - One implementation method per page type (HTML, header or sitemap), from one source.
- Every page lists itself and every other version; sets are identical across the cluster.
- All hreflang URLs are absolute, HTTPS, canonical, 200-status and indexable.
- Each localized page has a self-referencing canonical.
- Hreflang sitemap declares the
xhtmlnamespace and lists all versions under every<url>. - No automatic redirects by location or browser language; visible language/region links exist.
- Spot-checked with a hreflang tester, full-site crawl clean, key URLs inspected in Search Console.
- Updated sitemap submitted to Google Search Console and Bing Webmaster Tools.
How Sirajia Sol helps with international SEO
Hreflang is a small piece of code with a large blast radius: one template change can quietly break every cluster on a site. Our SEO team audits international setups against Google's documentation, builds the cluster map with you and turns the findings into a prioritized fix list. Where the fix lives in your codebase, our web development team can implement hreflang in Next.js, WordPress or Shopify and add checks so it stays correct after future releases.
If you are planning a new region or language, or your localized pages are showing in the wrong countries, contact us to talk through an international SEO and hreflang review.
