# Bad value X for attribute “lang” on element “html”: Subtags must not exceed 8 characters in length.

> Canonical HTML version: https://rocketvalidator.com/html-validation/bad-value-x-for-attribute-lang-on-element-html-subtags-must-not-exceed-8-characters-in-length
> Attribution: Rocket Validator (https://rocketvalidator.com)
> License: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/)

The `lang` attribute on `<html>` holds a value with a piece longer than 8 characters, which no BCP 47 language tag allows.

A language tag is made of subtags separated by hyphens, such as `en`, `en-US` or `zh-Hant-TW`. BCP 47 caps every subtag at 8 characters, so the validator rejects the value before it even checks whether the language exists. A primary language subtag is normally only two or three letters long.

Two mistakes cause this most often. The first is writing the language name instead of its code, as in `lang="portuguese"` instead of `lang="pt"`. The second is a template placeholder that was never filled in: a theme or CMS outputs `lang="$language"` literally because the variable was not replaced, and `$language` is 9 characters long. In that case, fix the template so it prints the real code, or hardcode the code if the site has a single language.

Screen readers read `lang` to pick a pronunciation, and browsers use it for hyphenation, spell checking and translation prompts, so a broken value hurts real visitors too.

## Invalid example

```html
<!DOCTYPE html>
<html lang="$language">
  <head>
    <title>Welcome</title>
  </head>
  <body>
    <p>Welcome to our site.</p>
  </body>
</html>
```

## Valid example

```html
<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Welcome</title>
  </head>
  <body>
    <p>Welcome to our site.</p>
  </body>
</html>
```
