Add Language Attribute to HTML Element
Learn how to add the lang attribute to HTML pages for proper accessibility and SEO. Includes code examples and language code reference.
What Is It?
The lang attribute specifies the primary language of a page using ISO 639-1 language codes (e.g., 'en' for English, 'es' for Spanish, 'de' for German). It goes on the <html> tag.
Affected users: Screen reader users, search engines, spell-checking systems, browser hyphenation systems
Why It Matters
Screen readers need to know the language to pronounce words correctly. Search engines use it for language-specific indexing. Browsers use it for spell-checking and hyphenation.
How to Detect This Issue
View page source and check the <html> tag. Look for lang="..." attribute. If missing or empty, it's a violation. Test with multiple language versions if applicable.
Code Examples & Fixes
HTML / CSS
<html><html lang="en">For pages in other languages, use the appropriate code: lang="es" for Spanish, lang="fr" for French, lang="de" for German, etc.
React / Next.js
ReactDOM.render(<App />, document.getElementById("root"));document.documentElement.lang = "en"; ReactDOM.render(<App />, document.getElementById("root"));In Next.js, use the html lang attribute in your _document.js or layout component. For Next.js 13+, set it in layout.tsx metadata.
WordPress
<html><html lang="en-US">In WordPress, the lang attribute is set automatically in wp_language_attributes(). Verify it's in your theme's header.php <html> tag.
Shopify Liquid
<html><html lang="{{ shop.locale }}">Shopify uses Liquid template language. Use {{ shop.locale }} to automatically set the correct language for each region.
Common Mistakes
Using generic 'en' when you should use regional codes like 'en-US' or 'en-GB'
Adding lang only to <body> instead of <html> root element
Not updating lang attribute for multilingual sites on per-page basis
Using incorrect language codes (e.g., 'eng' instead of 'en')
Assuming the lang attribute will be inherited (it must be explicitly set)
Frequently Asked Questions
What language codes should I use?
What if my page has multiple languages?
Do I need lang attributes on every page?
Does lang attribute affect SEO?
Check your website for free
Get your ADA, WCAG, privacy & security score in 90 seconds.