An HTML language code is a short tag that names the human language of your markup. You apply it with the global lang attribute—almost always on <html>, and again on nested elements when a phrase is in another language.
What does a language code do in HTML?
It tells browsers, search engines, and assistive technologies which language the content uses. Screen readers pick voices and pronunciation; hyphenation and spell-check follow language rules; crawlers match locale preferences.
Which codes should you use?
Prefer ISO 639-1 two-letter codes such as en, fr, and hi. For regional variants, use BCP 47 tags like en-US or pt-BR (language plus region from HTML country codes).
When should you set lang in HTML?
On every HTML document you publish. Set the primary language on <html>. For multilingual pages, mark foreign quotes, titles, or blocks with their own lang so accessibility checks (WCAG 3.1.1 / 3.1.2) pass.
Baseline · Widely available.
The lang attribute is standard HTML—not deprecated and not experimental. Support is universal; missing markup is the usual problem.
Language code ≠ country code.
en is English. US is a country. Combine them only in BCP 47 form: lang="en-US". Do not put a bare country code in lang.
Always set lang on <html>.
If no ancestor declares a language, the page language is unknown. That hurts screen readers and SEO even when the visible text looks fine.
Syntax
HTML Syntax
syntax.html
<html lang="language-code">...</html>
You can also set lang on any element (for example <p lang="fr">). Nested values override the document default for that subtree only.
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>HTML Document</title>
</head>
<body>
<!-- Content of the HTML document -->
</body>
</html>
Reference
Core HTML Concepts
Terms you will use when declaring language in HTML:
Concept
Meaning in HTML
lang
Global attribute that declares the natural language of an element
ISO 639-1
Two-letter language codes such as en, es, ja
BCP 47
Language tags that can add region or script, e.g. en-GB, zh-Hans
<html lang>
Document-wide default language for the whole page
Nested lang
Override on p, span, q, etc. for mixed-language content
hreflang
Language of a linked resource—not a substitute for content lang
srclang
Language of a media text track (captions/subtitles)
Country code
Nation identifier (US, IN)—combine with language only in BCP 47
For mixed-language content, wrap the foreign phrase in an element and set a nested lang.
For alternate language pages, use hreflang on links—do not replace content lang.
Task
HTML markup
English page
<html lang="en">
US English page
<html lang="en-US">
French paragraph
<p lang="fr">...</p>
Read in JavaScript
document.documentElement.lang
Try it
Live Preview
Change the language code on a sample paragraph. The visible text stays the same; the lang tag updates for study (screen readers would use the new code).
Inspect the sample element—only the language code changes.
Sample element
The quick brown fox jumps over the lazy dog.
lang="en" on the paragraph.
Code
HTML Examples
Short, copy-ready snippets. Use Try It Yourself for a live HTML editor (plain HTML, no CSS required).
Example 1 — Set the Document Language
Put lang="en" on <html> so the whole HTML page defaults to English.
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>English page</title>
</head>
<body>
<h1>Hello</h1>
<p>This document is in English.</p>
</body>
</html>
One root attribute.lang on <html> sets the default for every descendant.
ISO 639-1 value.en is the two-letter code for English.
Inheritance. Children without their own lang inherit this value.
JS check. Read it with document.documentElement.lang.
Example 2 — Mixed Languages on One HTML Page
Override lang on individual blocks when the page contains more than one language.
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Mixed languages</title>
</head>
<body>
<p>This paragraph is English (document default).</p>
<p lang="fr">Ce paragraphe est en français.</p>
<p lang="es">Este párrafo está en español.</p>
<p lang="hi">यह अनुच्छेद हिंदी में है।</p>
</body>
</html>
Language first. Lowercase en is the ISO 639-1 primary language.
Region second. Uppercase US is a country/region subtag.
Hyphen separates subtags in BCP 47 (en-US, not en_US in HTML).
Pair with country codes when you also need nation lists—see Country Code.
Reference
ISO 639-1 Language Code Table
Full HTML language code reference (191 entries). Some rows list legacy or alternate codes separated by commas—prefer the first code for new HTML projects.
Language
ISO Code
Abkhazian
ab
Afar
aa
Afrikaans
af
Akan
ak
Albanian
sq
Amharic
am
Arabic
ar
Aragonese
an
Armenian
hy
Assamese
as
Avaric
av
Avestan
ae
Aymara
ay
Azerbaijani
az
Bambara
bm
Bashkir
ba
Basque
eu
Belarusian
be
Bengali (Bangla)
bn
Bihari
bh
Bislama
bi
Bosnian
bs
Breton
br
Bulgarian
bg
Burmese
my
Catalan
ca
Chamorro
ch
Chechen
ce
Chichewa, Chewa, Nyanja
ny
Chinese
zh
Chinese (Simplified)
zh-Hans
Chinese (Traditional)
zh-Hant
Chuvash
cv
Cornish
kw
Corsican
co
Cree
cr
Croatian
hr
Czech
cs
Danish
da
Divehi, Dhivehi, Maldivian
dv
Dutch
nl
Dzongkha
dz
English
en
Esperanto
eo
Estonian
et
Ewe
ee
Faroese
fo
Fijian
fj
Finnish
fi
French
fr
Fula, Fulah, Pulaar, Pular
ff
Galician
gl
Gaelic (Scottish)
gd
Gaelic (Manx)
gv
Georgian
ka
German
de
Greek
el
Greenlandic
kl
Guarani
gn
Gujarati
gu
Haitian Creole
ht
Hausa
ha
Hebrew
he
Herero
hz
Hindi
hi
Hiri Motu
ho
Hungarian
hu
Icelandic
is
Ido
io
Igbo
ig
Indonesian
id, in
Interlingua
ia
Interlingue
ie
Inuktitut
iu
Inupiak
ik
Irish
ga
Italian
it
Japanese
ja
Javanese
jv
Kalaallisut, Greenlandic
kl
Kannada
kn
Kanuri
kr
Kashmiri
ks
Kazakh
kk
Khmer
km
Kikuyu
ki
Kinyarwanda (Rwanda)
rw
Kirundi
rn
Kyrgyz
ky
Komi
kv
Kongo
kg
Korean
ko
Kurdish
ku
Kwanyama
kj
Lao
lo
Latin
la
Latvian (Lettish)
lv
Limburgish ( Limburger)
li
Lingala
ln
Lithuanian
lt
Luga-Katanga
lu
Luganda, Ganda
lg
Luxembourgish
lb
Manx
gv
Macedonian
mk
Malagasy
mg
Malay
ms
Malayalam
ml
Maltese
mt
Maori
mi
Marathi
mr
Marshallese
mh
Moldavian
mo
Mongolian
mn
Nauru
na
Navajo
nv
Ndonga
ng
Northern Ndebele
nd
Nepali
ne
Norwegian
no
Norwegian bokmål
nb
Norwegian nynorsk
nn
Nuosu
ii
Occitan
oc
Ojibwe
oj
Old Church Slavonic, Old Bulgarian
cu
Oriya
or
Oromo (Afaan Oromo)
om
Ossetian
os
Pāli
pi
Pashto, Pushto
ps
Persian (Farsi)
fa
Polish
pl
Portuguese
pt
Punjabi (Eastern)
pa
Quechua
qu
Romansh
rm
Romanian
ro
Russian
ru
Sami
se
Samoan
sm
Sango
sg
Sanskrit
sa
Serbian
sr
Serbo-Croatian
sh
Sesotho
st
Setswana
tn
Shona
sn
Sichuan Yi
ii
Sindhi
sd
Sinhalese
si
Siswati
ss
Slovak
sk
Slovenian
sl
Somali
so
Southern Ndebele
nr
Spanish
es
Sundanese
su
Swahili (Kiswahili)
sw
Swati
ss
Swedish
sv
Tagalog
tl
Tahitian
ty
Tajik
tg
Tamil
ta
Tatar
tt
Telugu
te
Thai
th
Tibetan
bo
Tigrinya
ti
Tonga
to
Tsonga
ts
Turkish
tr
Turkmen
tk
Twi
tw
Uyghur
ug
Ukrainian
uk
Urdu
ur
Uzbek
uz
Venda
ve
Vietnamese
vi
Volapük
vo
Wallon
wa
Welsh
cy
Wolof
wo
Western Frisian
fy
Xhosa
xh
Yiddish
yi, ji
Yoruba
yo
Zhuang, Chuang
za
Zulu
zu
Edge Cases & Pitfalls
Most HTML language mistakes are missing lang, wrong codes, or confusing language with country.
missing
No lang on <html>
The page language is unknown. Always declare a primary code on the root element.
country
Using a country code alone
lang="US" is invalid as a language. Use en-US or plain en.
mixed
Foreign text without nested lang
Quotes or captions in another language need their own lang so screen readers pronounce them correctly.
legacy
Deprecated alternate codes
Rows like Indonesian may list id, in. Prefer the modern code (id) in new HTML.
hreflang
Confusing lang with hreflang
lang describes content in this document. hreflang describes the language of a linked page.
xml
Relying only on xml:lang
In HTML5, lang is enough. Keep xml:lang only if you still serve XHTML-style markup.
Compatibility
Browser Support
HTML language codes via lang are a browser document feature. They are not a Node.js, Deno, or Bun API.
✓ Baseline · Widely available
lang / language codes
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 with ISO / BCP 47 codesUniversally supported
Bottom line: Always set lang on html. Browser support is not the bottleneck — missing language codes are.
Remember
Key Takeaways
Role: HTML language codes declare content language through lang.
Start on <html>: set an ISO 639-1 or BCP 47 tag for the whole page.
Nest when mixed: override lang on elements that switch language.
Not country alone: use en-US, not US, inside lang.
One line: pick an ISO/BCP 47 code → set <html lang="..."> → nest lang only where the language changes.
Frequently Asked Questions
A short BCP 47 / ISO 639 tag that identifies the human language of HTML content, usually set with the lang attribute. Examples: en for English, fr for French, en-US for US English.
Always set lang on the html element for the whole page. For mixed-language pages, also set lang on nested elements such as p, span, or q that contain another language.
en is generic English. en-US is English plus a United States region tag (BCP 47). Use the more specific form when spelling, date formats, or pronunciation should follow a locale.
No. Language codes (en, fr) identify languages. Country codes (US, FR) identify nations. Combine them in HTML as lang="en-GB" for British English. See the Country Code tutorial for ISO nation lists.
Yes. Search engines use it to match language preferences, and WCAG expects the page language to be programmatically determined. Screen readers use lang for pronunciation.
In HTML5, lang alone is enough. xml:lang mattered more for XHTML. Prefer lang on html and nested elements in modern HTML documents.