Missing HTML lang Attribute: How to Fix It

The lang attribute tells browsers, screen readers and search engines what language a page is in. How to set it correctly, including multilingual sites.

Updated

The short answer

A missing HTML lang attribute means the <html> element does not say what language the page is written in. Screen readers then guess, and often read the page aloud with the wrong voice and pronunciation. Browsers cannot offer the right translation, and Lighthouse reports <html> element does not have a [lang] attribute. The fix is one attribute in your base template, such as <html lang="en">.

What the lang attribute is

The attribute sits on the root element and holds a language tag:

html
<html lang="en">

The value is a BCP 47 language tag: a language code, optionally followed by a region or script, such as en, en-GB, de, pt-BR or zh-Hans. A page without it looks like this:

html
<!doctype html>
<html>
  <head>
    <title>Trail running shoes</title>
  </head>
</html>

You can also set lang on any element inside the page when one passage is in another language, such as a quote:

html
<p>Their motto is <span lang="fr">savoir faire</span>.</p>

Why it matters

  • Screen readers pick the voice from it. Without a lang attribute, a screen reader uses its default language, so a German page can be read with English pronunciation and become hard to understand.
  • It is a basic accessibility requirement. WCAG success criterion 3.1.1, Language of Page, is Level A, the minimum level. Lighthouse and other accessibility checkers fail pages without it.
  • Browsers use it for translation, spellcheck and hyphenation. Translation prompts, spellchecking in form fields and CSS hyphens: auto all rely on the declared language.
  • It is not a ranking signal for Google. Google detects a page's language from its visible text and says it ignores the lang attribute. Use hreflang annotations to tell search engines about language versions of a page.

Why it happens

  • Hand written or old templates where the <html> tag was typed without attributes.
  • Static exports and landing page tools that output their own minimal HTML shell.
  • Custom templates that skip the theme header, so the attribute the theme sets never prints.
  • Multilingual sites with a hardcoded value, where every language version says lang="en". That is not missing, but it is wrong.
  • Invalid values, such as lang="english" or lang="en_US" with an underscore, which tools report as not valid.

How to find pages without a lang attribute

  1. Check a single page. View the source and look at the <html> tag, or run document.documentElement.lang in the browser console. An empty string means it is missing.
  2. Run Lighthouse. The accessibility audit flags <html> element does not have a [lang] attribute when it is missing, and <html> element does not have a valid value for its [lang] attribute when the value is wrong.
  3. Check every page. UpCrawler flags Missing html lang on any page whose <html> element has no lang attribute. Because the attribute comes from the base template, the flagged pages point straight at the template that needs it.

How to fix it

  1. Set lang on the <html> element of the base template, so every page inherits it.
  2. Use a valid language tag. A hyphen, not an underscore: en-GB, not en_GB. Add a region only when the content really differs by region.
  3. Set it per language on multilingual sites, from the same locale value that picks the translations, so the attribute always matches the text.
  4. Mark passages in another language with lang on the element that contains them.

Set it in the root layout. For a single language site:

tsx
export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en">
      <body>{children}</body>
    </html>
  )
}

For a multilingual site, put the root layout under a [lang] segment and read the locale from params:

tsx
export default async function RootLayout({ children, params }: {
  children: React.ReactNode;
  params: Promise<{ lang: string }>;
}) {
  const { lang } = await params
  return (
    <html lang={lang}>
      <body>{children}</body>
    </html>
  )
}

Classic themes print the attribute in header.php with a core function that reads the Site Language setting under Settings, then General:

php
<html <?php language_attributes(); ?>>

If the tag in your theme is a bare <html>, replace it with the line above, ideally in a child theme. Block themes get it from WordPress core. Multilingual plugins such as WPML and Polylang switch the value per language through the same function, so avoid hardcoding it.

The attribute belongs on the <html> tag in layout/theme.liquid. Current themes set it from the visitor's locale:

liquid
<html lang="{{ request.locale.iso_code }}">

If a page is flagged, check alternate layouts in the layout folder, such as a custom landing page layout, and add the attribute to each one.

Fix with AI

Let AI fix it, page by page.

Paste this prompt into AI with your project open. In UpCrawler, every affected page comes with a prompt like this, already filled in with its URL.

Prompt

Set lang on the <html> element in the root layout, resolved per locale on multilingual routes rather than hardcoded.

Frequently asked questions

Does the html lang attribute affect SEO?

Not for Google, which detects language from the page text and ignores the attribute. It still matters for accessibility, browser translation and accessibility audits, so set it on every page. For language versions in search, use hreflang.

What is the difference between lang and hreflang?

lang describes the language of the page you are on, for browsers and assistive technology. hreflang is a link annotation that tells search engines which other URLs are the same page in another language or region.

Should I use en or en-US?

Use en unless the content is written for one region. Add the region, as in en-US or en-GB, when spelling, prices or terms differ by country and you serve separate versions for each.

How do I fix "html element does not have a lang attribute" in Lighthouse?

Add lang with a valid language code to the <html> tag in your base template, such as <html lang="en">, then run Lighthouse again. If it still fails, the page is rendered by a different template or layout.

Found this useful?

Share it with whoever runs your site’s SEO.

Related issues

All SEO issues
Ready when you are!Crawly, the UpCrawler mascot

Catch issues like this on every page.

UpCrawler crawls your whole site, groups affected pages by template and hands you the fix for your platform.

14 days freeNo cardNothing to install