HTML Language Code

Beginner
8 min read
Updated: Nov 2026
3 examples
191 codes

Definition and Usage

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.

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>

Core HTML Concepts

Terms you will use when declaring language in HTML:

ConceptMeaning in HTML
langGlobal attribute that declares the natural language of an element
ISO 639-1Two-letter language codes such as en, es, ja
BCP 47Language tags that can add region or script, e.g. en-GB, zh-Hans
<html lang>Document-wide default language for the whole page
Nested langOverride on p, span, q, etc. for mixed-language content
hreflangLanguage of a linked resource—not a substitute for content lang
srclangLanguage of a media text track (captions/subtitles)
Country codeNation identifier (US, IN)—combine with language only in BCP 47

Common HTML language codes

LanguageCodeTry it
EnglishenTry it
FrenchfrTry it
SpanishesTry it
GermandeTry it
HindihiTry it
JapanesejaTry it
Chinese (Simplified)zh-HansTry it
ArabicarTry it

How to Use Language Codes in HTML

Declare the page language first, then override only where the language changes.

  1. Pick the primary ISO 639-1 (or BCP 47) code for the page.
  2. Add lang="..." on the <html> start tag.
  3. Keep <meta charset="UTF-8"> early in <head> so multilingual text encodes correctly.
  4. For mixed-language content, wrap the foreign phrase in an element and set a nested lang.
  5. For alternate language pages, use hreflang on links—do not replace content lang.
TaskHTML markup
English page<html lang="en">
US English page<html lang="en-US">
French paragraph<p lang="fr">...</p>
Read in JavaScriptdocument.documentElement.lang

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.

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>
Try It Yourself

How It Works

  1. One root attribute. lang on <html> sets the default for every descendant.
  2. ISO 639-1 value. en is the two-letter code for English.
  3. Inheritance. Children without their own lang inherit this value.
  4. 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>
Try It Yourself

How It Works

  1. Document default stays en on <html>.
  2. Nested lang overrides only that element’s subtree.
  3. Screen readers can switch pronunciation per paragraph.
  4. UTF-8 charset keeps Hindi and accented French text intact.

Example 3 — BCP 47 Language + Region

Add a region when locale matters (spelling, formats, or voice), such as US English.

HTML
<!DOCTYPE html>
<html lang="en-US">
<head>
  <meta charset="UTF-8">
  <title>HTML Document</title>
</head>
<body>
  <h1>English (United States)</h1>
  <p>The lang attribute uses a BCP 47 tag: language + region.</p>
</body>
</html>
Try It Yourself

How It Works

  1. Language first. Lowercase en is the ISO 639-1 primary language.
  2. Region second. Uppercase US is a country/region subtag.
  3. Hyphen separates subtags in BCP 47 (en-US, not en_US in HTML).
  4. Pair with country codes when you also need nation lists—see Country Code.

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.

LanguageISO Code
Abkhazianab
Afaraa
Afrikaansaf
Akanak
Albaniansq
Amharicam
Arabicar
Aragonesean
Armenianhy
Assameseas
Avaricav
Avestanae
Aymaraay
Azerbaijaniaz
Bambarabm
Bashkirba
Basqueeu
Belarusianbe
Bengali (Bangla)bn
Biharibh
Bislamabi
Bosnianbs
Bretonbr
Bulgarianbg
Burmesemy
Catalanca
Chamorroch
Chechence
Chichewa, Chewa, Nyanjany
Chinesezh
Chinese (Simplified)zh-Hans
Chinese (Traditional)zh-Hant
Chuvashcv
Cornishkw
Corsicanco
Creecr
Croatianhr
Czechcs
Danishda
Divehi, Dhivehi, Maldiviandv
Dutchnl
Dzongkhadz
Englishen
Esperantoeo
Estonianet
Eweee
Faroesefo
Fijianfj
Finnishfi
Frenchfr
Fula, Fulah, Pulaar, Pularff
Galiciangl
Gaelic (Scottish)gd
Gaelic (Manx)gv
Georgianka
Germande
Greekel
Greenlandickl
Guaranign
Gujaratigu
Haitian Creoleht
Hausaha
Hebrewhe
Hererohz
Hindihi
Hiri Motuho
Hungarianhu
Icelandicis
Idoio
Igboig
Indonesianid, in
Interlinguaia
Interlingueie
Inuktitutiu
Inupiakik
Irishga
Italianit
Japaneseja
Javanesejv
Kalaallisut, Greenlandickl
Kannadakn
Kanurikr
Kashmiriks
Kazakhkk
Khmerkm
Kikuyuki
Kinyarwanda (Rwanda)rw
Kirundirn
Kyrgyzky
Komikv
Kongokg
Koreanko
Kurdishku
Kwanyamakj
Laolo
Latinla
Latvian (Lettish)lv
Limburgish ( Limburger)li
Lingalaln
Lithuanianlt
Luga-Katangalu
Luganda, Gandalg
Luxembourgishlb
Manxgv
Macedonianmk
Malagasymg
Malayms
Malayalamml
Maltesemt
Maorimi
Marathimr
Marshallesemh
Moldavianmo
Mongolianmn
Nauruna
Navajonv
Ndongang
Northern Ndebelend
Nepaline
Norwegianno
Norwegian bokmålnb
Norwegian nynorsknn
Nuosuii
Occitanoc
Ojibweoj
Old Church Slavonic, Old Bulgariancu
Oriyaor
Oromo (Afaan Oromo)om
Ossetianos
Pālipi
Pashto, Pushtops
Persian (Farsi)fa
Polishpl
Portuguesept
Punjabi (Eastern)pa
Quechuaqu
Romanshrm
Romanianro
Russianru
Samise
Samoansm
Sangosg
Sanskritsa
Serbiansr
Serbo-Croatiansh
Sesothost
Setswanatn
Shonasn
Sichuan Yiii
Sindhisd
Sinhalesesi
Siswatiss
Slovaksk
Sloveniansl
Somaliso
Southern Ndebelenr
Spanishes
Sundanesesu
Swahili (Kiswahili)sw
Swatiss
Swedishsv
Tagalogtl
Tahitianty
Tajiktg
Tamilta
Tatartt
Telugute
Thaith
Tibetanbo
Tigrinyati
Tongato
Tsongats
Turkishtr
Turkmentk
Twitw
Uyghurug
Ukrainianuk
Urduur
Uzbekuz
Vendave
Vietnamesevi
Volapükvo
Wallonwa
Welshcy
Wolofwo
Western Frisianfy
Xhosaxh
Yiddishyi, ji
Yorubayo
Zhuang, Chuangza
Zuluzu

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.

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 Chrome All
Full support
Mozilla Firefox All
Full support
Apple Safari All
Full support
Microsoft Edge All
Full support
Opera All
Full support
Samsung Internet All
Full support
Internet Explorer All
Full support
lang with ISO / BCP 47 codes Universally supported

Bottom line: Always set lang on html. Browser support is not the bottleneck — missing language codes are.

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.

Try language codes in the editor

Change lang="en" on <html> and see how the document language updates.

Open Try It editor →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful