An HTML country code is not a built-in HTML keyword. On the web it almost always means an ISO 3166-1 alpha-2 two-letter code—such as US, GB, or IN—that you place in HTML forms, custom attributes, and (as a region subtag) inside lang values like en-US.
What does a country code do in HTML?
It gives markup a stable, machine-readable nation identifier. Browsers do not look up a special “country” feature from the code alone; your HTML form, script, or server uses the value for shipping, localization, tax, or analytics.
Any time an HTML page must submit or store a country: signup and checkout forms, region-specific content blocks, phone or address UIs, and locale tags that combine language + country (see HTML language codes).
HTML has no native country list.
Unlike elements and global attributes, country codes come from the ISO standard. Use alpha-2 consistently so forms and APIs stay interoperable.
Country code ≠ language code.
US is a country. en is a language. Do not put a bare country code in lang. Combine them only as lang="en-US".
Store the code, show the name.
In HTML forms, put the ISO code in value and the human-readable country name as the option text: <option value="US">United States</option>.
Syntax
HTML Syntax Patterns
There is no single country-code attribute in HTML. These are the patterns you will use most:
syntax.html
<option value="CC">Country name</option>
data-attribute.html
<div data-country="CC">...</div>
lang-region.html
<html lang="xx-CC">
Replace CC with an ISO 3166-1 alpha-2 code (uppercase by convention). Replace xx with an ISO 639 language code when building a BCP 47 tag.
Reference
Core HTML Concepts
Terms you will use when putting country codes into HTML:
Concept
Meaning in HTML
ISO 3166-1 alpha-2
Two-letter country codes such as US, IN, DE
ISO 3166-1 alpha-3
Three-letter codes (USA)—less common in HTML forms
<select> / <option>
Standard HTML controls for a country dropdown
data-country
Custom data attribute holding an ISO code for scripts
lang region subtag
Same alpha-2 codes inside BCP 47, e.g. en-GB
Language code
Identifies a language (en, fr)—not a nation
hreflang
Language (and optional region) of a linked alternate page
Buttons toggle which data-country section is visible
Default: show US section
How It Works
data-* attributes store machine values without affecting layout.
Same ISO codes as form options keep your HTML consistent.
querySelectorAll finds every country block for filtering.
Prefer progressive enhancement—content still readable if JS is off.
Example 3 — Full HTML Page Pattern
Combine document language with country-tagged sections on one page.
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>HTML Country Code Example</title>
</head>
<body>
<h1>Welcome to our website!</h1>
<p>We are pleased to serve customers from different countries.</p>
<div class="country-info" data-country="US">
<h2>United States</h2>
<p>This section contains specific information for customers in the United States.</p>
</div>
<div class="country-info" data-country="GB">
<h2>United Kingdom</h2>
<p>This section contains specific information for customers in the United Kingdom.</p>
</div>
<script>
var countryDivs = document.getElementsByClassName("country-info");
for (var i = 0; i < countryDivs.length; i++) {
var country = countryDivs[i].getAttribute("data-country");
if (country === "US") {
// United States logic
} else if (country === "GB") {
// United Kingdom logic
}
}
</script>
</body>
</html>
Two country-info sections in the DOM
Script reads data-country on each
How It Works
lang on html declares the page language (not the country).
data-country attaches ISO nation codes to content blocks.
A simple loop branches on each code for region-specific behaviour.
UTF-8 charset keeps international country names display-safe.
Reference
ISO 3166-1 Alpha-2 Country Codes
Full HTML country code reference (238 entries). Use these values in option, data-country, and as the region part of lang / hreflang tags.
Country
ISO Code
Afghanistan
AF
Albania
AL
Algeria
DZ
American Samoa
AS
Andorra
AD
Angola
AO
Antarctica
AQ
Antigua And Barbuda
AG
Argentina
AR
Armenia
AM
Aruba
AW
Australia
AU
Austria
AT
Azerbaijan
AZ
Bahamas
BS
Bahrain
BH
Bangladesh
BD
Barbados
BB
Belarus
BY
Belgium
BE
Belize
BZ
Benin
BJ
Bermuda
BM
Bhutan
BT
Bolivia
BO
Bosnia And Herzegovina
BA
Botswana
BW
Bouvet Island
BV
Brazil
BR
British Indian Ocean Territory
IO
Brunei Darussalam
BN
Bulgaria
BG
Burkina Faso
BF
Burundi
BI
Cambodia
KH
Cameroon
CM
Canada
CA
Cape Verde
CV
Cayman Islands
KY
Central African Republic
CF
Chad
TD
Chile
CL
China
CN
Christmas Island
CX
Cocos (Keeling) Islands
CC
Colombia
CO
Comoros
KM
Congo
CG
Congo, The Democratic Republic Of The
CD
Cook Islands
CK
Costa Rica
CR
Côte D'ivoire
CI
Croatia
HR
Cuba
CU
Cyprus
CY
Czech Republic
CZ
Denmark
DK
Djibouti
DJ
Dominica
DM
Dominican Republic
DO
Ecuador
EC
Egypt
EG
El Salvador
SV
Equatorial Guinea
GQ
Eritrea
ER
Estonia
EE
Ethiopia
ET
Falkland Islands (Malvinas)
FK
Faroe Islands
FO
Fiji
FJ
Finland
FI
France
FR
French Guiana
GF
French Polynesia
PF
French Southern Territories
TF
Gabon
GA
Gambia
GM
Georgia
GE
Germany
DE
Ghana
GH
Gibraltar
GI
Greece
GR
Greenland
GL
Grenada
GD
Guadeloupe
GP
Guam
GU
Guatemala
GT
Guinea
GN
Guinea-Bissau
GW
Guyana
GY
Haiti
HT
Heard Island And Mcdonald Islands
HM
Honduras
HN
Hong Kong
HK
Hungary
HU
Iceland
IS
India
IN
Indonesia
ID
Iran, Islamic Republic Of
IR
Iraq
IQ
Ireland
IE
Israel
IL
Italy
IT
Jamaica
JM
Japan
JP
Jordan
JO
Kazakhstan
KZ
Kenya
KE
Kiribati
KI
Korea, Democratic People's Republic Of
KP
Korea, Republic Of
KR
Kuwait
KW
Kyrgyzstan
KG
Lao People's Democratic Republic(Laos)
LA
Latvia
LV
Lebanon
LB
Lesotho
LS
Liberia
LR
Libyan Arab Jamahiriya
LY
Liechtenstein
LI
Lithuania
LT
Luxembourg
LU
Macao
MO
Macedonia, The Former Yugoslav Republic Of
MK
Madagascar
MG
Malawi
MW
Malaysia
MY
Maldives
MV
Mali
ML
Malta
MT
Marshall Islands
MH
Martinique
MQ
Mauritania
MR
Mauritius
MU
Mayotte
YT
Mexico
MX
Micronesia, Federated States Of
FM
Moldova, Republic Of
MD
Monaco
MC
Mongolia
MN
Montenegro
ME
Montserrat
MS
Morocco
MA
Mozambique
MZ
Myanmar
MM
Namibia
NA
Nauru
NR
Nepal
NP
Netherlands
NL
Netherlands Antilles
AN
New Caledonia
NC
New Zealand
NZ
Nicaragua
NI
Niger
NE
Nigeria
NG
Niue
NU
Norfolk Island
NF
Northern Mariana Islands
MP
Norway
NO
Oman
OM
Pakistan
PK
Palau
PW
Palestinian Territory, Occupied
PS
Panama
PA
Papua New Guinea
PG
Paraguay
PY
Peru
PE
Philippines
PH
Pitcairn
PN
Poland
PL
Portugal
PT
Puerto Rico
PR
Qatar
QA
Réunion
RE
Romania
RO
Russian Federation
RU
Rwanda
RW
Saint Helena
SH
Saint Kitts And Nevis
KN
Saint Lucia
LC
Saint Pierre And Miquelon
PM
Saint Vincent And The Grenadines
VC
Samoa
WS
San Marino
SM
Sao Tome And Principe
ST
Saudi Arabia
SA
Senegal
SN
Serbia
RS
Seychelles
SC
Sierra Leone
SL
Singapore
SG
Slovakia
SK
Slovenia
SI
Solomon Islands
SB
Somalia
SO
South Africa
ZA
South Georgia And The South Sandwich Islands
GS
Spain
ES
Sri Lanka
LK
Sudan
SD
Suriname
SR
Svalbard And Jan Mayen
SJ
Swaziland
SZ
Sweden
SE
Switzerland
CH
Syrian Arab Republic
SY
Taiwan
TW
Tajikistan
TJ
Tanzania, United Republic Of
TZ
Thailand
TH
Timor-Leste
TL
Togo
TG
Tokelau
TK
Tonga
TO
Trinidad And Tobago
TT
Tunisia
TN
Turkey
TR
Turkmenistan
TM
Turks And Caicos Islands
TC
Tuvalu
TV
Uganda
UG
Ukraine
UA
United Arab Emirates
AE
United Kingdom
GB
United States
US
United States Minor Outlying Islands
UM
Uruguay
UY
Uzbekistan
UZ
Vanuatu
VU
Venezuela
VE
Viet Nam
VN
Virgin Islands, British
VG
Virgin Islands, U.S.
VI
Wallis And Futuna
WF
Western Sahara
EH
Yemen
YE
Zambia
ZM
Zimbabwe
ZW
ISO alpha-2 covers countries and many territories, but not every geopolitical label. Prefer this list for HTML forms; refresh it if your product needs newly assigned codes.
Edge Cases & Pitfalls
Most HTML country-code mistakes mix nations with languages or store display names instead of codes.
lang
Putting a country code in lang alone
lang="US" is invalid. Use a language first: lang="en-US".
UK
Using UK instead of GB
ISO alpha-2 for the United Kingdom is GB. Prefer GB in HTML forms and APIs.
value
Submitting the country name as value
Names vary by language and spelling. Store US in value; localize the visible label.
alpha-3
Mixing alpha-2 and alpha-3
Do not mix US and USA in the same HTML form field without converting on the server.
sort
Sorting the select by code
Users scan country names. Sort options alphabetically by the localized name in the HTML.
stale
Hard-coding a never-updated list
ISO occasionally assigns new codes. Keep your HTML/JSON source maintainable and refresh it when needed.
Compatibility
Browser Support
Country codes in HTML rely on ordinary markup (select, option, data-*, lang). Those features are universally supported in browsers.
✓ Baseline · Widely available
forms / data-* / lang region
ISO country codes themselves are a data standard. HTML form controls and attributes that carry them work in all major browsers.
100%HTML feature 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
select, data-*, langUniversally supported
Bottom line: You do not need a special browser API for country codes — use standard HTML values consistently.
Remember
Key Takeaways
Role: ISO alpha-2 codes identify countries inside HTML forms and attributes.
Forms:value="US" on options; show the country name as text.
Not language: combine with language codes only in tags like en-US.
UK tip: prefer GB for the United Kingdom in HTML.
One line: use ISO alpha-2 in HTML value / data-country → show names to users → combine with language only in BCP 47 tags.
Frequently Asked Questions
HTML does not define its own country codes. In web pages, country codes usually mean ISO 3166-1 alpha-2 — two-letter codes like US, GB, and IN that you put in form values, data attributes, and lang region tags.
Common places: option value on a select dropdown, data-country on elements, hidden inputs submitted with a form, and the region subtag of lang such as en-US.
An international standard of two-letter country codes. It is the usual choice for HTML forms, payment APIs, and BCP 47 region subtags.
No. Country codes identify nations (US, FR). Language codes identify languages (en, fr). Combine them in HTML as lang="en-US" for English as used in the United States.
Prefer alpha-2 (two letters) for HTML forms and most web APIs. Alpha-3 (USA) appears in some databases but is less common in front-end markup.
Use a select element. Set each option value to the ISO code and the visible text to the country name. Load options from this reference table or a maintained JSON list.