Coding Now – Best AI & Full Stack Courses in Delhi NCR | 100% Placement
Limited Offer: Get 50% OFF on AI & Full Stack Courses
📞 Call Now: +91 9667708830
Back to HTML Notes
Topic #117

HTML lang Attribute

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 lang to 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 lang entirely — 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 of lang="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.

Related HTML Notes

Want to go beyond the notes?

Join CodingNow's HTML course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available
💬 Talk to Advisor
1
WhatsApp

Latest from Our Blog

Insights on AI, Data Science, Full Stack & Career

View All Articles →