Skip to content

Why the html lang attribute matters

SEO1 min readFixes check lang-attr

The lang attribute tells browsers, search engines and screen readers what language the page is in. It affects translation prompts, hyphenation and pronunciation.

Step by step, with screenshots: hreflang language and region codes: the reference table →

Check your own site

Runs this check and the other 192, free, in about 45 seconds.

Or run only this check with the free Hreflang checker, the free AI crawlers check or the free AI visibility checker.

What it is

The html lang attribute declares the main language of a page, for example <html lang="en"> or <html lang="hr">. It uses a BCP 47 language tag: a language code, optionally followed by a region, such as en-GB or de-AT.

Screen readers use it to pick the right voice and pronunciation, browsers use it for translation prompts, hyphenation and spell-check, and Bing reads it as a language hint. Google says it detects language from the visible text, so for search across languages you also need hreflang. A missing lang fails WCAG 2.2 success criterion 3.1.1, one of the most basic accessibility checks.

OK looks like this: the html element carries one valid lang value that matches the language the page is actually written in. getReport checks that the attribute exists and holds a valid code.

What a passing site looks like

  • The <html> element declares its languagewarning · −1.5 ptseffort S

The <html> element has no valid lang attribute

Why it matters. The lang attribute tells search engines and translation tools which language the page is in, and lets screen readers pick the right pronunciation.

How to fix it.
  1. Add lang to the html element, for example <html lang="hr"> or <html lang="en-GB">.
  2. In WordPress the theme prints it from Settings → General → Site Language.

Questions people ask

What is the html lang attribute?

It is the lang attribute on the opening <html> tag, such as <html lang="en">, that declares the language of the whole page. Browsers, screen readers and translation tools read it to handle the text correctly. Parts in another language can carry their own lang, for example a quote marked lang="fr".

Should you use html lang en or en-US?

Use plain en unless the page is written for one country. en-US or en-GB adds a region, which helps spell-checkers and speech engines with spelling and pronunciation, but it is not required. Match the region to how the text is actually written, and use the same code in hreflang if you have regional versions.

How do you add a lang attribute to the html element?

Edit the opening tag at the top of your template so it reads <html lang="en">, using your page's language code. In WordPress the theme prints it from Settings → General → Site Language, so pick the right language there. Most frameworks set it in the root layout or document template.

Is the lang attribute the same as hreflang?

No. lang says what language this page is written in; hreflang lists the other language versions of the page and where they live. A multilingual site needs both: a correct lang on each version, and hreflang links between the versions so search engines can show each searcher the right one.

Filed under Technical SEO. Copy is generated from the same catalogue that scores every report, so what you read here is what the report says.