Country & Language Codes

Language codes and country codes are used together in language tags to identify the language of HTML content and, when necessary, a regional variation of that language.

The HTML lang attribute accepts language tags such as en, en-US, fr, and fr-CA. Correct language information helps browsers, search engines, translation software, and assistive technologies interpret webpage content.

Language Tags

HTML uses language tags to identify the human language of a document or part of a document. A basic language tag commonly begins with an ISO 639 language code.

en
fr
de
es
ja

A language tag can also include additional subtags. A two-letter region subtag based on an ISO 3166-1 country code can distinguish regional language variations.

en-US
en-GB
fr-CA
pt-BR

The language subtag is conventionally written in lowercase and the two-letter region subtag in uppercase, with the subtags separated by a hyphen.

HTML lang Attribute

The lang global attribute specifies the language of an HTML element and its contents. The primary language of a webpage should normally be declared on the opening <html> element.

<html lang="en">

A regional language tag can be used when the regional distinction is relevant.

<html lang="en-US">

Using a valid language tag can help screen readers select appropriate pronunciation rules and can help other software process the language of the content correctly.

Common Language Codes

The following two-letter language codes are commonly used as the primary language subtag in HTML language tags.

Language Code
Arabicar
Chinesezh
Czechcs
Danishda
Dutchnl
Englishen
Finnishfi
Frenchfr
Germande
Greekel
Hebrewhe
Hindihi
Hungarianhu
Indonesianid
Italianit
Japaneseja
Koreanko
Norwegian Bokmålnb
Polishpl
Portuguesept
Romanianro
Russianru
Spanishes
Swedishsv
Thaith
Turkishtr
Ukrainianuk
Vietnamesevi

Common Country Codes

Two-letter ISO 3166-1 country codes can be used as region subtags when a language tag needs to identify a regional variation. A country code by itself should not be used as the value of lang to identify a language.

Country or Region Code
ArgentinaAR
AustraliaAU
AustriaAT
BelgiumBE
BrazilBR
CanadaCA
ChinaCN
DenmarkDK
FinlandFI
FranceFR
GermanyDE
GreeceGR
IndiaIN
IrelandIE
ItalyIT
JapanJP
MexicoMX
NetherlandsNL
New ZealandNZ
NorwayNO
PortugalPT
South AfricaZA
South KoreaKR
SpainES
SwedenSE
SwitzerlandCH
United KingdomGB
United StatesUS

Regional Language Tags

A region subtag can be added when the regional variation of a language is important. The language and region subtags are separated with a hyphen.

Language Tag Description
en-USEnglish as used in the United States.
en-GBEnglish as used in the United Kingdom.
en-AUEnglish as used in Australia.
fr-FRFrench as used in France.
fr-CAFrench as used in Canada.
de-DEGerman as used in Germany.
de-ATGerman as used in Austria.
es-ESSpanish as used in Spain.
es-MXSpanish as used in Mexico.
pt-PTPortuguese as used in Portugal.
pt-BRPortuguese as used in Brazil.
zh-CNChinese with the China region subtag.
zh-TWChinese with the Taiwan region subtag.

Do not add a region subtag unless the regional distinction is useful. If the content is simply English without a necessary regional distinction, lang="en" is sufficient.

Language Changes Within a Page

The lang attribute can be placed on an individual HTML element when part of a page uses a language different from the surrounding content.

<p>The French phrase <span lang="fr">bonjour tout le monde</span> means "hello everyone."</p>

The language declared on an element applies to its contents unless a descendant element specifies a different language.

Language Code Format

Language tags can contain more than a language and region. Depending on the language being identified, a tag can include script and other registered subtags.

Tag Description
enLanguage only.
en-USLanguage and region.
zh-HansChinese using the Simplified Han script.
zh-HantChinese using the Traditional Han script.
zh-Hant-TWChinese using Traditional Han with the Taiwan region subtag.

Language tags follow the BCP 47 language-tagging system. Not every possible combination of language, script, and region should be used; choose the shortest valid tag that accurately identifies the content.

Language Code Best Practices

  • Declare the primary language of every HTML document with the lang attribute on the <html> element.
  • Use a valid BCP 47 language tag.
  • Use the language code by itself when a regional distinction is unnecessary.
  • Add a region subtag only when it provides useful information about the language variation.
  • Use lang on individual elements when their language differs from the surrounding content.
  • Do not use a country code alone as a substitute for a language code.
  • Use a hyphen, not an underscore, between language-tag subtags.
  • Use conventional casing such as en-US for readability, although language tags are case-insensitive.