Missing lang attribute on the HTML tag: why it matters and how to fix it

A missing lang attribute means the page's opening <html> tag does not declare the language of the content, as in <html lang="en">. Screen readers use it to choose the right voice and pronunciation, and browsers use it for translation prompts, hyphenation and spell-checking. In WordPress, the fix is making sure the theme prints <html <?php language_attributes(); ?>>, which outputs the site language automatically.

It is mainly an accessibility fix. Google has said it works out a page's language from its visible content rather than the lang attribute, so do not expect ranking changes. It is still a basic accessibility requirement and takes minutes to fix.

What it looks like in the HTML

Before

html
<!DOCTYPE html>
<html>
<head>

After

html
<!DOCTYPE html>
<html lang="en-US">
<head>

Why it matters

A screen reader reading an English page with a French voice, or a Spanish page with English pronunciation rules, is close to unintelligible. The lang attribute tells assistive technology which language rules to apply from the first word. It is part of the Web Content Accessibility Guidelines (success criterion 3.1.1, Language of Page), so accessibility audits check for it too.

Browsers use it as well: to decide whether to offer translation, to hyphenate text correctly with CSS, and to pick fonts for some scripts. Search engines have other ways to detect language, so the SEO effect is small. For sites in several languages, use hreflang annotations to tell search engines about alternate versions; the lang attribute does not do that job.

Why WordPress pages are missing it

WordPress provides the value through the language_attributes() function, which prints lang="en-US" (or whatever your site language is) plus the text direction for right-to-left languages. Standard themes call it in the opening <html> tag. When it is missing:

  • The theme hardcodes <html>. Custom and older themes sometimes write the tag without the function.
  • A custom template prints its own document. Landing page templates, maintenance pages or static HTML files uploaded to the server.
  • A caching or minification step strips attributes from the <html> tag. Rare, but it happens with aggressive HTML minifiers.

How to fix it in WordPress

  1. Check the site language. Under Settings → General, make sure Site Language is set correctly. This is what language_attributes() prints.
  2. Find the <html> tag. In a classic theme it is in header.php. In a child theme, copy header.php from the parent if you need to change it.
  3. Use the WordPress function. Replace a bare <html> with:
php
<html <?php language_attributes(); ?>>

This prints the correct lang, and dir="rtl" for right-to-left languages, and it updates automatically if you change the site language. 4. Fix other templates. If only some pages are affected, check their templates or the plugin that generates them. 5. Mark language changes inside the page. For a quote or phrase in another language, add lang to that element, for example <blockquote lang="fr">.

Block themes print the <html> element through WordPress core, so they get the attribute automatically. Hydrogen SEO does not change the <html> tag.

How to check the fix

View source and look at the first few lines: the <html> tag should carry lang with a valid code such as en, en-US or de-DE. In the browser console, document.documentElement.lang returns the value. Purge any cache and rerun the free SEO audit.

Common questions

Does the lang attribute affect SEO?

Very little. Google has said it detects language from the visible content. The attribute's main value is accessibility and correct browser behavior.

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

Both are valid. A region subtag like en-US or en-GB adds detail for pronunciation and spelling; WordPress uses your Site Language setting.

Is lang the same as hreflang?

No. The lang attribute declares the language of the current page. Hreflang tells search engines about alternate language or regional versions of the page.