SEO

Hreflang Tag Generator — validated codes, reciprocal sets

Build a complete hreflang set with valid language and country codes, a self-reference, and the return links search engines require.

Used to check the set includes a self-reference, which is required and most often missing.
Separate the code and the URL with a space, a comma, a tab or a pipe. Case is corrected for you.
Pick one method and use it consistently. Mixing them across a site causes conflicting signals.
Verdict
—
 
0
Alternates in the set
0
Errors
0
Warnings
—
Self-reference
Tip: the same complete set — every alternate, plus the page itself — has to appear on every page in the group. A set that only points outwards is the most common reason hreflang is ignored entirely.

An hreflang tag generator is only useful if it enforces the rules that actually break international sites, and there are three: the codes must be real, every page in a group must link to every other page in the group including itself, and one version should usually be marked as the fallback. This page generates the markup and checks what a single page can show: whether each code is real, whether any code or URL is duplicated, whether the page you are marking up appears in its own set, and whether an x-default is present. It cannot visit your other pages, so the return-link rule stays a checklist you confirm on the live site. Everything runs in your browser, so nothing about an unlaunched locale leaves the tab.

The failure that matters most is also the easiest to miss. The markup exists, the codes look plausible and the tags are in the right place, but the return links are missing, so search engines may ignore the set. The pages then fail to swap in the right locale, and the usual conclusion is that hreflang does not work. It does. It just has a stricter contract than most SEO markup.

What This Hreflang Tag Generator Does

List your locales and their URLs, one per line, and the tool builds the complete annotation set in whichever of the three supported formats you need: HTML link elements for the head of a page, an HTTP Link header for non-HTML files such as PDFs, or the xhtml:link markup used inside an XML sitemap. It also validates as it goes.

Each code is split into its language, optional script and optional region parts and checked against the code lists search engines accept: ISO 639-1 for the language, ISO 15924 for the script, ISO 3166-1 alpha-2 for the region. Codes that are the wrong shape entirely — a region with no language, an invented country code, a three-letter language — are errors. Codes that are merely unconventional, such as an uppercase language subtag, are corrected in the output and reported as warnings, because hreflang values are case-insensitive but consistency makes an audit far easier.

Then the structural checks. The page URL you supply at the top is matched against the set to confirm a self-reference exists. Duplicate codes are errors, since two tags claiming the same locale give a crawler no way to choose. Duplicate URLs across different codes are warnings, because that is sometimes deliberate and sometimes a copy-paste mistake. A missing x-default is a warning, and relative URLs are errors.

Know the limits. The language list is ISO 639-1 only, and the script list holds 19 common ISO 15924 scripts rather than all of them. The self-reference check ignores the x-default row and compares URLs exactly, so a trailing-slash difference is reported as an error. In the sitemap format the <loc> is taken from the first row, so change it to the page you are marking up before you paste. In the HTTP header format the tool prints one Link: line per tag; if your server needs a single header, join them with commas as in Google's example.

How to Use It

  1. Enter the URL of the page you are marking up. This is what the self-reference check compares against, so use the exact canonical form including the trailing slash.
  2. List every version of that page. One line each: the locale code, then the absolute URL. Include the page you are on — that line is the self-reference.
  3. Add an x-default line pointing at whichever version should serve users whose language and region you do not target.
  4. Choose the output format and click Generate. The verdict tells you whether the set is complete, and the report lists every error and warning with the line it came from.
  5. Repeat for every page in the group — or better, generate the set once and have your templates output the same block on all of them, with only the self-reference changing position.

How to Read the Result

  • Verdict shows the number of errors when there are any, otherwise "Valid set of N" with a count of warnings. Errors are rows that were dropped from the output or checks that fail; warnings are worth reviewing but do not block the set.
  • Alternates in the set counts the rows that passed validation, including the x-default row. A row with an invalid code or a relative URL is left out of the output and the count.
  • Self-reference reads Present only when a non-x-default row matches the page URL exactly, otherwise Missing.
  • The report under the tags lists each problem with its line number, then a four-point reciprocity checklist that the tool cannot verify for you.

These are the results for the starting set on this page and seven variations of it:

Scenario (change to the default set)AlternatesErrorsWarningsSelf-referenceWhat the report says
Default: six rows, page is the en-US row600PresentValid set of 6, codes valid, x-default declared
en-GB typed as en-UK510Present"UK" is not an ISO 3166-1 country code. Use GB for the United Kingdom.
Page URL is not in any row610MissingNo self-reference: none of the rows points at the page
en-US row written without the trailing slash610MissingDifferent trailing slash; the URLs must match exactly
de replaced by us510Present"us" is a country code used on its own; the language subtag is mandatory
x-default row removed501PresentValid set of 5, 1 warning: no x-default row
Rows EN-us, en-US, fra, x-default222PresentDuplicate en-US, three-letter "fra"; EN and us corrected in the output
Relative URL /en-us/pricing/ in the first row121MissingNot an absolute URL, no self-reference, no x-default

What to Do Next

  1. Fix every error before copying. Rows with errors are not in the output, so the set you paste would be incomplete.
  2. Put the same block on every page in the group, from a template or locale table, and confirm it on the live pages with view-source.
  3. Check that each locale page has a canonical pointing at itself and is not blocked or noindex.
  4. Validate the sitemap with the sitemap validator if you chose that format.
  5. Spot-check which locale each country sees in search results once Google has recrawled the pages, and allow time for that.

How the Codes Are Validated

An hreflang value is a language tag, and language tags have a defined grammar: a primary language subtag, optionally a script subtag, optionally a region subtag, in that order. Search engines accept a useful subset of that grammar — language alone, language plus region, or language plus script plus region — and reject the rest. The full grammar is specified in RFC 5646, Tags for Identifying Languages, and the subset that matters for search is described in Google's documentation on localized versions of a page.

Two mistakes account for most invalid codes in the wild. The first is en-uk. There is no country code UK in ISO 3166-1; the United Kingdom is GB, and en-gb is the correct tag. UK is reserved and will not be recognised, so a British site marked en-uk is running unrecognised markup on every page. The second is using a region on its own, such as us or ca. The language subtag is mandatory and the region is the optional part, so a region-only value is either invalid or, worse, silently read as a language — ca is a valid language code for Catalan, which means a set meant for Canada may quietly target Catalan speakers instead.

A related trap is the region subtag as a whole. It describes the country of the audience, not the country the content was written in or the country the server sits in. es-mx means Spanish for readers in Mexico. It does not mean "Mexican Spanish" as a dialect label, and it will not be shown to Spanish speakers elsewhere unless a broader es version also exists. That is why a language-only tag is usually worth including alongside the regional ones: it catches everyone the specific targets miss.

The Return-Link Rule, and Why It Breaks Everything

This is the rule the whole feature depends on, and it is the differentiator worth understanding properly: hreflang annotations must be reciprocal. If page A declares page B as its French alternate, page B must declare page A as its English alternate. If it does not, the annotation is unconfirmed and search engines may ignore it — not just the one link, but potentially the entire set for those pages.

The reason is straightforward once you think about it as a trust problem. Anyone can add a tag on their own page claiming that some other page is its French version, including on a domain they do not control. Without a return link, that claim is unverifiable and would be trivially abusable to hijack a competitor's rankings in another market. The return link is the confirmation: both pages agree they belong to the same group, and only then does the pair count.

In practice this means every page in a group carries the same block of tags, and that block includes a tag pointing at the page itself. A group of five locales has five tags on each of five pages — twenty-five in total, not twenty. The self-reference is not decoration and it is the part hand-written implementations drop most often, usually because the person writing it thinks of the tags as "links to the other versions". They are not. They are a declaration of the whole group, published identically by every member.

Two corollaries follow. First, if you add a sixth locale, every existing page needs updating, which is why generating these tags from a shared template or a locale table is the only maintainable approach beyond a handful of pages. Second, the URLs in the annotations must match exactly across pages — a trailing slash on one page and not on another produces two different URLs, the return link does not match, and the set silently fails. Our URL parser is useful for spotting exactly where two nearly-identical URLs diverge.

What x-default Is Actually For

The x-default value marks the version to serve when none of the other annotations match the user. It is not "the English version" and it is not "the homepage", although it is frequently both by coincidence. It is the fallback: a language selector page, a global version, or whichever locale you would rather show a visitor from a country you do not specifically target.

It is optional, and this tool warns rather than errors when it is missing, but omitting it means visitors outside your targeted locales get whichever version the search engine guesses at. For a site targeting en-us, en-gb, fr-fr and de-de, that covers four countries and leaves the rest of the world to chance. The x-default tag participates in the same reciprocity rule as everything else: it belongs in the block on every page of the group, not only on the fallback page itself.

Three Places to Put Them, and Never Mix

Hreflang annotations can be delivered in exactly three ways: link elements in the HTML head, an HTTP Link header, or xhtml:link elements inside an XML sitemap. All three are equally valid and search engines treat them the same. The HTML method is the most common and the easiest to debug because it is visible in view-source. The header method exists for files that have no head to put tags in, such as PDFs. The sitemap method scales best for very large sites because it keeps the annotations out of the page payload entirely — a group of ten locales adds ten tags to every page's head, which is real weight on a site with a hundred thousand pages.

