Every HTML document has a language, but browsers and assistive technologies can only act on it if you declare it. When the <html> element has no lang attribute, machines are left guessing.
Declaring the language is one of the cheapest accessibility and SEO wins available.
Always declare the primary language of the document on the root <html> element using a valid BCP 47 language tag, such as en-AU for Australian English. This is a formal accessibility requirement: WCAG 2.1 Success Criterion 3.1.1 (Language of Page) requires the default human language of each page to be programmatically determinable, and MDN documents the lang attribute as the way to do it.
<html><head><title>SSW Rules</title></head><body>...</body></html>
❌ Figure: Bad example - Bad example - no lang attribute, so machines must guess the language
<html lang="en-AU"><head><title>SSW Rules</title></head><body>...</body></html>
✅ Figure: Good example - Good example - the document language is declared as Australian English
When part of a page is written in a different language from the document, set lang on that element too. This lets assistive technology switch voices mid-page and keeps translation tools accurate, and it satisfies WCAG 2.1 Success Criterion 3.1.2 (Language of Parts).
<html lang="en-AU"><body><p>Our team says <span lang="fr">bonjour</span> to new clients.</p></body></html>
✅ Figure: Good example - Good example - the French phrase is marked with its own lang attribute
If you publish the same content in multiple languages or regions, add hreflang annotations so search engines serve the right version to each audience. This complements the lang attribute rather than replacing it.
<link rel="alternate" hreflang="en-au" href="https://example.com/au/" /><link rel="alternate" hreflang="en-us" href="https://example.com/us/" />
For more on structuring accessible, discoverable pages, see: