The langglobal attribute declares the natural language of an element’s content — or the language users should write in for editable fields. Its value is a single BCP 47 language tag such as en, en-US, or fr.
Always set lang on <html>. Nest another lang when a phrase or block is in a different language so assistive tech can pronounce it correctly (WCAG 3.1.1 / 3.1.2).
Baseline · Widely available.
Not deprecated and not experimental. A core HTML global attribute supported everywhere modern browsers render pages.
Do not leave the page language unknown.
If no ancestor (and no Content-Language cue) sets a language, the language is unknown. That hurts screen readers and SEO — set lang on <html>.
Syntax
HTML Syntax
syntax.html
<element lang="bcp47-tag">
Common forms: language only (en), or language + region (en-GB, pt-BR).
Inspect <html> — it should include lang="en" (or your locale, e.g. en-US).
How It Works
One root tag.lang on <html> sets the default for all descendants.
BCP 47 value. Use en, or be more specific with en-US / en-GB.
Inheritance. Children without their own lang inherit this value.
Accessibility + SEO. Assistive tech and crawlers can detect the page language.
Example 2 — Mixed-Language Content
Override lang on spans or blocks that switch language mid-page.
HTML
<html lang="en">
<body>
<p>The French word for hello is <span lang="fr">bonjour</span>.</p>
<blockquote lang="de">
Alle Menschen sind frei und gleich an Würde und Rechten geboren.
</blockquote>
</body>
</html>
Click to toggle document.documentElement.lang between en and es.
How It Works
Reflects the attribute.document.documentElement.lang maps to <html lang>.
Assign a new tag. Setting the property updates the live attribute.
Keep content in sync. Also swap visible strings/translations when you change language.
Still set HTML first. Prefer a correct initial lang in markup for first paint and no-JS users.
Edge Cases & Pitfalls
Most issues are a missing root lang, wrong tags, or confusing related attributes.
a11y
Always declare the page language
WCAG expects a programmatically determined page language. Start with <html lang="…">.
compare
Not hreflang or srclang
hreflang describes a linked document’s language. srclang is for <track>. lang is for content in this document.
xml
xml:lang must match if both exist
If you also set xml:lang, HTML requires the same value as lang (case-insensitive). xml:lang takes priority when both are present.
empty
Empty vs invalid
lang="" means unknown. A non-BCP-47 string is invalid. Prefer real tags; avoid inventing codes.
legacy
Do not confuse with language on <script>
The old language attribute on scripts is deprecated. Use type / modern module scripts instead — unrelated to page language.
Compatibility
Browser Support
lang is an HTML global attribute in the browser. It is not a Node.js, Deno, or Bun API.
✓ Baseline · Widely available
lang
Supported in all major browsers for decades. Safe and expected on every HTML document for accessibility and internationalization.
100%Global support (approx.)
Google ChromeAll
Full support
Mozilla FirefoxAll
Full support
Apple SafariAll
Full support
Microsoft EdgeAll
Full support
OperaAll
Full support
Samsung InternetAll
Full support
Internet ExplorerAll
Full support
lang global attributeUniversally supported
Bottom line: Always use lang. Browser support is not the bottleneck — missing markup is.
Remember
Key Takeaways
Role: declare content language with a BCP 47 tag.
Start on <html>: then nest overrides for foreign phrases.
Inheritance: children inherit unless they set their own lang.
A11y: required for WCAG page language; mark language changes in content.
One line: set lang on <html>, then override nested parts so every language is announced correctly.
Frequently Asked Questions
It declares the natural language of an element’s content (or the language the user should write in for editable content) using a BCP 47 language tag such as en, en-US, or fr.
Always set it on the html element for the whole page. Add lang again on nested elements when a phrase or section is in a different language.
Yes for WCAG: the page language must be programmatically determined (3.1.1), and parts in other languages should be marked too (3.1.2). Screen readers use lang for pronunciation.
lang="" means the language is unknown. A value that is not a valid BCP 47 tag is treated as invalid. Prefer a real tag like en or es.
If an element has no lang, it inherits from its ancestors. If nothing sets a language, Content-Language (HTTP or meta) may apply; otherwise the language is unknown.
lang describes content language in the document. hreflang describes the language of a linked resource. srclang is the language of a media text track.