Skip to Content
OpportunitiesTechnicalIssue ReferenceHreflangInvalid hreflang language or region code

Invalid hreflang language or region code

What it is

At least one hreflang link on the page has a value that is not a valid language code, optionally followed by a country code. Typical cases are en-UK (the United Kingdom is GB), en_US with an underscore, a three-letter language such as eng, a country on its own such as gb, and a regional code such as es-419 for Latin America.

Why it matters

Google reads an hreflang value as an ISO 639-1 language code with an optional ISO 3166-1 alpha-2 region . It names es-419 as unsupported and says it ignores a reserved region such as UK or EU, so en-UK is likely read as plain en. An entry with a bad code does not reach the audience you meant, and people there may be shown another version of the page.

How Asky checks it

Asky checks the value of every <link rel="alternate" hreflang> in the page’s raw HTML, in any letter case. Valid is x-default, or a two-letter ISO 639-1 language, then an optional four-letter script (zh-Hant), then an optional ISO 3166-1 alpha-2 country, joined by hyphens. Rejected: empty values, underscores, languages that are not two-letter ISO 639-1 codes (eng, gb), reserved or unassigned countries (UK, EU), UN M.49 areas (419) and extra parts. The page gets one finding listing every invalid value, with the fix where there is one (en-GB for en-UK). Any four letters pass as a script, and the href is not checked.

Reported as an error with high severity.

How to fix it

  1. Open the finding to see each invalid value and the reason Asky gives for it.
  2. Write each value as a two-letter language, a hyphen and a two-letter country: en-GB, pt-BR, de-AT. Use the language alone, such as en, for a version aimed at all speakers of it.
  3. There is no country code for Latin America or other groups of countries. Use the language alone (es), or add one link per country (es-MX, es-AR, es-CO), which may all point to the same URL.
  4. Fix the value where it is generated: the locale settings of your CMS’s localization feature, the language settings of a multilingual plugin, or the template. Every page in the group shares the same set, so one setting usually fixes them all.
  5. Use each value only once on a page, and add an x-default when the page lists two or more versions, so the fix does not raise the duplicate or x-default issues.

Example

The hreflang set on https://example.com/pricing, with three invalid values and then corrected:

<!-- Before --> <link rel="alternate" href="https://example.com/uk/pricing" hreflang="en-UK"> <link rel="alternate" href="https://example.com/pricing" hreflang="en_US"> <link rel="alternate" href="https://example.com/es/precios" hreflang="es-419"> <!-- After --> <link rel="alternate" href="https://example.com/uk/pricing" hreflang="en-GB"> <link rel="alternate" href="https://example.com/pricing" hreflang="en-US"> <link rel="alternate" href="https://example.com/es/precios" hreflang="es"> <link rel="alternate" href="https://example.com/pricing" hreflang="x-default">

← Back to Hreflang

Last updated on