How to Fix a Missing or Invalid Page Language (html lang)

This check fails when your page's <html> element has no lang attribute, an empty one, or a value that isn't a valid language code, or when any other element on the page uses an invalid lang value. By the end of this guide, every page will declare a correct BCP 47 language code such as en or en-US, and any foreign-language passages will be marked up correctly.

By Updated ⏱ 15 minutes🎯 Beginner● Medium impactAccessibility
Illustration: Page language declared fix guide
ACCESSIBILITY · FIX GUIDE Page language declared IMPACTEFFORT TIME15 minutes LEVELBeginner

Why it matters

Screen readers such as NVDA, JAWS and VoiceOver use the lang attribute to choose a voice and pronunciation rules. Without it, the reader falls back to the user's default language, so an English page can be read with French phonetics and become hard to understand. Browsers also use it for automatic translation prompts, hyphenation and spell-check, and search engines and AI crawlers treat it as one language signal among several.

2 Language of Parts for inline lang values), so a missing declaration is a baseline accessibility failure.

✕Before<html> or <html lang="english"> or<html lang="en_US">✓After<html lang="en-US">

What you need

Access to your site's theme, template or CMS settings
The primary language (and region, if relevant) of your content
A browser with developer tools (Chrome, Edge or Firefox)

Step-by-step fix

1

Check what your page currently declares

Open the page, press Ctrl+U (Cmd+Option+U on Mac) to view source, and look at the opening <html> tag. Note whether lang is missing, empty (lang=""), or uses an invalid value. Then search the source (Ctrl+F) for lang= to find any other elements with their own lang attribute, because the audit validates those too.

Pro tip: View the rendered DOM in DevTools (Elements panel) as well. A JavaScript framework can change the lang attribute after load, so the source and the live page may differ.
2

Pick a valid BCP 47 language code

The value must start with a real ISO 639 language subtag, optionally followed by a hyphen and a region. Valid examples:

  • en, en-US, en-GB
  • fr, fr-CA
  • de, es-MX, pt-BR, zh-Hans

Invalid examples that fail the check: english, EN_us, en_US (underscore instead of hyphen), us, or an empty string. Use the language your main content is written in, not the language of your audience or server location.

Pro tip: If you are unsure whether to add a region, plain en or fr is always valid. Add a region only when spelling or vocabulary is region-specific.
3

Add the lang attribute to the <html> element

For static sites or hand-coded templates, edit the shared layout or header file so every page gets the attribute on the root <html> tag. Putting lang on <body> or a wrapper <div> does not satisfy this check; it has to be on <html>. If you have one template per language, set the matching code in each.

html
<!DOCTYPE html>
<html lang="en-US">
<head>
  <meta charset="utf-8">
  <title>Example Co</title>
</head>
Pro tip: If your pages also include xml:lang (common in older XHTML templates), set it to the same value as lang or remove it. A mismatch is a separate accessibility error.
4

Set it through your CMS or framework

Most platforms generate the <html> tag for you, so change the setting instead of hard-coding it. In WordPress go to Settings → General → Site Language. liquid should output the store locale dynamically.

js App Router, set it in the root layout as shown below. See the platform notes for other systems.

javascript
// app/layout.tsx
export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en">
      <body>{children}</body>
    </html>
  );
}
Pro tip: For multilingual Next.js sites, read the locale from the route segment (e.g. app/[lang]/layout.tsx) and pass it into <html lang={params.lang}> so each language version is labeled correctly.
5

Fix lang values on inline foreign-language content

When a passage, quote or button is in a different language from the page, wrap it with a lang attribute so screen readers switch voice for that part. Every such value must also be a valid code. Language switcher links are a common source of errors: label each link with its own language.

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

<nav aria-label="Language">
  <a href="https://example.com/en/" lang="en">English</a>
  <a href="https://example.com/de/" lang="de">Deutsch</a>
  <a href="https://example.com/es/" lang="es">Español</a>
</nav>
Pro tip: Search your theme and page builder content for lang="" and remove empty attributes. An empty lang on an inner element fails validation.
6

