# Bad value X for attribute “lang” on element “html”: The language subtag X is not a valid ISO language part of a language tag.

> Canonical HTML version: https://rocketvalidator.com/html-validation/bad-value-x-for-attribute-lang-on-element-html-the-language-subtag-x-is-not-a-valid-iso-language-part-of-a-language-tag
> Attribution: Rocket Validator (https://rocketvalidator.com)
> License: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/)

The `lang` attribute on the `<html>` element tells browsers, screen readers, and search engines what language the page content is written in. Its value must follow the BCP 47 standard, which uses ISO 639 language codes as the primary language subtag. When the validator reports that a language subtag "is not a valid ISO language part of a language tag," it means the code you provided doesn't match any recognized language in the ISO 639 registry.

## Common Causes

### Typos in the language code

A simple misspelling like `emg` instead of `en`, or `fre` instead of `fr`, will trigger this error.

### Using a country code instead of a language code

Country codes (ISO 3166) and language codes (ISO 639) are different standards. For example, `uk` is the country code for the United Kingdom, but it's also the valid language code for Ukrainian. Using `gb` (Great Britain) as a language would be invalid. Similarly, `us` is not a language code — you need `en` for English or `en-US` for American English specifically.

### Using made-up or deprecated codes

Codes like `xx`, `en-UK`, or other non-standard values will fail validation. Note that while `en-US` and `en-GB` are valid (language-region format), `en-UK` is not because `UK` is not the correct ISO 3166-1 region subtag for the United Kingdom — `GB` is.

## Why This Matters

- **Accessibility:** Screen readers rely on the `lang` attribute to select the correct pronunciation rules and voice profile. An invalid language code can cause assistive technology to mispronounce content or fall back to a default language.
- **SEO:** Search engines use the `lang` attribute as a signal for serving the right content to users in the appropriate language and region.
- **Browser behavior:** Browsers use the language tag for spell-checking, hyphenation, font selection, and other language-sensitive rendering decisions.

## How to Fix It

1. Identify the language your page is written in.
2. Look up the correct ISO 639-1 two-letter code (preferred) or ISO 639-2 three-letter code for that language.
3. If you need to specify a regional variant, append a hyphen and the ISO 3166-1 region code (e.g., `pt-BR` for Brazilian Portuguese).
4. Replace the invalid value in the `lang` attribute.

Some commonly used valid language codes:

| Language | Code |
|---|---|
| English | `en` |
| English (US) | `en-US` |
| English (UK) | `en-GB` |
| Spanish | `es` |
| French | `fr` |
| German | `de` |
| Portuguese (Brazil) | `pt-BR` |
| Chinese (Simplified) | `zh-Hans` |
| Japanese | `ja` |
| Arabic | `ar` |

## Examples

### ❌ Invalid: Typo in language code

```html
<html lang="emg">
```

### ❌ Invalid: Country code used instead of language code

```html
<html lang="us">
```

### ❌ Invalid: Incorrect region subtag

```html
<html lang="en-UK">
```

### ❌ Invalid: Made-up language code

```html
<html lang="english">
```

### ✅ Valid: Correct two-letter language code

```html
<html lang="en">
```

### ✅ Valid: Language with region subtag

```html
<html lang="en-GB">
```

### ✅ Valid: Full document with proper lang attribute

```html
<!DOCTYPE html>
<html lang="fr">
  <head>
    <meta charset="utf-8">
    <title>Ma page</title>
  </head>
  <body>
    <p>Bonjour le monde !</p>
  </body>
</html>
```

You can verify your language tag using the [IANA Language Subtag Registry](https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry) or the [BCP 47 Language Subtag Lookup tool](https://r12a.github.io/app-subtags/) to ensure your code is valid before updating your markup.
