How to Fix a Missing HTML lang Attribute on Every Page

Your audit flagged pages whose <html> element has no lang attribute, or an empty one, so the page never declares its language. By the end of this guide, every template on your site will output a valid language code such as lang="en" or lang="de-AT", and you will have confirmed it across all crawled URLs.

By Updated ⏱ 15 minutes🎯 Beginner● Low impactOn-Page
Illustration: HTML lang attribute fix guide
ON-PAGE · FIX GUIDE HTML lang attribute IMPACTEFFORT TIME15 minutes LEVELBeginner

Why it matters

Screen readers use the lang attribute to choose the right pronunciation rules. 1 (Language of Page). Browsers use it to decide whether to offer translation, to choose hyphenation rules for CSS hyphens:auto, and to pick fonts for CJK text.

Google says it mostly detects language from the visible text, so the ranking effect is small. A correct declaration still removes ambiguity for other search engines, AI crawlers and translation tools. The fix is a one-line template change.

✕Before<!DOCTYPEhtml><html><head><title>Example Co |Pricing</title>✓After<!DOCTYPE html><htmllang="en"><head><title>Example Co |Pricing</title>

What you need

Access to your site's main HTML template, theme files or CMS settings
The language (and optional region) each page is written in
A browser with DevTools, or a site crawler such as Screaming Frog

Step-by-step fix

1

Find every page missing the attribute

The audit checks each crawled page, so a single template without lang can fail many URLs at once. Open a flagged URL, press Ctrl+U (Cmd+Option+U on Mac) and look at the opening <html> tag. You can also run the snippet below in the DevTools Console.

It returns an empty string or null when the attribute is missing. In a crawler, set up a custom extraction for the lang attribute on the html element, then sort by empty values to see which templates are affected.

javascript
document.documentElement.getAttribute('lang')
Pro tip: Group the failing URLs by template, such as blog posts, landing pages and error pages. You usually fix one file per group, not one page at a time.
2

Choose the correct BCP 47 language code

Use a valid BCP 47 tag that matches the language of the page's main content. Use a plain language code such as en, fr or ja when you serve one version of the language. Add a region only when you publish regional variants, for example en-GB and en-US, or pt-BR and pt-PT.

Write the language part in lowercase and the region part in uppercase. Do not use underscores (en_US) or invented values like "english".

html
<html lang="en">      <!-- English -->
<html lang="en-GB">   <!-- British English -->
<html lang="de-AT">   <!-- German, Austria -->
<html lang="zh-Hant"> <!-- Chinese, Traditional script -->
Pro tip: Use the same codes you use in your hreflang tags so the two declarations never contradict each other.
3

Add lang to the root html element in your template

Edit the layout or header file that outputs the opening <html> tag, which is shared by every page using that template. Put the attribute on the <html> element itself. Putting it on <body> or a wrapper <div> does not count as the page language.

html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Example Co</title>
</head>
Pro tip: Keep the attribute in the server-rendered HTML. A lang added by JavaScript after load may not be seen by crawlers that do not render scripts.
4

Make lang dynamic on multilingual sites

If one template serves several languages, output the code from the active locale instead of hardcoding it. Otherwise your Spanish pages will declare lang="en". Pull the value from your CMS, translation plugin or routing layer.

In PHP, for example, it would look like the snippet below.

php
<html lang="<?php echo htmlspecialchars($currentLocale, ENT_QUOTES); ?>">
Pro tip: Spot-check one URL per language after deploying. Translation plugins sometimes keep the default locale on archive or search pages.
5

Fix the templates that live outside your main theme

Pages that do not use your main layout are the usual reason a site still fails after the theme is fixed. Check each of these and add lang wherever an <html> tag is generated:

  • Custom 404 and 500 error pages
  • Standalone landing pages from page builders
  • Maintenance and coming-soon pages
  • Static HTML files in /public or the web root
  • Legacy microsites served on the same domain
