ratemysite.ai

How to set the lang attribute on your HTML element

The lang attribute on the html element declares the page language for search engines, screen readers and translation tools. Set it to a valid code such as en, and add a region like en-GB only when the spelling or content truly differs by region.

By . Updated .

How do you fix it?

  1. Open your base template and find the opening <html> tag.
  2. Add the language code, for example <html lang="en">, using the primary language of the visible text.
  3. Use the two or three letter language code first, and add a region only when needed, as in pt-BR.
  4. Mark passages in another language with their own lang attribute on the surrounding element.
  5. Re-run the audit and confirm the HTML lang check passes.

What is the HTML lang attribute?

The lang attribute is a short code on the html element that names the language of the page, such as en for English or fr for French. Screen readers use it to choose the right voice and pronunciation, browsers use it to offer translation, and search engines use it as one more hint about who the page is for. Without it, a screen reader may read English text with a French accent, which makes the page hard to follow.

Which language code should I use?

Use the two letter ISO 639-1 code, such as en, es or de. Add a region subtag only when it changes the content, for example en-GB for British spelling or pt-BR for Brazilian Portuguese. A single site in 1 language needs only one value on the html element. If part of the page switches language, such as a quoted French phrase, wrap it in an element with its own lang attribute so assistive tools can follow.

How much does this check matter?

What else do people ask?

Does Google use the lang attribute to rank pages?
Google says it detects language from the visible text, but the attribute still helps other engines, assistive tools and browsers decide how to handle the page.
Is lang the same as hreflang?
No. lang describes the current page. hreflang links alternate versions of a page in other languages or regions.

Sources