HTML Lang Attribute: What It Does and How to Add It
Declare your page language the right way with the lang attribute: valid codes, honest SEO facts and copy ready fixes for any platform.
Free to use 5 min read Updated Oct 2026
HTML lang attribute: the quick answer
Quick answer: The HTML lang attribute declares the primary language of the page, such as lang="en" for English, so browsers and screen readers treat the text correctly. Our report passes any non-empty value on the html element. Google does not use it to detect language, so it helps accessibility, not rankings.
- Pass: the html tag has a non-empty lang value.
- Fail: it is missing, empty or on another element.
- Fix: add a valid language code to the html tag.
What is the HTML lang attribute?
The lang attribute in HTML is a global attribute that names the natural language of an element's content. On the html root element it sets the document language. The MDN lang attribute reference documents it, and our doctype declaration guide covers the line above it.
Syntax and placement
The value is a BCP 47 language tag: an ISO 639-1 language code such as en, then an optional script subtag (Hans) or region subtag (US), as in zh-Hans.
<!DOCTYPE html>
<html lang="en">Overriding the language for one element
A child element can carry its own value, as WCAG 3.1.2 Language of Parts asks. A French phrase in an English page gets its own span, <span lang="fr">c'est la vie</span>, so screen readers switch voice for those words. An empty lang="" means unknown.
Does the HTML lang attribute help SEO?
For Google, no. It does not use the lang attribute to detect language, and nothing in its documentation makes lang a ranking factor. The payoff is accessibility, the same goal as our image alt text guide.
What Google says about language detection
The Google localized versions documentation, part of Google Search Central, says Google relies on its own algorithms, not hreflang or lang. Hreflang separately lists alternate URLs, so multilingual sites need both.
Who actually reads the attribute
NVDA, JAWS and VoiceOver use the value for screen reader pronunciation. Without it, many read a French page in the default voice, which is why WCAG 3.1.1 Language of Page is Level A. Browsers use it as a hint for the browser translation prompt and spellcheck language, and the CSS :lang() selector can target it.
Audits flag it too. The axe-core rule html-has-lang rates a missing value serious, and the Lighthouse accessibility audit fails its lang check.
How SEO Site Checker tests your HTML lang attribute
Our crawler loads the page in headless Chromium, waits for the load event and reads the lang attribute of the root html element.
The rule: any non-empty value passes. A missing or empty one fails with "This webpage has not language declared".
What passes
A passing page gets the green tick and its code in a badge, but nothing checks that the code is real, so lang="english" passes too.
What fails
Four cases fail: a missing language declaration, an empty lang attribute, lang only on body or a div, or xml:lang alone. A value a script adds after the load event can be missed, and the Content-Language header is not read. The same result feeds the Declared language line in the AI readiness section, which warns when it is missing.
How to add the HTML lang attribute
- Pick the language. Choose the code for the visible text from the table below.
- Edit the opening tag. In the template that prints it, such as header.php, theme.liquid or index.html, add lang="en".
- Match each translation. Print the value from the page's own language, so the Spanish URL outputs es and the German one de, in server-sent HTML.
- Run the report again. Clear the cache, then look for the green tick.
Static HTML pages
Preview the edit in the Online HTML Viewer, then check the live page with View Source. See the charset declaration guide for the neighboring tag.
<!-- Before -->
<html>
<!-- After -->
<html lang="en">Multilingual pages
Use values such as es-MX or fr-CA where audiences differ, and test one translated URL per language.
Set the lang attribute in WordPress, Shopify and JavaScript frameworks
CMS and store builders
In WordPress, set Settings, General, Site Language. Classic themes need language_attributes() in header.php. In Shopify, use lang="{{ request.locale.iso_code }}" in theme.liquid. In Wix and Squarespace, set the site language in settings.
JavaScript frameworks
| Framework | File | Setting |
|---|---|---|
| Next.js App Router | Root layout | html tag with lang="en" |
| React, Vue or Angular | index.html shell | html tag with lang="en" |
| Nuxt | App head config | htmlAttrs: { lang: 'en' } |
Prefer server rendering, because a browser-side document.documentElement.lang can be missed. Our tools for developers cover more template checks.
Common HTML lang attribute mistakes and valid values
| Code | Meaning | When to choose it |
|---|---|---|
| en | English | Default; en-GB or en-US for spelling |
| fr-CA | French, Canada | Canadian French pages |
| de | German | Any German page, -AT or -CH only if wording differs |
| zh-Hans | Chinese, Simplified | Simplified characters |
Slips: en_US should be en-US, "english" should be en, and en-UK should be en-GB.
Arabic, a right to left language, also needs dir="rtl", since lang does not set text direction. A Content-Language HTTP header describes the intended audience rather than the text, so it cannot stand in for lang. The W3C says never to use the meta http-equiv content-language tag, so leave that out.
Our report passes an invalid lang attribute value, so check yours in the IANA language subtag registry. The W3C language declaration guide adds that in XHTML served as text/html, xml:lang must match lang.
How to Fix
The short version, the same steps you see when you click How to Fix in your report.
Why this fails: The opening html tag has no lang value, or the value is empty or sits on another element, so the report shows "This webpage has not language declared". The check reads only the lang attribute of the html element in the rendered page, and without it browsers, screen readers and translation tools have to guess the language.
How to fix it:
- Pick the code for the main language of the visible text, such as en, es or de.
- Edit the template that prints the opening html tag and add lang="en" there, using your own code.
- On multilingual sites, print the value from each page's language so every translation gets its own code.
- Save the file, clear any page cache and reload the page.
<!-- Before -->
<html>
<!-- After -->
<html lang="en">Platform variants for the most common setups:
- WordPress: set Settings, General, Site Language. Block themes then write the attribute themselves, while classic themes need header.php to print
<html <?php language_attributes(); ?>>. - Shopify: use
<html lang="{{ request.locale.iso_code }}">in theme.liquid. - Next.js App Router: return
<html lang="en">from the root layout. - Wix and Squarespace: set the site language in the dashboard settings, then re-test.
- Plain HTML: edit the first tag after the doctype.
Re-test: View the page source and check the first html tag, then run the free SEO report again and look for the green tick with your language code in the badge.
Frequently Asked Questions
What is the purpose of the HTML lang attribute?
Is the lang attribute required on the html element?
What are the valid values for the HTML lang attribute?
How do I fix the html is missing lang attribute error?
Can one page use more than one language?
What is the difference between lang and hreflang?
See how your site scores right now
Paste your address into the free report, then use the How to Fix button on anything that needs work.
Free to use. Results in under a minute for most sites.