Documentation reviewed 24 November 2026.
Quick answer
hreflang is an annotation that tells a search engine which URLs are language or regional versions of the same page, so it can show each searcher the right one. It does not translate anything, it does not replace the canonical tag, and Google does not use it to detect a page's language. You can place it in the HTML head, in an HTTP Link header or in an XML sitemap, and Google treats the three as equivalent. The rules are short: every version lists itself and every other version, the links are returned, the URLs are fully qualified, and the codes are an ISO 639-1 language with an optional ISO 3166-1 Alpha 2 region. Add x-default for searchers whose language you do not serve.
Who this guide is for
This guide is for developers and SEO leads who have to add hreflang to a site, or fix one that reports errors. It covers the annotation only. For URL structure, language switchers and everything else on a multilingual site, see the website localization guide.
At the end you will have:
- The rules, each traced to the search engine's own documentation.
- A correct example of all three placements.
- A script that generates head tags and a sitemap from one list of locales.
- A script that crawls a list of URLs and reports
hreflangerrors. - A checklist to run before and after a release.
Part 1: what hreflang does and does not do
Google's documentation gives hreflang one job: when a page exists in several languages or regions, the annotation helps Google Search point users to the most appropriate version.
Google recommends it in three situations:
- The content is fully translated, for example German and English versions of each page.
- The content is in one language with small regional variations, for example English for the US, Great Britain and Ireland.
- Only the template is translated, such as navigation and footer, while the main content stays in one language. Forums often work this way.
What it does not do, according to the same pages:
- It does not detect language. Google states that it does not use
hreflangor the HTMLlangattribute to detect the language of a page. It uses algorithms on the visible content. - It does not replace
rel="canonical". Canonical says which URL represents a set of duplicates.hreflangsays which URLs are alternates of each other. See Part 6. - It is not documented as a way to rank higher. Google describes it as a way to choose which version to show. Its page on multi-regional sites says targeting a country can improve rankings in that country at the expense of results in other locales.
- It is not required for indexing. Google says it might find alternate versions without help, and that it is usually best to indicate them explicitly.
One side effect is documented. In a 2023 post, Google wrote that URLs in hreflang annotations, including x-default, may be used for URL discovery and scheduled for crawling.
hreflang swaps the URL shown in a result for the version that fits the searcher. It is a statement about a group of pages, so it only works when every page in the group agrees.Part 2: the three placements
Google supports three methods and says they are equivalent from its perspective. It also says that using all three at once brings no benefit in Search and is harder to manage. Pick one per page type.
HTML link elements in the head
Each version of the page carries one <link> per version, itself included. The set is identical on every page in the group.
Two conditions from Google's page:
- The tags must be inside a well-formed
<head>. Google suggests pasting the rendered code into an HTML validator when in doubt. - Do not combine
hreflangwith other alternate attributes, such asmedia, in a single<link>.
HTTP Link header
Use this for files that have no head, such as PDFs. The response to a GET request for each version returns one Link header that lists every version, including the one requested. The header is identical for every version.
XML sitemap
Add the xhtml namespace, then give each URL its own <url> element with one <xhtml:link> child per version, itself included.
Google's sitemap rules for this method:
- The order of the child elements does not matter.
- Child elements do not count toward the sitemap URL limit. A single sitemap is still limited to 50,000 URLs or 50MB uncompressed.
- A sitemap can only contain URLs that descend from the directory it is hosted in.
Which placement fits
| Situation | Placement that fits | Why |
|---|---|---|
| A few languages, templates you control | HTML head | Visible in page source, easy to inspect and test |
| Many languages or many pages | XML sitemap | Keeps the head small. One generated file holds every group |
| PDFs and other non-HTML files | HTTP Link header | These files have no head |
| No access to templates or response headers | XML sitemap | Needs only a file on the server |
| No sitemap and no control of headers | HTML head | Google names this case for the head method |
| Yandex matters to you | HTML head | Yandex states it no longer reads language versions from sitemaps. See Part 11 |