Pro tip: Search the codebase for opening html tags that have no lang attribute. On Linux or macOS, run: grep -rn "<html" . | grep -v "lang="
6

Mark inline passages in other languages

This step is optional and does not affect the audit check. If part of a page is in a different language, such as a German quote on an English page, wrap that passage in an element with its own lang. Screen readers will then switch pronunciation for just that passage.

html
<p>Our motto is <span lang="de">Vorsprung durch Klarheit</span>.</p>
7

Deploy, clear caches and re-check

Publish the changes, then purge your CDN and page cache so crawlers get the new HTML. Fetch a few previously failing URLs with curl and confirm the attribute appears in the raw response. Finally, re-run the audit so every crawled page is tested again.

text
curl -s https://www.example.com/pricing | grep -o '<html[^>]*>'
Pro tip: Test at least one URL from each template group you found in step 1, not just the homepage.

Platform-specific notes

WordPress

Go to Settings → General → Site Language. Block themes and well-coded classic themes output the lang attribute through language_attributes(). If a classic theme still fails, open header.php and change the opening tag to <html <?php language_attributes(); ?>>. Make that edit in a child theme so updates don't overwrite it. WPML and Polylang set the attribute per language automatically.

Shopify

Go to Online Store → Themes → … → Edit code and open layout/theme.liquid. Dawn and other current themes use <html lang="{{ request.locale.iso_code }}">, which follows the store's active language. If your theme hardcodes a value or has none, replace the tag with that line. Check any other files in /layout as well, such as password.liquid.

Next.js

With the App Router, set <html lang="en"> in app/layout.tsx. For multiple languages, use an app/[lang]/layout.tsx and output lang={params.lang}. In Next.js 15 and later, params is a Promise, so await it first. With the Pages Router, add <Html lang="en"> in pages/_document.tsx, or configure i18n.locales in next.config.js so Next sets lang for you.

Wix

Wix generates the lang attribute from the site language, so you cannot edit the html tag directly. Check the language under Settings → Language & Region. For translated sites, set up Wix Multilingual so each language version outputs its own code.

Webflow

Go to Site settings → Localization and set the primary locale. Webflow outputs it as the lang attribute. Each secondary locale added through Webflow Localization gets its own lang value. Static HTML exports keep the value that was set when you exported.

Check that it worked

✅ How to verify

  • In DevTools Console on several formerly failing URLs, document.documentElement.lang returns the expected code, not an empty string.
  • Run curl -s URL | grep -o '<html[^>]*>' and confirm lang appears in the raw server HTML, not only after JavaScript runs.
  • Run Lighthouse (DevTools → Lighthouse → Accessibility) and confirm the audit '<html> element has a [lang] attribute' passes, along with 'has a valid value for its [lang] attribute'.
  • Re-run the site audit and confirm the HTML lang attribute check reports 0 failing pages.

⚠️ Common mistakes

  • Hardcoding lang="en" in a shared template on a multilingual site, so every translated page declares the wrong language.
  • Using invalid values such as en_US, english or EN-us instead of a valid BCP 47 tag like en-US.
  • Fixing the main theme but forgetting error pages, landing-page builder templates and static files, which keep failing the check.
  • Putting lang on <body> or a wrapper div instead of the <html> element.

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

Does the HTML lang attribute affect Google rankings?

Not directly. Google has said it detects page language from the visible content and largely ignores the lang attribute. Hreflang is the signal Google uses for alternate language versions. The attribute still matters for accessibility, browser translation prompts and other search engines and tools that read it.

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

Use lang="en" if you publish one English version for everyone. Use a regional code like en-US or en-GB only when you publish separate regional variants, and match the codes in your hreflang tags.

Is lang the same as hreflang?

No. The lang attribute declares the language of the current page. Hreflang link tags or sitemap entries point to alternate versions of the page in other languages or regions. Multilingual sites should use both, with matching codes.

What if my page mixes two languages?

Set the html lang to the language of most of the content. Then wrap passages in the other language in an element with its own lang attribute, such as <span lang="fr">.