In short: hreflang tags tell Google which language or regional version of a page to show each searcher. You add them in one of three places: <link> elements in the page <head>, an HTTP Link header, or your sitemap. That sitemap is the XML (Extensible Markup Language) file listing your URLs for search engines. Every version must list itself and all its alternates, with absolute URLs, valid codes from the International Organization for Standardization (ISO) and an x-default fallback.
Most broken setups fail on the same three points: missing return links, wrong codes, and canonical tags that contradict the cluster.
For any multilingual website, that’s the core of international SEO. This guide shows all three methods with copy-ready code for an English page, a French page and an x-default fallback. It also covers WordPress and a Node.js Express app, then walks through the mistakes that make Google quietly ignore your markup. An in-depth look at it is worth the time.
What hreflang tags actually do (and what they don’t)
The hreflang attribute is a piece of HTML code that declares the language, and optionally the country, a page is written for. It sits on a <link rel="alternate"> element, so it connects one web page to each alternate version in a different language or for a different country. Search engines read it; visitors never see it. That answers the common question “what is hreflang in HTML?”: it’s a machine-readable map of your page’s language versions and their geographical targeting.
The mechanism is easier to grasp in three steps.
First, Google decides that one of your URLs deserves a spot in the results, using its usual ranking signals. Next, it checks whether that URL belongs to a hreflang cluster, meaning a group of pages that all point to each other.
Finally, just before showing the result, it swaps in the version that best matches the searcher’s language settings and location. Hreflang works on that last step, the swap, and nothing else: the hreflang annotation is how you tell Google which version belongs to which language preference.
Three consequences follow, and they clear up most of the confusion around the topic:
- It’s a hint, not a directive. Google can ignore a cluster, especially when the tags contradict each other or the pages are near-identical.
- It isn’t a ranking factor. Your French page won’t rank higher because it has hreflang. It will simply be the page French users see, instead of the English one.
- It doesn’t detect language. Google’s documentation states that it uses its own algorithms to work out a page’s language, not hreflang or the HTML
langattribute. A badly translated page stays a badly translated page.
Hreflang also helps with a classic duplicate content issue between regional versions. Two English pages for the United States (US) and the United Kingdom (UK), differing only by spelling and currency, look like copies. The annotation tells Google they’re deliberate alternates for different audiences, so it can show each one in the right country rather than picking one and filtering the other.
Search engine support varies. Google and Yandex read hreflang. Bing has historically leaned on other signals, such as the content-language meta tag and country-code domains. A site that cares about Bing traffic should therefore set its language declarations correctly too.

Do you need hreflang tags? A quick decision table
Hreflang only makes sense when you have equivalent content in multiple languages or for more than one region. Creating that content is the real work; the markup comes after. The table below matches common situations to a recommendation.
| Your situation | Do this | Avoid |
|---|---|---|
| One language, one market | No hreflang. Set <html lang="en"> and move on. |
Adding a lone self-referencing tag “just in case” |
| Full translations (English + French) | Language-only codes: en, fr, plus x-default |
Adding country codes you don’t actually target |
| Same language, several countries (US, UK, Australia) | Language-region codes: en-US, en-GB, en-AU, plus a generic en |
Identical pages with no local difference (prices, spelling, shipping) |
| Same country, several languages (Canada, Belgium, Switzerland) | en-CA and fr-CA, or nl-BE and fr-BE |
One URL that switches language with a cookie |
| Only the menus are translated | Translate the main content first | Pointing hreflang at pages that aren’t really equivalent |
| PDFs or other files in several languages | HTTP Link header |
Leaving downloads out of the cluster |
Machine translation deserves a word of caution. The markup itself works on any page, but sending French searchers to a raw automatic translation hurts the user experience hreflang is supposed to improve. In our view, a short human review of each translated page matters more than the tags.
Anatomy of a tag: language codes, region codes and x-default
Every hreflang tag has three parts, and the syntax never changes. Here’s the English version of a page declaring itself:
<link rel="alternate" hreflang="en" href="https://example.com/en/pricing/" />
rel="alternate"says the linked URL is another version of the same content.hreflang="en"gives the audience: a language code, optionally followed by a region code.hrefgives the full, absolute URL of that version, includinghttps://.
Language and region codes
The language part uses two-letter codes in ISO 639-1 format: en, fr, de, ja. The optional region part uses ISO 3166-1 Alpha 2 country codes, separated by a hyphen: fr-CA means French for Canada. Google’s documentation names both standards explicitly. Together they form a tag in the BCP 47 format (Best Current Practice 47), the standard for language tags published by the Internet Engineering Task Force (IETF).
BCP 47 tags are case-insensitive, so en-gb and en-GB are equivalent. Lowercase language and uppercase region is simply the usual convention.
These codes are the whole of your regional targeting, so a typo sends the wrong signal. Four rules catch most code errors:
- A region never stands alone.
hreflang="US"is invalid; useen-US. - Country and language codes differ. The United Kingdom is
GB, soen-UKis wrong. Greek isel, while Greece isGR. - Use a hyphen, not an underscore.
en_UScomes from software locales and isn’t valid here. - No made-up values. Google ignores
hreflang="french"orhreflang="eng".
BCP 47 also allows script subtags, such as zh-Hant for Chinese written in Traditional characters. You’ll only need them for languages written in more than one script.
The x-default value
x-default is a reserved value for searchers whose preferred language matches none of your listed versions. Google introduced it in 2013 for international landing pages. It usually points to a language selector page, or to the default page you’d rather show, often the English version. For our English and French example, a Spanish speaker in Mexico would get the x-default URL, since there’s no Spanish version to swap in.
One subtle rule applies to the x-default tag: every page in the cluster must name the same URL. If your French page points x-default to /en/ while your English page points it to /, the cluster contradicts itself.