Part 3: the rules
These apply to all three placements. Each one is from Google's page on localized versions.
- Each version lists itself and all other versions. The self reference is part of the set, not an extra.
- Links must be returned. If page X names page Y, page Y must name page X. Google states that when two pages do not both point to each other, the tags are ignored. Otherwise anyone could name their page as an alternate of yours.
- URLs are fully qualified, including the scheme.
https://example.com/foo, not//example.com/fooand not/foo. - Alternates do not need to be on the same domain.
example.comandexample.decan be one group. - One URL, one language of content. Google recommends a different URL for each language version, and a single language for content and navigation on each page.
Two relaxations are documented:
- You may annotate part of a site. Google's 2023 post says it is fine to have
hreflangon only some pages. - You may leave some languages out on some pages. If a complete set is hard to maintain, Google still processes the pairs that do point to each other. It asks that new language pages are linked both ways with the original or dominant language first.
Generate the set once per group and print the same lines on every member. A set written by hand per page is where missing return links come from.
Part 4: language, region and script codes
The value is a language code, optionally followed by a region code, separated by a dash:
- Language: ISO 639-1, two letters.
de,en,fr. - Region, optional: ISO 3166-1 Alpha 2.
en-GB,de-CH. - Script, optional: ISO 15924.
zh-Hant,zh-Hans. A region can follow:zh-Hans-US.
Google states that only codes listed in those two standards are supported. The value is case-insensitive. Google notes that upper-case regions, as in en-GB, follow the ISO convention.
Codes people get wrong
| Written | Problem | Write instead |
|---|---|---|
en-UK | UK is not the assigned code. Google lists UK, EU and UN as codes that have no effect | en-GB |
es-419 | 419 is not an ISO 3166-1 Alpha 2 code. Google names es-419 as unsupported | es for all Spanish speakers, or es-MX, es-AR and so on per country |
GB, US, DE alone | A region cannot stand alone. The first code is always read as a language | en-GB, en-US, de-DE |
be for Belgium | be is the Belarusian language | nl-BE, fr-BE, de-BE |
en-EU | EU is a reserved code, so that part is ignored | en, or one entry per country |
jp, eng | Not ISO 639-1 language codes | ja, en |
en_US | Google's format uses a dash | en-US |
zh-CN when you mean "Simplified Chinese anywhere" | Valid, but it targets users in China | zh-Hans |
zh-CN and zh-Hans are both valid and mean different things. With zh-TW, Google derives the script from the country: Traditional Chinese for users in Taiwan. zh-Hant names the script and no country. Choose by audience.
Language only, or language and region
| Your content | Code to use |
|---|---|
| One page for all speakers of a language | Language only: de |
| Pages that differ by country in the same language | Language and region for each: en-US, en-GB, en-AU, plus a catch-all en |
| A page for a language in a country where it is not the main one | Language and region: de-ES is German for users in Spain |
| A language selector or fallback page | x-default |
Part 5: x-default
x-default is a reserved value. Google uses it when no other language or region in the set matches the searcher's browser setting. It needs no language code, because the language of that page is irrelevant to the match.
Google's documentation and its 2023 post describe three pages it can point to:
- A language or country selector page. Google says the value was designed for these and works best with them.
- The page you send users to when you have nothing for their region.
- The version of the content you consider the default.
So x-default may share a URL with one of your language versions. In Google's own example, a page with English and Spanish versions and x-default on the English URL sends French-speaking users to the English page.
Google's wording is "consider adding" it. It is recommended, not required. Use it when:
- The home page redirects or adapts by location or
Accept-Language. Yandex documents the same use. - You serve some languages and want to choose where everyone else lands.
- A page exists in one language only and other speakers should reach a selector.
Without it, Google picks a version for unmatched searchers itself.
Part 6: hreflang with canonical tags
The correct combination has three parts:
- Each language version names itself as canonical.
- Each version carries the full
hreflangset. - Every
hrefin that set is the canonical URL of its page.
What Google's canonical documentation says on the subject:
- If you use
hreflang, specify a canonical page in the same language, or the best possible substitute language if none exists. - Include a self-referencing
rel="canonical"on the canonical page. - A
rel="canonical"annotation that carrieshreflang,lang,mediaortypeattributes is not used for canonicalization. Keep the two as separate<link>elements.
The mistake: canonicalising every language to English
A translated page is not a duplicate of its source. Google states that localized versions are only considered duplicates if the main content remains untranslated. rel="canonical" is, in Google's words, a strong signal that the specified URL should become canonical. A German page whose canonical is the English URL asks Google to index the English page in its place, while its hreflang asks Google to show the German one. The two instructions contradict each other.
This mistake usually comes from a template, not a person: a layout that prints one hardcoded canonical, or an SEO plugin that builds the canonical from the default language's URL. Check one translated page per template.
Part 7: pagination, parameters, noindex and redirects
Google's hreflang page does not mention these four cases. The rules below follow from its other pages and from how audit tools document the same errors.
Pagination
Google's pagination guidance says to give each page in a sequence its own canonical URL, and not to make the first page canonical for the rest. It follows that page 2 in English is the alternate of page 2 in German, not of page 1. Annotate each page of the sequence with its own set.
URL parameters
A sorted or filtered URL such as ?order=price is normally not the canonical URL. Google suggests keeping such variations out of the index with noindex or robots.txt. Put hreflang on the canonical URL and point it at canonical URLs, with no tracking parameters.
noindex pages
Google says that when it sees noindex on a page, it drops that page entirely from Search results. Such a page cannot be the version shown to anyone. Screaming Frog's documentation adds that noindex on a return link may result in the relationship being ignored. Leave noindex pages out of every set.
Redirects
A URL that returns a redirect has no head and no content of its own, so it cannot return a link. Google's redirect documentation says a permanent redirect signals that the target should be canonical. Point every href at the final URL that returns 200, and update the set whenever URLs move.
| Target of an hreflang link | Keep it? |
|---|---|
| Returns 200, self-canonical, indexable | Yes |
| Redirects | No. Use the final URL |
| Returns 404 or 5xx | No. Remove it or fix the page |
noindex | No |
| Canonical points to another URL | No. Use the canonical URL |
Blocked in robots.txt | No. Google cannot read its return link |
Part 8: one language in several countries
Pages for en-US, en-GB and en-AU often share most of their text and differ in currency, spelling or shipping terms.
Three points from its documentation:
- Add a catch-all. With several regional pages in one language, Google advises a generic version for that language too, for speakers elsewhere. The catch-all can be one of the regional pages.
- A URL can therefore carry two values. If the US page is also your generic English page, list it under
en-USand underen. - Subdomain or folder names are not read. Google states that the
en-gbin a hostname is not used to determine the audience. You must map it explicitly.
Is this duplicate content?
Where similar same-language content sits on different URLs, Google's instruction is to pick a preferred version and use rel="canonical" and hreflang so the correct regional URL is served. Regional pages that are each their own canonical, with a complete set, are declared alternates.
hreflang does not make thin variations worth having. Bing's webmaster blog says localization creates duplicate content when regional or language pages are nearly identical, and advises meaningful differences such as terminology, examples, regulations or product details. If the pages differ in nothing a visitor would notice, one page with a language-only code is less to maintain.

