Skip to main content
HTML Validation

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

About This HTML Issue

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

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

Valid example

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

Find issues like this automatically

Rocket Validator scans thousands of pages in seconds, detecting HTML issues across your entire site.

Help us improve our guides

Was this guide helpful?
🌍 Trusted by teams worldwide

Validate at scale.
Ship accessible websites, faster.

Automated HTML & accessibility validation for large sites. Check thousands of pages against WCAG guidelines and W3C standards in minutes, not days.

Scheduled Reports
API Access
Open Source Standards
€5 / week

1K Weekly

1,000 monthly checks. Cancel anytime.

Get 1K Weekly →

Join teams across 40+ countries