Three ways to add hreflang, with copy-ready code
Google treats the three methods as equivalent, so the best practice is to pick one per type of content and stick to it. Mixing them doesn’t help; it only multiplies the places where the data can drift apart.
| Method | Best for | Effort and skills | Avoid when |
|---|---|---|---|
HTML <head> |
Small and medium sites, or a content management system (CMS) with a plugin | Low; template access | Dozens of languages: the <head> gets heavy |
| HTTP header | PDFs and other non-HTML files | Medium; server or app access | Normal pages you can edit in HTML |
| XML sitemap | Large sites, many language versions | Medium to high up front, then easy to maintain | Your sitemap isn’t generated automatically |
Method 1: link elements in the HTML head
Put the same block in the <head> of both pages. The English page and the French page carry identical lines; only the page you’re on changes.
<link rel="alternate" hreflang="en" href="https://example.com/en/pricing/" />
<link rel="alternate" hreflang="fr" href="https://example.com/fr/tarifs/" />
<link rel="alternate" hreflang="x-default" href="https://example.com/en/pricing/" />
This one block already handles the self-referencing tag and the return link. On the English page, the en line points to itself and the fr line points to its alternate; on the French page, it’s the other way round. Set the matching <html lang="en"> or <html lang="fr"> too, since some audit tools flag a mismatch between the two. This self-referential line is what most guides mean when they say each page must “link back” to itself.
Method 2: the HTTP Link header
A PDF has no <head>, so the server sends the annotation in the response headers instead. Each file returns the full list:
Link: <https://example.com/en/guide.pdf>; rel="alternate"; hreflang="en",
<https://example.com/fr/guide.pdf>; rel="alternate"; hreflang="fr",
<https://example.com/en/guide.pdf>; rel="alternate"; hreflang="x-default"
You can check the result with curl -I https://example.com/fr/guide.pdf, which prints the headers without downloading the file.
Method 3: the XML sitemap
In a sitemap, each URL gets its own <url> entry, and each entry lists every version, itself included, with <xhtml:link> elements. Don’t forget the xmlns:xhtml namespace declaration on the root element.
<?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://example.com/en/pricing/</loc>
<xhtml:link rel="alternate" hreflang="en" href="https://example.com/en/pricing/" />
<xhtml:link rel="alternate" hreflang="fr" href="https://example.com/fr/tarifs/" />
<xhtml:link rel="alternate" hreflang="x-default" href="https://example.com/en/pricing/" />
</url>
<url>
<loc>https://example.com/fr/tarifs/</loc>
<xhtml:link rel="alternate" hreflang="en" href="https://example.com/en/pricing/" />
<xhtml:link rel="alternate" hreflang="fr" href="https://example.com/fr/tarifs/" />
<xhtml:link rel="alternate" hreflang="x-default" href="https://example.com/en/pricing/" />
</url>
</urlset>
A single sitemap file is limited to 50,000 URLs and 50 megabytes (MB) uncompressed, according to Google’s sitemap documentation. Beyond that, split it and list the parts in a sitemap index. Then submit the sitemap in Google Search Console under Indexing > Sitemaps.
Implementing hreflang on WordPress and on an Express app
Most multilingual sites run either on a CMS such as WordPress or on a custom Node.js server. Here’s how to handle both without writing every tag by hand.
WordPress
On WordPress, let the translation plugin generate the tags. WPML (WordPress Multilingual), Polylang and Weglot all output hreflang links for the translations they manage, so the cluster stays reciprocal when you add or remove a language. The steps look like this:
- Install one translation plugin, not two, and set your target audience languages and URL format (folders such as
/fr/are the simplest to maintain). - Link each post to its translation inside the plugin, so it knows which pages belong together.
- Set the default language, then check which URL the plugin outputs as
x-default. - Open a published page, view its source and search for
hreflangto confirm the full set appears on both versions.
If you run a site without a translation plugin, for instance two separate WordPress installs, you can print the tags from your child theme’s functions.php:
add_action( 'wp_head', function () {
$alternates = array(
'en' => 'https://example.com/en/pricing/',
'fr' => 'https://example.com/fr/tarifs/',
'x-default' => 'https://example.com/en/pricing/',
);
foreach ( $alternates as $lang => $url ) {
printf( '<link rel="alternate" hreflang="%s" href="%s" />' . "\n",
esc_attr( $lang ), esc_url( $url ) );
}
} );
In practice you’d read the URL pairs from a custom field rather than hard-code them. Above all, never run a plugin and a manual snippet together: the duplicate, conflicting tags are worse than none.
Express (Node.js)
In an Express app, build the list of alternates once per route and pass it both to the template and, for files, to the response headers. A small helper keeps the cluster consistent:
const BASE = 'https://example.com';
const routes = {
pricing: { en: '/en/pricing/', fr: '/fr/tarifs/', 'x-default': '/en/pricing/' }
};
function alternates(key) {
return Object.entries(routes[key]).map(([lang, path]) => ({ lang, href: BASE + path }));
}
app.get(['/en/pricing/', '/fr/tarifs/'], (req, res) => {
res.render('pricing', { alternates: alternates('pricing') });
});
Then, in the shared layout (EJS here), print the block inside <head>:
<% alternates.forEach(a => { %>
<link rel="alternate" hreflang="<%= a.lang %>" href="<%= a.href %>" />
<% }) %>
For a PDF served by Express, add the header before sending the file with res.append(), which Express supports from version 4.11.0:
res.append('Link', '<https://example.com/en/guide.pdf>; rel="alternate"; hreflang="en"');
res.append('Link', '<https://example.com/fr/guide.pdf>; rel="alternate"; hreflang="fr"');
Single-page apps need one extra precaution. If a React or Vue app injects hreflang only in the browser after load, a crawler may index the page before the tags exist. Render them on the server, or move the cluster to the sitemap. Next.js handles this through the alternates.languages field of its Metadata API, which outputs the link elements in the server-rendered HTML.