Part 9: generating hreflang at scale
Sets written by hand drift. Generate them from one list of locales and one list of paths.
A generator script
This script targets Node.js 22 or later and has no dependencies. It reads a config file and writes two outputs: the head tags for every page, and a sitemap with xhtml:link children. Use one output, not both.
The script was run for this guide. With the config above it wrote eight pages in two groups, and the sitemap passed xmllint --noout. The head example in Part 2 is its output for /en-gb/pricing, with a title added.
It assumes every path exists in every locale, with the same slug. Two cases need more input:
- Translated slugs. Replace
pathswith a map from a page id to its path per locale. - Pages missing in some locales. Build each set from the locales that have the page, and print no entry for the others.
Next.js
The samples target the Next.js 16 App Router. Its metadata API has an alternates field with canonical and languages. The documentation shows languages rendering as <link rel="alternate" hreflang="..."> elements, and metadataBase turning relative paths into absolute URLs.
Two notes. The x-default key is not in the documentation's example. It is a typed key (UnmatchedLang) in the next 16.4.6 package. And for sitemaps, app/sitemap.ts accepts alternates.languages per entry since v14.2.0 and writes xhtml:link children. The documented output contains only the languages you list, so add the entry's own language to its languages object to meet Google's self-reference rule. This sample follows the documentation and was not run in a Next.js app. Translate a React or Next.js app automatically covers the translation files behind these routes.
WordPress
On WordPress, hreflang comes from the multilingual plugin. Stated from each plugin's own pages:
- WPML says it automatically inserts
hreflangtags into pages and updates them as the site changes, with no action needed. - Polylang says it adds
hreflangautomatically, converts WordPress locales such asen_ZAtoen-ZA, and generatesx-defaultonly for the home page. It documents thepll_rel_hreflang_attributesfilter for changing the set, for example to add a genericenor anx-defaulton every page.
Whichever plugin you use, view the source of a translated page and run it through the audit in Part 10. Best CMS translation tools for content teams compares the wider options.
Shopify
Shopify's theme documentation states that Shopify automatically includes hreflang tags through the content_for_header object. Its help centre states that each published language gets its own URLs. A theme that outputs content_for_header in its layout therefore needs no hreflang code of its own. Nothing further is documented on those two pages about which codes are emitted or about x-default, so check the rendered source of your store. See AI translation for Shopify stores for the translation side.
Part 10: auditing hreflang
The common errors
| Error | What it looks like | Effect | Fix |
|---|---|---|---|
| Missing return link | X names Y, Y does not name X | Google ignores that pair | Print the same set on every member |
| Missing self reference | The page is absent from its own set | Breaks Google's "must list itself" rule | Add the page to its set |
| Wrong language code | jp, eng, a country used as a language | Not a supported value | Use ISO 639-1 |
| Wrong region code | en-UK, en-EU | Google ignores that part of the annotation | Use ISO 3166-1 Alpha 2 |
| Relative URL | href="/de/" | Not fully qualified | Print the scheme and host |
| Redirected or broken target | href returns 301 or 404 | No page to return the link | Point at the final 200 URL |
| Non-canonical target | The target's canonical is another URL | Conflicts with the canonical signal | Use the canonical URL |
| Canonical to another language | German page, English canonical | Asks Google to drop the German page | Self-referencing canonical |
| Tags outside the head | The head closes early in rendered HTML | Tags are not read as head tags | Fix the markup, validate rendered HTML |
| Two methods that disagree | Head says one set, sitemap another | Two answers to one question | Keep one method |
An audit script
This script reads a list of URLs, fetches each without following redirects, and reads hreflang from the head and from the Link header. For every target it fetches the page and checks the return link. It targets Node.js 22 or later and uses the built-in fetch.
It was run against a local fixture: a small Node.js server with four pages and one redirect, each broken on purpose. This is the output:
A missing return link is reported on the page that is not linked back, here French. The fix belongs on /de/, which forgot the link.
Limits of the script:
- It reads the HTML the server returns. Tags added by JavaScript in the browser are not seen.
- It does not read sitemaps.
- Script subtags are checked for shape, four letters, not against the ISO 15924 list.
- A trailing-slash difference counts as a different URL.
Run it in CI against a preview deployment. React localization CI checks shows the same pattern for translation files.
Where other tools report errors
- Google Search Console. The International Targeting report is deprecated. Google's help page says it will continue to support and use
hreflangtags. The Performance report can group data by Countries and Pages, which shows which URL appears in which country. - Tools Google names. Its documentation links to a third-party tag generator by Aleyda Solis and a single-page testing tool by Merkle, and says they are not maintained or checked by Google.
- Screaming Frog SEO Spider. Its documentation describes an Hreflang tab with 13 filters, including Non-200 Hreflang URLs, Missing Return Links, Inconsistent Language & Region Return Links, Non Canonical Return Links, Noindex Return Links, Incorrect Language & Region Codes, Missing Self Reference and Missing X-Default. For sets that span domains it says external pages are not fully reviewed by default.
- Ahrefs Site Audit. Its help centre lists these issues: hreflang annotation invalid, self-reference hreflang annotation missing, page referenced for more than one language, more than one page for same language, hreflang and HTML lang mismatch, missing reciprocal hreflang, hreflang to non-canonical and hreflang to broken page.
Neither crawler was run for this guide. The lists above are what each vendor's page states.
Part 11: Bing and Yandex
Yandex
Yandex documents hreflang on its own Webmaster help pages, with differences from Google:
- Placement. It describes
<link rel="alternate" hreflang>elements in the head. It states that it no longer supports using the sitemap file for language versions. Its page does not describe an HTTP header method. - Codes. ISO 639-1 for the language. For the region, ISO 3166-1 Alpha 2, or ISO 3166-2:RU for Russian regions. It publishes a list of supported languages.
- x-default. Use it when the page language is chosen automatically, for example from the IP address or the
Accept-Languageheader. - Structure. Versions can sit on different domains, subdomains or directories.
If Yandex matters to you, head tags are the placement both engines read.
Bing
Bing's public material says less. A Bing Webmaster blog post from December 2025 tells site owners to use hreflang to define language and regional targeting, with an HTML <link> example, and lists hreflang with canonical tags, redirects and noindex as signals that make clear which URL to show. Microsoft's page on how Bing delivers results says ranking considers the user's location, where the page is hosted and the language of the page.
No Bing page was found that sets out placements, code rules or a return-link requirement, so none are stated here. An hreflang set that is valid for Google uses the same markup Bing's example shows.
Part 12: what to expect after a fix
Google does not document a timeline for hreflang specifically. What it does document:
- Crawling can take anywhere from a few days to a few weeks.
- Requesting a crawl, through the URL Inspection tool for a few URLs or a sitemap for many, does not guarantee instant inclusion in results.
Because a pair only counts when both pages point to each other, a fix is complete for a pair once Google has recrawled both pages. That is a deduction from the return-link rule, not a figure Google publishes.
What to watch:
- Run the audit until it reports nothing.
- Resubmit the sitemap if that is your placement.
- In the Search Console Performance report, group the data by Countries and by Pages and look at which pages appear in each market. English URLs showing in Germany should give way to German URLs as pages are recrawled.
Do not expect a change in how many searches you appear for. hreflang changes which of your URLs is shown.

