Why It Matters
- Screen readers use it to choose the right voice. When a screen reader encounters a page with
lang="en", it uses an English voice with English pronunciation rules. An invalid or missing lang attribute may cause it to use the wrong language engine, making content incomprehensible. - Browsers use it for rendering decisions. The lang attribute influences hyphenation, quotation mark styles, font selection for CJK languages, and other rendering details. An invalid code means the browser cannot apply these language-specific rules correctly.
- Search engines use it for content targeting. The lang attribute helps search engines understand which language your content is in and serve it to the appropriate audience. Invalid codes confuse this targeting and may result in your page being shown to the wrong users.
- Translation tools depend on it. Browser-based translation features and third-party translation services use the lang attribute to determine the source language. An invalid code may cause incorrect translations or prevent the translation feature from activating at all.
How to Fix It
- Set the lang attribute on the html element. Every page should have
<html lang="xx"> where xx is the correct BCP 47 language code. For English pages, use lang="en". For American English specifically, use lang="en-US". - Use valid BCP 47 language codes. Stick to recognized codes:
en, es, fr, de, ja, zh, and so on. Do not invent codes, use full language names like lang="english", or use country codes alone like lang="US". - Match the code to the actual content language. If your page is in French, use
lang="fr" — not lang="en" because your CMS defaulted to English. The code must match what users actually read on the page. - Check your CMS or template configuration. Many CMS platforms set the lang attribute through a global configuration setting. Make sure it is configured correctly rather than left at a default value that may not match your content language.
- Validate with accessibility testing tools. Run an accessibility check on your pages to confirm the lang attribute exists and contains a valid code. Invalid codes are easy to miss visually but caught instantly by automated validators.
Common Mistakes
- Omitting the lang attribute entirely. A page without a lang attribute forces screen readers and browsers to guess the language. They often guess wrong, especially for less common languages, leading to mispronunciation and rendering issues.
- Using invalid or made-up codes. Codes like
lang="english", lang="eng", or lang="uk" (which means Ukrainian, not United Kingdom English) are either invalid or misunderstood. Always reference the BCP 47 standard. - Setting the wrong language. Using a template designed for one language on a site in another language and forgetting to update the lang attribute is surprisingly common. The page says
lang="en" but the content is in Portuguese. - Forgetting to update lang for multilingual sites. Sites with multiple language versions need each version to have the correct lang attribute. A Spanish page served with
lang="en" causes screen readers to attempt English pronunciation of Spanish words.
Bottom Line: Set a valid BCP 47 language code on the <html> element of every page, match it to the actual content language, and verify it with accessibility validators. It is a single attribute that affects screen readers, browsers, search engines, and translation tools — getting it right costs nothing and getting it wrong hurts everyone.
-
-
-
-
Follow us around the web: