Every hreflang tag carries a short code, and that code is where most of the confusion lives. Is it en, en-GB or en-UK? Does Spanish for Latin America get a country code at all? A wrong guess does not produce a slightly weaker tag. It produces a tag that declares a language or region in a shape search engines do not recognise.
The good news is that the format is small and strict. A code is built from a fixed list, in a fixed order, with only two optional shapes for the region part. This guide lays out that format and builds a correct set with the free Hreflang Tag Generator on Ovatly, which validates the codes as you enter them.
Contents
- Quick answer
- The anatomy of a code
- Language codes: the ISO 639-1 list
- Region codes: two letters or three digits
- Plain language or region: making the choice
- x-default: the code that is not a code
- What codes cannot express
- How to generate a set with correct codes, step by step
- Worked example: English and French versions of one page
- Limitations
- Common mistakes
- FAQs
- Conclusion
Quick answer
Write the language first, using its two-letter code from the ISO 639-1 list: en, fr, es. Add a region only when the content genuinely differs by country, as two letters (en-GB, en-US) or, for a multi-country region, three digits (es-419 for Latin America). Leave the region off when the page targets all speakers of the language. The Hreflang Tag Generator checks language codes against the ISO 639-1 list and format-checks region codes, so a malformed code is flagged before you copy anything.
The anatomy of a code
A hreflang value has up to two parts joined by a hyphen. The first part is always the language. The second part, when present, is the region. Language first, region second, never the other way round: en-GB is English as used in the United Kingdom, and no valid arrangement puts the country first.
Each tag pairs one of these codes with the full URL of the version it describes. The code says who the version is for; the URL says where it lives. Together the tags form the declaration that tells search engines which version to show each user.
Language codes: the ISO 639-1 list
Language codes are not improvised. They come from ISO 639-1, the international list that assigns each language a two-letter code: en for English, fr for French, es for Spanish. If a code is not on that list, it is not a language code, however plausible it looks.
This matters because plausible inventions are easy. A guessed code can look right and still not be the one the list assigns, and only the listed code declares anything. Working from a generator that validates against the ISO 639-1 list removes the guesswork: an unlisted code is rejected at entry rather than discovered months later.
Region codes: two letters or three digits
When a region is justified, it takes one of two shapes. The common one is two letters naming a country: GB in en-GB, US in en-US. The second shape is three digits naming a multi-country region: 419 in es-419, the code for Latin America, which lets one Spanish version serve a whole group of countries at once.
Those are the only two shapes. A region written as three letters, or a country name spelled out, falls outside the format and is not recognised. The generator format-checks region codes against exactly these shapes.
Plain language or region: making the choice
The decision rule is about audience, not about how many offices the company has. Use a plain language code when the page targets all speakers of that language: one English page meant for every English reader is en, full stop. Add a region only when the content genuinely differs by country: different delivery terms, different legal wording, a catalogue that really is not the same in the two places.
Splitting by region without a genuine difference behind it creates near-identical versions that have to be maintained and kept consistent, and tells engines there is a distinction where none exists. One honest en serves readers better than three decorative regional copies of the same text.
x-default: the code that is not a code
Alongside the language codes, a set can carry one special value: x-default. It is not a language and it has no region. It names the fallback page for visitors whose language or region matches none of your versions, often a language selector page or your main English page.
Think of it as the answer to a question the other codes cannot cover: what should a user see when nothing matches? It is optional, and the rest of the set works without it, but leaving it out leaves that question unanswered.
What codes cannot express
Hreflang targets language and region, and nothing else. There is no code for a page that differs only in currency, and no code for content differences within the same language and region. A store showing the same English page to the same country with different prices has one version, not two, and no hreflang value will describe it as anything else. If the difference is not language or region, hreflang is not the mechanism for it.
How to generate a set with correct codes, step by step
- Open the Hreflang Tag Generator.
- Add a row for every language or region version of the page, including the original.
- In each row, enter the code and the full URL of that version, using codes like
en,en-GBores-419. Language codes are validated against the ISO 639-1 list; region codes are format-checked. - Optionally set an x-default URL for visitors whose language matches nothing.
- Copy the link tags into every version's
<head>, or use the sitemap version in your sitemap file. Both implementations are equivalent to search engines; tags are easier for a few pages, and the sitemap version scales better and avoids editing every template.
Worked example: English and French versions of one page
A page exists in English at https://example.com/page and in French at https://example.com/fr/page. Neither version is country-specific: the English page is for all English speakers, the French page for all French speakers. So the codes are the plain language forms, en and fr, with no regions attached. The English page also serves as the fallback, so it is entered a second time as x-default.
The output includes <link rel="alternate" hreflang="en" href="https://example.com/page">, the matching fr tag, and an x-default tag, plus a sitemap block where each <url> lists all versions as xhtml:link alternates. Had the English content genuinely differed between the United Kingdom and the United States, the honest codes would have been en-GB and en-US with separate URLs. The codes describe the versions that exist, not versions a site might one day grow into.
Limitations
Correct codes are necessary but not sufficient. Hreflang is reciprocal: every version must list every other version, including itself, or search engines may ignore the set. The versions also need to be real, reachable pages whose canonical tags point at themselves. Publishing the output, and keeping codes in step when versions change, stays with you.
Common mistakes
- Inventing a language code. If it is not on the ISO 639-1 list, it declares nothing.
- Writing the region first. The order is fixed: language, then region.
- Guessing a three-letter region. Regions are two letters or three digits; there is no third shape.
- Adding regions for identical content. A region code claims the content genuinely differs by country. If it does not, use the plain language code.
- Treating x-default as a language. It is the fallback value, not a code for any audience.
FAQs
Where do hreflang language codes come from? From the ISO 639-1 list of two-letter language codes, such as en for English, fr for French and es for Spanish. The generator validates language codes against that list.
What shapes can a region code take? Two letters for a country, as in en-GB or en-US, or three digits for a region group, as in es-419, where 419 stands for Latin America. Region codes are format-checked against those two shapes.
Should I use en or en-GB style codes? Use a plain language code (en) when the page targets all speakers of that language. Add a region (en-GB, en-US) only when the content genuinely differs by country.
Is x-default a language code? No. It is a special value that names the fallback page for users whose language or region matches none of your versions, often a language selector page or your main English page.
Can a code separate pages that differ only in currency? No. Hreflang targets language and region, not currency or content differences within the same language and region, so there is no code for a price-only variant.
Conclusion
The code format rewards precision and punishes improvisation: language from the ISO 639-1 list, region as two letters or three digits and only when the content earns it, x-default as the fallback. Generate the set with the Hreflang Tag Generator and the validation happens as you type. For what goes wrong when these rules are broken, see the companion guide, Hreflang Mistakes That Stop International Pages Ranking, and browse the rest of the SEO Tools guides for the neighbouring tag sets.