The lang attribute on <html> declares the page's primary language — it's small, easy to forget, and genuinely affects accessibility and SEO.
Syntax
<html lang="en"> <!-- English -->
<html lang="hi"> <!-- Hindi -->
<html lang="en-IN"> <!-- English as used in India -->
Values follow the BCP 47 language tag format — a two-letter language code, optionally followed by a region code.
Why It Matters
- Screen readers use
langto choose the correct pronunciation rules and voice — without it, a screen reader may mispronounce content using the wrong language's rules - Browsers use it to offer accurate "translate this page" suggestions
- Search engines use it as one signal for serving the right page to users searching in a given language
Overriding lang for Part of a Page
<html lang="en">
...
<p>
The French phrase <span lang="fr">c'est la vie</span> means "that's life."
</p>
The lang attribute is global — it can be set on any element to mark a specific phrase as being in a different language than the rest of the page.
Common Mistakes
- Omitting
langentirely — a small thing that's flagged by nearly every accessibility audit tool (like Lighthouse) - Setting the wrong language code, or using a full language name instead of the code (
lang="English"instead oflang="en")
Interview Relevance
A good "small but real" accessibility question: "Why does the lang attribute matter, and what happens if it's missing?" — shows whether a candidate thinks about accessibility beyond just ARIA attributes.
Practice Question
Add the correct lang attribute to an <html> tag for a page written primarily in Hindi.