Clear caches and re-test the page

Purge your CMS, plugin and CDN caches so the updated HTML is served. Reload the page, view the source again, and confirm the <html> tag shows the expected value. Then run your audit again, or run axe DevTools or Lighthouse (Accessibility category) in Chrome DevTools, and confirm the html-has-lang, html-lang-valid and valid-lang checks pass.

text
curl -s https://example.com/ | grep -o '<html[^>]*>'
Pro tip: Test at least one page from each template type (home, article, product, checkout). A custom template sometimes bypasses the main layout file.

Platform-specific notes

WordPress

Go to Settings → General → Site Language and save. Themes that call language_attributes() in header.php then output lang automatically (e.g. lang="en-US"). If the attribute is still missing, the theme's header.php has a hard-coded <html> tag; change it to <html <?php language_attributes(); ?>>, ideally in a child theme. With WPML or Polylang, each translation gets its own code.

Shopify

Open Online Store → Themes → ⋯ → Edit code → layout/theme.liquid and make sure the tag reads <html lang="{{ request.locale.iso_code }}">. Online Store 2.0 themes such as Dawn already do this; older or custom themes may hard-code it or omit it. Check checkout and any alternate layout files too.

Next.js

In the App Router, set lang on <html> in app/layout.tsx. In the Pages Router, use <Html lang="en"> in pages/_document.tsx, or configure i18n.locales and i18n.defaultLocale in next.config.js, which makes Next.js set lang per locale automatically.

Wix

Wix generates the <html> tag itself. Set the language under Settings → Language & Region (site language). With Wix Multilingual, each language version gets its own lang value. You cannot edit the <html> tag directly.

Webflow

Webflow outputs lang from the site's primary locale. Set it in Site settings → Localization (primary locale). Secondary locales receive their own lang value on their localized pages. Avoid trying to inject lang via custom code; it won't change the root tag reliably.

Check that it worked

✅ How to verify

  • View source or run curl -s https://example.com/ | grep -o '<html[^>]*>' and confirm a valid code like lang="en" or lang="en-US".
  • Run Lighthouse (Chrome DevTools → Lighthouse → Accessibility) and confirm '<html> element has a [lang] attribute' and 'has a valid value for its [lang] attribute' pass.
  • Use the axe DevTools browser extension to confirm no html-has-lang, html-lang-valid or valid-lang issues remain, including on inline elements.
  • Listen to the page with VoiceOver (Cmd+F5 on Mac) or NVDA and confirm it reads with the correct accent and switches voice for marked-up foreign phrases.

⚠️ Common mistakes

  • Using an underscore or a full language name, such as en_US or english, instead of a hyphenated BCP 47 code like en-US.
  • Putting lang on <body> or a wrapper <div> rather than on the <html> element.
  • Hard-coding lang="en" in a shared template on a multilingual site, so German and Spanish pages are announced as English.
  • Leaving empty lang="" attributes on inner elements created by page builders or translation plugins, which fails validation.

Is this still an issue on your site? Run a free audit — ZORO checks this and 294 other SEO, AI-visibility, accessibility and security signals, with fixes for your platform.

Check my site free

FAQ

Should I use lang="en" or lang="en-US"?

Both are valid and pass the check. Use en if your content isn't region-specific; use en-US or en-GB if spelling and vocabulary follow one region. Screen readers handle both.

Does the html lang attribute affect SEO?

Google says it mostly ignores lang for determining page language and relies on the content itself, and uses hreflang for alternate versions. Bing and other engines, browsers and translation tools do use it, and it's required for accessibility, so set it regardless.

Is lang the same as hreflang?

No. lang on <html> tells software what language the current page is written in. hreflang link tags tell search engines which alternate URLs exist for other languages or regions. Multilingual sites need both.

What lang should I use for a page with mixed languages?

Set the <html> lang to the language of most of the content, then add lang to the elements containing other languages, such as <blockquote lang="es"> or <span lang="ja">.