Doing this with Transglot
Transglot is a continuous localization platform: it keeps the text of a product or site translated. What its documentation states about hreflang is limited to this:
- WordPress. With the Transglot plugin, translations are rendered on per-language URLs with
hreflangand per-language sitemaps. See the WordPress connector page. - Sites built in code.
hreflangis the job of your framework and templates. Transglot supplies the translated files or strings. The routing, the canonical and the alternate links come from code such as the samples in Part 9.
Neither was tested for this guide. Audit the WordPress output the same way as any other site.
Common mistakes
- Missing return links. The set differs from page to page.
- No self reference.
en-UK,es-419, or a country code alone.- Relative or protocol-relative URLs.
- Canonical on every translation pointing at English.
- Targets that redirect after a URL change.
noindexpages in the set.- Tags outside the head in rendered HTML.
- Head tags and a sitemap that disagree.
- Expecting a ranking gain. The gain is the right URL in the right market.
- Automatic redirects by IP or browser language on top of
hreflang. - Every page pointing at each language's home page in place of its own translation.
Checklist
Frequently asked questions
What is an hreflang tag?
An hreflang tag is a <link rel="alternate" hreflang="code" href="url"> element that names one language or regional version of a page. A page carries one per version, itself included.
Does hreflang improve rankings?
Google documents it as a way to point users to the most appropriate version of a page, not as a way to rank higher. Its effect is on which of your URLs appears for a searcher.
What is x-default hreflang and do I need it?
x-default names the page for searchers whose language or region matches none of your versions. Google recommends it and does not require it. It can point to a language selector, to a page you redirect unmatched users to, or to the version you treat as the default.
Should hreflang go in the HTML or in the sitemap?
Google treats the head, the HTTP header and the sitemap as equivalent and advises picking one. The head is easy to inspect. An hreflang sitemap keeps pages lighter when there are many languages. Yandex no longer reads language versions from sitemaps, so use head tags if it matters to you.
Is there an hreflang generator?
Google's documentation links to a third-party generator by Aleyda Solis and notes that it is not maintained or checked by Google. For a site with many pages, generate the tags in code from one list of locales, as the script in Part 9 does.
How do I check hreflang tags?
Fetch each page, read its set, then fetch every target and confirm it returns 200, is canonical, and links back. The script in Part 10 does this for a list of URLs. Google links to a single-page testing tool by Merkle, and crawlers such as Screaming Frog and Ahrefs Site Audit document hreflang reports.
Why does a tool say "your site has no hreflang tags"?
It means the crawler found no hreflang annotations in the pages it read, which is correct for a site in one language. If you do have tags, check that they are inside the <head> of the rendered HTML and that the tool read your sitemap or headers if that is your placement.
Is en-UK a valid hreflang code?
No. The ISO 3166-1 Alpha 2 code for the United Kingdom is GB, so the value is en-GB. Google lists UK, EU and UN as codes that have no effect in hreflang annotations.
How this guide was checked
- Rules, placements, codes, x-default and common mistakes follow Google Search Central's "Tell Google about localized versions of your page", read on 24 November 2026. The
x-defaultuses and the URL discovery note follow Google's 2013 and 2023 blog posts. - Canonical, pagination, noindex, redirects and timing follow the Google pages listed below. Google's
hreflangpage does not cover pagination, parameters, noindex or redirects. Part 7 says where a point is a deduction from other Google pages or comes from a crawler vendor's documentation. - Yandex follows its Webmaster help page on localized pages. Bing follows one Bing Webmaster blog post and one Microsoft support page. An older Bing post on country and language signals returned 404 and was not used.
- Next.js follows the
generateMetadataandsitemapreference pages. Thex-defaultkey was confirmed in the type definitions ofnext16.4.6. The sample was not run in a Next.js app. - WordPress and Shopify are stated only from WPML's, Polylang's and Shopify's own pages. No plugin or store was tested.
- The generator script was run on Node.js 22.15. Its sitemap was checked with
xmllintfor well-formed XML. It was not submitted to Search Console. - The audit script was run on Node.js 22.15 against a local fixture server with seeded errors. The output shown is the real output. It was not run against a production site. Its language and region lists were built from the Library of Congress ISO 639-2 code file (183 two-letter codes) and the Debian iso-codes list for ISO 3166-1 (249 codes).
- Other tools. Screaming Frog and Ahrefs are described from their own documentation. Neither was run or benchmarked. The two tools Google links to were not tested.
- Not tested. No ranking, traffic or indexing effect was measured. Baidu, Naver and AI answer engines are not covered.
Sources
- Google Search Central: Tell Google about localized versions of your page
- Google Search Central: Managing multi-regional and multilingual sites
- Google Search Central: How to specify a canonical URL
- Google Search Central: Pagination and incremental page loading
- Google Search Central: Block Search indexing with noindex
- Google Search Central: Redirects and Google Search
- Google Search Central: Build and submit a sitemap
- Google Search Central: Ask Google to recrawl your URLs
- Google Search Central Blog: How x-default can help you (2023)
- Google Search Central Blog: Introducing x-default hreflang (2013)
- Search Console Help: The International Targeting report is deprecated
- Search Console Help: Performance report
- Yandex Webmaster: Indexing localized pages
- Bing Webmaster Blog: Does duplicate content hurt SEO and AI search visibility?
- Microsoft Support: How Bing delivers search results
- Next.js: generateMetadata
- Next.js: sitemap.xml
- WPML: How to add hreflang in a WordPress website
- Polylang: Hreflang tag attributes and Polylang
- Shopify developers: Support multiple currencies and languages
- Shopify Help: Localization and translation
- Screaming Frog: How to audit hreflang
- Ahrefs Help: How to fix hreflang implementation errors identified by Site Audit
- Library of Congress: ISO 639-2 code list
- Transglot: WordPress connector