HTML Lang: Declare the Primary Language of the Document
Browsers, screen readers, and translation systems all benefit from knowing the page language up front.
The lang attribute is a small but foundational signal.
What It Is
The HTML lang attribute is placed on the root <html> element and identifies the primary language of the document.
<html lang="en">
Why It Matters
- Screen readers use it to choose pronunciation rules.
- Browsers and translation tools use it for language-aware behavior.
- It reduces ambiguity for multilingual or international content.
Best Practices
- Set the root language on every page.
- Use the right value, such as
en,en-US, orfr. - Update the value when a page is served in another language.
Common Mistakes
- Leaving the attribute out.
- Using the wrong language code site-wide.
- Forgetting to update it on localized pages.
Quick Checklist
- One
langattribute on<html>. - Correct language code.
- Localized pages use localized values.
Final Takeaway
Language declaration is low effort and high value. There is little reason to ship without it.