Hreflang and canonical tags: how they work together
The two tags answer different questions. A canonical tag says which URL to index among duplicates. Hreflang says which indexed URL to show to which audience. Conflicts appear when a canonical removes a page that hreflang wants to show.
The safe pattern is simple: each language version carries a self-referencing canonical, and the hreflang cluster connects them. The French page’s canonical points to the French page, never to the English one. If it pointed to the English page, you’d be telling Google to drop the French URL from the index while asking it to show that same URL to French users. Faced with that contradiction, Google may simply ignore the hreflang.
Canonicals across regions are a different case. Suppose you have en-US and en-CA pages with exactly the same text. Google may treat them as duplicates and choose one canonical for both, whatever your tags say.
Real local differences for each specific region make it far more likely that Google indexes each version and swaps it in properly. Think currency, shipping terms, phone numbers or spelling.
The five common mistakes that break a hreflang cluster
Errors are the rule rather than the exception. A 2023 Ahrefs study, cited by Greenlane, found that 67% of domains using hreflang had at least one issue. The most frequent were a missing x-default (56.3% of domains), a missing self-reference (18%), links to broken or redirected pages (16.9%) and missing return tags (15.3%). Here’s how to spot and fix the ones that matter most. See nichepursuits.com for their take.
1. Missing return links.
- Symptom: the wrong language version keeps appearing, and your audit tool reports “no return tag”.
- Cause: page A points to page B, but B doesn’t point back, often because a new language was added to only one side. Google’s documentation is explicit that such one-way annotations may be ignored.
- Fix: generate the full cluster from a single source, such as a plugin, a route map or the sitemap, so every page carries the same list.
2. Invalid codes.
- Symptom: the tags are present but English speakers in Canada still see the US page, or the correct language never shows up.
- Cause:
en-UK,en_US, a region alone or a full language name. - Fix: check each value against ISO 639-1 and ISO 3166-1 Alpha 2 before publishing.
3. Pointing to URLs that aren’t final.
- Symptom: errors about redirects or non-indexable URLs.
- Cause: the
hreftargets a redirected page, a 404, a page markednoindex, or one whose canonical points elsewhere. Google can’t confirm the return link from a page it won’t index. - Fix: each
hrefmust return a 200 and be its own canonical.
4. Relative URLs.
- Symptom: nothing happens, with no obvious error.
- Cause:
href="/fr/tarifs/"or a URL withouthttps://. Google requires fully qualified URLs. - Fix: always write the protocol and domain, even when every version sits on the same site.
5. Conflicting signals between methods or pages.
- Symptom: different tools report different clusters for the same page.
- Cause: the sitemap says one thing and the
<head>another, or each page names a differentx-default. - Fix: choose one method per content type and remove the leftovers of the other.
One related trap isn’t strictly a tagging error. Redirecting visitors automatically by IP address or browser language can stop Google from crawling your other versions, because Googlebot mostly crawls from US addresses. Google advises against automatic redirection by perceived language. Offer a visible language switcher instead, and let hreflang handle the search results.

