Skip to content

HTML lang attribute and SEO: what it does and what it doesn't

Google says it ignores the HTML lang attribute for language detection. Here is what lang does control, how it differs from hreflang, and how to set it.

By Crawlito · 8 min read

In short

  • Google documents that it detects a page's language from its visible text and does not use the HTML lang attribute or hreflang for that.
  • The lang attribute tells browsers and assistive technology which language the text is in, and WCAG 2.2 success criterion 3.1.1 (Level A) requires the page's default language to be programmatically determinable.
  • The lang value must be a valid BCP 47 language tag such as en, en-GB, es-419 or zh-Hant, or the empty string, which means the language is unknown.
  • The meta http-equiv content-language pragma is non-conforming in the HTML standard, and the HTTP Content-Language header describes the intended audience, not the language of the text.
  • Hreflang links equivalent pages for different languages or regions; it does not replace lang, and lang does not replace hreflang.
On this page

Google Search does not use the HTML lang attribute: its documentation says it determines a page's language from the visible content and lists lang among the attributes it does not support. You should still set it correctly, because browsers and screen readers use it, and WCAG requires it. A missing or invalid lang warning in an audit tool is an accessibility and correctness fix, not a Google Search setting.

This post separates three things that often get mixed up in audits: the lang attribute, the Content-Language header or meta tag, and hreflang. For the hreflang side in depth, see the hreflang audit guide. For testing whole language editions, see multilingual AI readiness.

What Google says about the lang attribute

Google is unusually direct on this point, in three separate pages:

The practical consequence for Google is that the text decides. Google's multilingual guide recommends one language for the content and navigation of each page and advises against side-by-side translations. A page whose lang="fr" wraps an English body is read as English. A correct lang value cannot rescue a page where only the menu is translated.

Hreflang still has a job in Google Search, but a different one: Google lists hreflang annotations (in HTML tags, HTTP headers or sitemaps) among the signals for which locale a page targets, and uses them to show users the right language or regional version. That is about choosing between equivalent URLs, not reading the language of one page.

What about Bing and AI search tools?

We could not find current Microsoft Bing documentation that says how Bing treats lang, and an older Bing Webmaster blog post on country and language signals returns a 404 at the time of writing. Treat any claim that Bing depends on lang as unverified.

The AI search operators (OpenAI, Anthropic, Perplexity) do not document whether their crawlers read lang at all. What is safe to say: a page whose visible text is clearly in one language gives every system the same evidence, whatever it reads in the markup.

What lang actually controls

The HTML standard defines lang as the primary language of an element's contents and of its text attributes, such as alt and title. User agents may use it to choose fonts, pronunciations, dictionaries for spell-checking, and the interface of form controls such as date pickers. The CSS :lang() selector also matches on it.

The most visible user of lang is assistive technology. W3C's understanding document for WCAG 2.2 success criterion 3.1.1, Language of Page, explains that a declared language lets screen readers load the correct pronunciation rules and lets visual browsers display characters and scripts correctly. Criterion 3.1.1 is Level A, the lowest conformance level: the default human language of each page must be programmatically determinable, and setting lang on the html element (technique H57) is a sufficient way to meet it.

That is why accessibility checkers flag it. The axe-core rule set, for example, has html-has-lang ("<html> element must have a lang attribute") and html-lang-valid, which checks that the value is valid.

lang vs Content-Language vs hreflang

These three are declared in different places and answer different questions.

MechanismWhere it livesWhat it declaresStatus
lang attribute<html> and any elementThe language of that text, for processing and displayStandard, recommended on every page
Content-Language HTTP headerResponse headersThe intended audience of the document, can list several languagesValid HTTP metadata, not a substitute for lang
<meta http-equiv="content-language"><head>Sets a fallback "pragma-set default language"Non-conforming in the HTML standard
hreflang<link> tags, HTTP Link headers or sitemapsWhich other URLs are language or regional equivalentsUsed by Google for locale targeting

A few details matter here:

  • The meta pragma is obsolete. The HTML standard's pragma section marks http-equiv="content-language" as non-conforming and says authors are encouraged to use the lang attribute instead. If its value contains a comma, the pragma is ignored; if it has several space-separated tokens, only the first counts.
  • The HTTP header is about audience. W3C's internationalization article on HTTP and the lang attribute describes Content-Language as metadata about the intended audience, which is why it allows a comma-separated list. A bilingual page can legitimately send Content-Language: en, fr, but its text still needs lang markup.
  • Precedence. The HTML standard's algorithm uses the element's own lang, then its ancestors' lang, then the meta pragma, and only then language information from the higher-level protocol, such as HTTP. If there is nothing, or the protocol reports several languages, the language is unknown. In practice, a lang on <html> settles it.
  • hreflang codes are stricter. Google supports only ISO 639-1 language codes, optionally followed by an ISO 3166-1 Alpha 2 region code, plus ISO 15924 script variants such as zh-Hant. lang accepts the full BCP 47 grammar. So es-419 (Latin American Spanish) is a valid lang value, but Google's localized versions page names it as a code it does not support in hreflang.

Valid lang values and common mistakes

The HTML standard requires the value to be a valid BCP 47 language tag or the empty string. An empty string explicitly means the language is unknown. An unrecognized tag is not silently corrected: the standard treats lang="xyzzy" as an unknown language with the tag "xyzzy", so the CSS selector :lang(xyzzy) matches it while :lang(en) does not.

W3C's guide to choosing a language tag gives one rule above the others: keep the tag as short as possible. Use the primary language subtag alone unless a region or script adds information you need.

ValueMeaningVerdict
enEnglishGood default
en-GBEnglish as used in the United KingdomGood when spelling differs, for example for spell-checking
es-419Spanish for Latin AmericaValid BCP 47
zh-HantChinese in Traditional scriptValid, script subtag carries real information
pt-BRPortuguese as used in BrazilValid
en_USUnderscore instead of hyphenInvalid, a locale format from software, not BCP 47
ukUkrainian, not the United KingdomValid but often wrong
englishA language nameInvalid
en-UKRegion code that is not the ISO code for the UKNot what you meant, use en-GB

The same mistake matters in hreflang: Google says UK in hreflang annotations has no effect, because the ISO region code is GB. Primary language subtags are written in lower case and region subtags in upper case by convention, though W3C notes that case does not matter for HTML language markup. Look up subtags in the IANA Language Subtag Registry rather than guessing.

Two more mistakes show up in templates:

  1. A hard-coded default. Many themes ship with <html lang="en"> and nobody changes it for the French edition. Generate the value from the locale of the content record, not from the site default.
  2. Mixed-language blocks with no markup. A Spanish page that quotes an English product name needs nothing, but a full English paragraph inside it should carry its own lang. WCAG covers this in criterion 3.1.2, Language of Parts (Level AA).
html
<!doctype html>
<html lang="es">
<head>
  <meta charset="utf-8">
  <title>Guía de envíos</title>
  <link rel="alternate" hreflang="es" href="https://example.com/es/envios/">
  <link rel="alternate" hreflang="en" href="https://example.com/en/shipping/">
</head>
<body>
  <p>Enviamos a toda la Unión Europea.</p>
  <blockquote lang="en">
    <p>Orders ship within two business days.</p>
  </blockquote>
</body>
</html>

For right-to-left languages, lang does not set text direction. W3C's article on structural markup and right-to-left text says not to assume language declarations indicate direction, and to add dir="rtl" to the html tag when the whole document is right-to-left, alongside lang="ar" or lang="he".

How to check the lang attribute on a page

Check the HTML the server sends, not only what the browser shows after scripts run. Some client-side translation tools rewrite lang after load, which is a different situation, covered in JavaScript translation widgets.

bash
curl -sS https://example.com/es/envios/ -o page.html
grep -io '<html[^>]*>' page.html
curl -sSI https://example.com/es/envios/ | grep -i '^content-language'
grep -io '<meta[^>]*content-language[^>]*>' page.html

Then compare the results with the visible text:

  1. Is there a lang on <html>? If not, add it in the base layout.
  2. Is the value valid BCP 47? Look for underscores, language names and country codes used as language codes.
  3. Does it match the body? A French article with lang="en" is a template bug. Fix the template variable, then spot-check one page per locale.
  4. Is there an obsolete meta pragma? Remove <meta http-equiv="content-language"> and rely on lang.
  5. Do hreflang and lang agree? The page's own hreflang entry should name the same language as its lang, even if the formats differ slightly (es-419 vs es).

If the server negotiates language from the Accept-Language request header, test with and without it, because the lang you see may depend on your browser's settings. The Accept-Language redirects guide explains why that pattern causes trouble for crawlers. Encoding problems are a separate issue: a wrong charset garbles the text even when lang is right, as covered in content type and encoding errors.

Frequently asked questions

Does a missing lang attribute hurt Google rankings?

Google lists lang among the attributes it does not support and says it detects language from the page's text, so adding lang is not a Google Search change. It does affect accessibility: WCAG 2.2 criterion 3.1.1 requires the page language to be programmatically determinable.

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

Use en unless the regional variant matters, for example for spelling. W3C recommends keeping language tags as short as possible.

Can lang replace hreflang?

No. lang declares the language of the text on one page, while hreflang tells Google which other URLs are equivalent pages for other languages or regions.

Is the Content-Language meta tag still valid?

No. The HTML standard marks <meta http-equiv="content-language"> as non-conforming and encourages authors to use lang instead. The HTTP Content-Language header remains valid as audience metadata.

Does lang set right-to-left text direction?

No. Use the dir attribute, for example <html lang="ar" dir="rtl">.

Check your page's language markup

After fixing the template, run the commands above on one page per locale, then use the free check on an important translated page to confirm crawlers can fetch it at all. For a multilingual site with many templates, an audit reviews the site with evidence and prioritized fixes.

Filed under Structure and schema. Topics: html, international-seo, hreflang, accessibility, google