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 |
|---|---|
| Arabic | ar |
| Chinese | zh |
| Czech | cs |
| Danish | da |
| Dutch | nl |
| English | en |
| Finnish | fi |
| French | fr |
| German | de |
| Greek | el |
| Hebrew | he |
| Hindi | hi |
| Hungarian | hu |
| Indonesian | id |
| Italian | it |
| Japanese | ja |
| Korean | ko |
| Norwegian Bokmål | nb |
| Polish | pl |
| Portuguese | pt |
| Romanian | ro |
| Russian | ru |
| Spanish | es |
| Swedish | sv |
| Thai | th |
| Turkish | tr |
| Ukrainian | uk |
| Vietnamese | vi |
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 |
|---|---|
| Argentina | AR |
| Australia | AU |
| Austria | AT |
| Belgium | BE |
| Brazil | BR |
| Canada | CA |
| China | CN |
| Denmark | DK |
| Finland | FI |
| France | FR |
| Germany | DE |
| Greece | GR |
| India | IN |
| Ireland | IE |
| Italy | IT |
| Japan | JP |
| Mexico | MX |
| Netherlands | NL |
| New Zealand | NZ |
| Norway | NO |
| Portugal | PT |
| South Africa | ZA |
| South Korea | KR |
| Spain | ES |
| Sweden | SE |
| Switzerland | CH |
| United Kingdom | GB |
| United States | US |
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-US | English as used in the United States. |
en-GB | English as used in the United Kingdom. |
en-AU | English as used in Australia. |
fr-FR | French as used in France. |
fr-CA | French as used in Canada. |
de-DE | German as used in Germany. |
de-AT | German as used in Austria. |
es-ES | Spanish as used in Spain. |
es-MX | Spanish as used in Mexico. |
pt-PT | Portuguese as used in Portugal. |
pt-BR | Portuguese as used in Brazil. |
zh-CN | Chinese with the China region subtag. |
zh-TW | Chinese 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 |
|---|---|
en | Language only. |
en-US | Language and region. |
zh-Hans | Chinese using the Simplified Han script. |
zh-Hant | Chinese using the Traditional Han script. |
zh-Hant-TW | Chinese 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
langattribute 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
langon 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-USfor readability, although language tags are case-insensitive.