How to test hreflang and measure the result
Google Search Console used to include an International Targeting report for hreflang errors, but Google retired it in 2022. Testing now relies on crawlers and browser extensions, plus a few Search Console reports that still help:
- Screaming Frog SEO Spider crawls your site and lists missing return links, invalid codes and non-canonical targets.
- Ahrefs Site Audit and Semrush Site Audit flag the same families of issues in their crawl reports.
- SEO Minion, a browser extension, shows the hreflang set of the page you’re viewing, which is handy for spot checks.
- The URL Inspection tool in Search Console shows the canonical Google selected, so you can confirm each version is indexed in its own right.
To measure the effect, open the Search Console Performance report and filter by country. If the French page starts getting the impressions from France that the English page used to receive, the swap is working. In your analytics, compare bounce rate and conversions per language version: visitors who land on the correct version should stay longer and convert more often. Compare four to eight weeks before and after the change, because recrawling every version takes time.
Where to start if your site already has problems? Fix return links and invalid codes first, since they break whole clusters. Canonical conflicts come next, while a missing x-default can wait: Google recommends it but doesn’t require it.
After that, re-run a crawl after each release, because a new template or URL change can break the cluster without any visible error on the site.
Hreflang implementation checklist
- Confirm you have equivalent content in each language or region.
- List the codes: ISO 639-1 language, plus ISO 3166-1 Alpha 2 region only where content differs.
- Choose one method per content type: HTML head, HTTP header for files, or sitemap.
- Give every version the full set of tags, itself included.
- Use absolute
https://URLs that return a 200 and are indexable. - Add the same
x-defaultURL on every page of the cluster. - Set a self-referencing canonical on each version.
- Match the
<html lang>attribute to the hreflang code. - Render the tags on the server, never only in client-side JavaScript.
- Crawl with an audit tool, then repeat after each release.
Your next step
Pick one page that exists in two languages, such as your pricing or contact page, and add the three-line block from Method 1 to both versions. Check the source of each page, run a crawl, and fix what the tool reports before rolling the same pattern out site-wide. A small, verified cluster teaches you more than a big untested one.
If you’re planning a multilingual build, design the URL structure and the language switcher at the same time as the hreflang setup. All three are far easier to get right together than to retrofit.
FAQ
How do you pronounce hreflang?
In our view, the most natural way to say it is “aitch-ref-lang”. That reading follows the name itself: href (the attribute holding a link’s address) followed by lang (language).
What are tags for SEO, and where does hreflang fit?
SEO tags are pieces of HTML that give search engines information about a page, such as the title tag, the meta description, the canonical tag and the robots meta tag. Hreflang is the one dedicated to language and regional versions. It doesn’t replace the others; each page still needs its own title and description in its own language.
Can hreflang point to a different domain?
Yes. The versions can live on country-code domains such as example.fr and example.de, on subdomains or in folders. The same rules apply: absolute URLs, return links on both sides, and access to each site’s code or sitemap.
Do I need hreflang on every page of the site?
No, only on pages that have an equivalent in another language or region. A blog post that exists only in English needs no hreflang. Adding tags that point to a translated homepage instead of a real equivalent creates a false cluster.
Is hreflang enough if I translate my site with an automatic widget?
Usually not. Widgets that translate in the browser don’t create separate URLs, and hreflang needs a distinct, crawlable URL for each version. Choose a solution that publishes each translation at its own address.
