Invalid hreflang language code: en-UK, en_US and other values Google ignores

An hreflang value has a fixed format: a two-letter ISO 639-1 language code, optionally followed by a hyphen and a two-letter ISO 3166-1 Alpha 2 region code. en, en-GB and pt-BR are valid. en-UK, en_US and US are not, and Google ignores annotations it cannot parse.

The page is still indexed normally. What fails is the targeting: the version you built for a particular language or country is not matched to those searchers.

What it looks like

Before

html
<link rel="alternate" hreflang="en-UK" href="https://example.com/uk/">
<link rel="alternate" hreflang="en_US" href="https://example.com/us/">
<link rel="alternate" hreflang="jp" href="https://example.com/jp/">

After

html
<link rel="alternate" hreflang="en-GB" href="https://example.com/uk/">
<link rel="alternate" hreflang="en-US" href="https://example.com/us/">
<link rel="alternate" hreflang="ja" href="https://example.com/jp/">

The format, precisely

  • Language first, always. The language code is required. The region is optional and can never stand alone.
  • Hyphen, not underscore. en-US, not en_US.
  • Case is not significant in language tags, though the convention is lower-case language and upper-case region.
  • Script codes are allowed where a language is written in more than one script, using ISO 15924: zh-Hans for Simplified Chinese, zh-Hant for Traditional, and optionally a region after it, as in zh-Hant-TW.
  • x-default is the one reserved value that is not a language. It marks the fallback page.

List every hreflang value on a page with:

code
curl -s https://example.com/ | grep -io 'hreflang="[^"]*"' | sort | uniq -c

Mistakes we see most

Country codes that are not the ISO code. The United Kingdom is GB, so British English is en-GB. en-UK is the single most common error.

Country code used as a language. The language code often differs from the country's:

IntendedWrongRight
Japanesejpja
Koreankrko
Czechczcs
Danishdkda
Swedishsesv
Greekgrel
Ukrainianuauk
Chinesecnzh

Some of the wrong values are valid codes for other languages, which is worse than being invalid: uk targets Ukrainian speakers, not the United Kingdom, and se is Northern Sami.

Region only. hreflang="US" or hreflang="de-". A region needs a language in front of it.

Regions that are not countries. en-EU and es-LA do not work, because the European Union and Latin America are not ISO 3166-1 countries. Google's documentation specifies country codes for the region part, so target the language alone (es) or list the individual countries.

Three-letter codes. eng and deu are ISO 639-2. Use the two-letter forms.

Typos in x-default, such as xdefault or x_default.

Where bad values come from in WordPress

WordPress stores locales with an underscore: en_US, pt_BR, de_DE_formal. Code that prints get_locale() straight into an hreflang attribute produces invalid values. Convert it:

php
$hreflang = str_replace( '_', '-', get_locale() ); // en-US

Even then, check for locales with a third part such as de_DE_formal, which converts to de-DE-formal and is not a valid hreflang value; trim it to the first two parts.

In multilingual plugins, the hreflang code for each language is usually an editable field in the language settings, separate from the locale and the URL slug. A custom language added by hand, or a default edited to match the URL folder (/uk/), is where en-UK typically enters. Fix the field once and every page updates.

For hand-built sets, our hreflang tag generator checks each code as you add it and outputs the tags with x-default.

Language-only or language plus region?

Use the region only when you have separate pages for the same language in different countries, such as prices in pounds and in dollars. If you have one English version, en is correct and serves English speakers everywhere. A common overreach is to tag a single English page as en-US, which says nothing useful to English speakers elsewhere. Where you have both, add a plain-language tag as the catch-all:

html
<link rel="alternate" hreflang="en-GB" href="https://example.com/uk/">
<link rel="alternate" hreflang="en-US" href="https://example.com/us/">
<link rel="alternate" hreflang="en" href="https://example.com/us/">

The lang attribute on the <html> element is a different thing. It declares the language of the current page for browsers and assistive technology, and Google does not use it for language targeting. It follows a similar syntax, so the same underscore mistake appears there. See missing HTML lang attribute.

Check the corrected tags

Run the listing command again on each language version and read every value against the format rules. Make sure the set is still identical on all versions after your edit, since changing a code in one template and not another creates missing return tags. The free SEO audit counts the hreflang tags on a page but does not validate the codes, so use the generator or a crawler for that.

Common questions

Is en-UK ever accepted?

No. The ISO 3166-1 code for the United Kingdom is GB. Use en-GB.

Can I target a continent or a group of countries?

Not with one value. Use the language alone, or one tag per country pointing at the same URL.

Does capitalisation matter?

No. Language tags are case-insensitive, so en-gb and en-GB mean the same. Pick one style for readability.

Is es-419 valid for Latin American Spanish?

It is a valid language tag in the broader standard, but Google's documentation specifies ISO 3166-1 country codes for the region part, so do not rely on it for hreflang.