Choose one and stay with it. Using two methods at once is not additive; it is a source of contradictions, because the two sets drift the moment somebody updates one and forgets the other, and there is no rule saying which wins. If you go the sitemap route, the annotations have to sit inside the same <url> entry as the <loc> they describe, and the file still has to satisfy every ordinary sitemap rule — run the result through our sitemap validator and build the file itself with the XML sitemap generator. For the HTML method, the tags belong in the head alongside your other meta elements, which our meta tag generator produces.

Hreflang and Canonical Have to Agree

The single most damaging conflict in international SEO is an hreflang set that fights the canonical tags. Each locale page should carry a self-referencing canonical — the French page canonicalises to itself — and the hreflang block declares the group. Point the French page's canonical at the English page instead, as a well-meaning attempt to consolidate duplicate content, and you have told search engines that the French page should not be indexed at all, while simultaneously telling them it is the French version of a group. The contradiction is resolved by ignoring the hreflang.

The same logic applies to noindex. A page excluded from the index cannot be served as anyone's alternate, so a noindex on one locale removes it from the group and, because the return link from that page no longer counts, weakens the rest of the set too. Check the rendered head of each locale before assuming the markup is the problem — and check how the result reads in search with our SERP snippet preview, since a locale showing the wrong language in its title is often the first visible symptom.

Language Versus Region: Choosing Your Granularity

More locales is not better. Every additional locale multiplies the tags on every page, the templates to maintain, and the ways the set can break. The useful question is whether the content genuinely differs by region or only by language. If your Australian and British pages are identical English apart from a currency symbol, en-au and en-gb as separate entries buy you very little and cost you maintenance. If pricing, shipping, legal terms or product availability differ, they are genuinely different pages and the regional split earns its keep.

A practical middle ground is a language-only tag as the base, plus regional tags only where the content really diverges: en for everyone, with en-us and en-au layered on top where the differences matter. Search engines prefer the most specific match and fall back to the language-only version otherwise, which is exactly the behaviour you want. If you are also marking up regional organisation or product data, our schema markup generator covers the structured-data side of the same problem.

Running a site across several countries and languages?

Arb Digital plans international site structure, implements hreflang and canonical signals that agree with each other, and tracks performance per locale rather than as one blended number.

SEO Services Talk To Our Team

Common Mistakes to Avoid

  • Leaving out the self-reference — every page must include a tag pointing at itself, or the group is incomplete and may be discarded.
  • Using en-uk — the ISO 3166-1 code for the United Kingdom is GB. UK is not recognised and the tag does nothing.
  • Writing a region without a language — the language subtag is mandatory, and codes like ca will be read as a language rather than a country.
  • Canonicalising one locale to another — it removes that page from the index and breaks the return link, taking the rest of the set down with it.
  • Mixing delivery methods — HTML tags plus sitemap annotations plus HTTP headers drift apart, and nothing defines which set wins.

Related Free Tools From Arb Digital

Build the rest of the head with the meta tag generator, produce the sitemap that carries these annotations with the XML sitemap generator, check that file with the sitemap validator, compare two near-identical URLs with the URL parser, preview how a locale appears in results with the SERP snippet preview, or add structured data with the schema markup generator. Everything we publish is in the free online tools hub.

Frequently Asked Questions

What is the hreflang return-link requirement?

Annotations must be reciprocal. If page A declares page B as an alternate, page B must declare page A in return. Without that confirmation the annotation is unverified and search engines may ignore the whole set, because otherwise anyone could claim another site's page as their alternate.

Does every page need a tag pointing at itself?

Yes. The self-reference is required, and it is the part most hand-written implementations leave out. A group of five locales therefore carries five tags on each of the five pages.

Why is en-UK invalid?

Because UK is not an ISO 3166-1 country code. The United Kingdom is GB, so the correct tag is en-GB. A site using en-UK is publishing an unrecognised value on every page.

What does x-default do?

It marks the fallback version for users whose language and region match none of your other annotations. It is optional but recommended, and like every other tag in the group it must appear on every page, not only on the fallback page.

Can I use hreflang in an XML sitemap instead of the page head?

Yes. HTML link elements, HTTP Link headers and sitemap annotations are all valid and treated equally. Choose one method and use it consistently, because two methods drift apart and nothing defines which one wins.

Should each locale canonicalise to itself?

Yes. Each locale page needs a self-referencing canonical. Pointing one locale's canonical at another removes it from the index and breaks the return link, which weakens the annotations for the rest of the group.

Do I need a region code, or is a language enough?

A language alone is enough, and is often the better choice. Add a region only where the content genuinely differs by country, since every extra locale multiplies the tags to maintain and the ways the set can break.

Is anything I enter here sent to a server?

No. Validation and tag generation both run in your browser, so you can safely paste URLs for locales that have not launched yet.

Take it further

Prefer to hand this off? See how our Web Design & Build work handles it for clients.