HTML Guides for subtag
Learn how to identify and fix common HTML validation errors flagged by the W3C Validator — so your pages are standards-compliant and render correctly across every browser. Also check our Accessibility Guides.
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>
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.
1K Weekly
1,000 monthly checks. Cancel anytime.
Get 1K Weekly →Join teams across 40+ countries