HTML Country Code

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

Definition and Usage

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.

Where do country codes appear in HTML?

Most often as <option value="US"> in a <select>, as data-country="GB" on a section, or as the region part of a BCP 47 tag on <html lang="en-US">.

When should you use them?

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>.

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.

Core HTML Concepts

Terms you will use when putting country codes into HTML:

ConceptMeaning in HTML
ISO 3166-1 alpha-2Two-letter country codes such as US, IN, DE
ISO 3166-1 alpha-3Three-letter codes (USA)—less common in HTML forms
<select> / <option>Standard HTML controls for a country dropdown
data-countryCustom data attribute holding an ISO code for scripts
lang region subtagSame alpha-2 codes inside BCP 47, e.g. en-GB
Language codeIdentifies a language (en, fr)—not a nation
hreflangLanguage (and optional region) of a linked alternate page

Popular HTML country codes

CountryCodeTry it
United StatesUSTry it
United KingdomGBTry it
IndiaINTry it
CanadaCATry it
AustraliaAUTry it
GermanyDETry it
FranceFRTry it
JapanJPTry it

How to Use Country Codes in HTML

Pick alpha-2 codes, put them in markup values users never have to type as raw codes, then read them in script or on the server.

  1. Choose ISO 3166-1 alpha-2 (two letters) for HTML forms and APIs.
  2. Build a <select name="country"> with <option value="CC">Name</option> for each country.
  3. Sort options by localized country name for humans, not by code.
  4. For region-specific blocks, add data-country="CC" and filter with JavaScript.
  5. When declaring locale on the page, combine with a language code: <html lang="en-US">.
TaskHTML markup
Form option<option value="US">United States</option>
Data attribute<section data-country="IN">...</section>
Document locale<html lang="en-GB">
Read in JSel.getAttribute("data-country")

Live Preview

Choose a country code and see how it would appear as an HTML <option value> and a data-country attribute.

The sample markup below updates when you change the code.

Sample HTML
<option value="US">United States</option>
<div data-country="US">...</div>
<html lang="en-US">

ISO alpha-2 code: US

HTML Examples

Copy-ready snippets for forms and regional content. Use Try It Yourself for a live HTML editor.

Example 1 — Country Select Dropdown

Use a native HTML <select>. Submit the ISO code; show the country name to the user.

HTML
<label for="country">Country:</label>
<select id="country" name="country">
  <option value="">-- Select --</option>
  <option value="US">United States</option>
  <option value="GB">United Kingdom</option>
  <option value="IN">India</option>
  <option value="CA">Canada</option>
  <option value="AU">Australia</option>
  <option value="DE">Germany</option>
</select>
Try It Yourself

How It Works

  1. value holds the code. Servers and APIs prefer stable ISO alpha-2 values.
  2. Text holds the name. Users see “United States”, not only US.
  3. Empty first option forces an explicit choice when required.
  4. Same pattern scales to the full table below.

Example 2 — data-country Sections

Mark HTML sections with a custom data attribute, then show or style them with JavaScript.

HTML
<div class="country-info" data-country="US">
  <h2>United States</h2>
  <p>US-specific content.</p>
</div>
<div class="country-info" data-country="GB">
  <h2>United Kingdom</h2>
  <p>UK-specific content.</p>
</div>

<script>
  var sections = document.querySelectorAll(".country-info");
  // Compare getAttribute("data-country") to "US", "GB", ...
</script>
Try It Yourself

How It Works

  1. data-* attributes store machine values without affecting layout.
  2. Same ISO codes as form options keep your HTML consistent.
  3. querySelectorAll finds every country block for filtering.
  4. 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>
Try It Yourself

How It Works

  1. lang on html declares the page language (not the country).
  2. data-country attaches ISO nation codes to content blocks.
  3. A simple loop branches on each code for region-specific behaviour.
  4. UTF-8 charset keeps international country names display-safe.

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.

CountryISO Code
AfghanistanAF
AlbaniaAL
AlgeriaDZ
American SamoaAS
AndorraAD
AngolaAO
AntarcticaAQ
Antigua And BarbudaAG
ArgentinaAR
ArmeniaAM
ArubaAW
AustraliaAU
AustriaAT
AzerbaijanAZ
BahamasBS
BahrainBH
BangladeshBD
BarbadosBB
BelarusBY
BelgiumBE
BelizeBZ
BeninBJ
BermudaBM
BhutanBT
BoliviaBO
Bosnia And HerzegovinaBA
BotswanaBW
Bouvet IslandBV
BrazilBR
British Indian Ocean TerritoryIO
Brunei DarussalamBN
BulgariaBG
Burkina FasoBF
BurundiBI
CambodiaKH
CameroonCM
CanadaCA
Cape VerdeCV
Cayman IslandsKY
Central African RepublicCF
ChadTD
ChileCL
ChinaCN
Christmas IslandCX
Cocos (Keeling) IslandsCC
ColombiaCO
ComorosKM
CongoCG
Congo, The Democratic Republic Of TheCD
Cook IslandsCK
Costa RicaCR
Côte D'ivoireCI
CroatiaHR
CubaCU
CyprusCY
Czech RepublicCZ
DenmarkDK
DjiboutiDJ
DominicaDM
Dominican RepublicDO
EcuadorEC
EgyptEG
El SalvadorSV
Equatorial GuineaGQ
EritreaER
EstoniaEE
EthiopiaET
Falkland Islands (Malvinas)FK
Faroe IslandsFO
FijiFJ
FinlandFI
FranceFR
French GuianaGF
French PolynesiaPF
French Southern TerritoriesTF
GabonGA
GambiaGM
GeorgiaGE
GermanyDE
GhanaGH
GibraltarGI
GreeceGR
GreenlandGL
GrenadaGD
GuadeloupeGP
GuamGU
GuatemalaGT
GuineaGN
Guinea-BissauGW
GuyanaGY
HaitiHT
Heard Island And Mcdonald IslandsHM
HondurasHN
Hong KongHK
HungaryHU
IcelandIS
IndiaIN
IndonesiaID
Iran, Islamic Republic OfIR
IraqIQ
IrelandIE
IsraelIL
ItalyIT
JamaicaJM
JapanJP
JordanJO
KazakhstanKZ
KenyaKE
KiribatiKI
Korea, Democratic People's Republic OfKP
Korea, Republic OfKR
KuwaitKW
KyrgyzstanKG
Lao People's Democratic Republic(Laos)LA
LatviaLV
LebanonLB
LesothoLS
LiberiaLR
Libyan Arab JamahiriyaLY
LiechtensteinLI
LithuaniaLT
LuxembourgLU
MacaoMO
Macedonia, The Former Yugoslav Republic OfMK
MadagascarMG
MalawiMW
MalaysiaMY
MaldivesMV
MaliML
MaltaMT
Marshall IslandsMH
MartiniqueMQ
MauritaniaMR
MauritiusMU
MayotteYT
MexicoMX
Micronesia, Federated States OfFM
Moldova, Republic OfMD
MonacoMC
MongoliaMN
MontenegroME
MontserratMS
MoroccoMA
MozambiqueMZ
MyanmarMM
NamibiaNA
NauruNR
NepalNP
NetherlandsNL
Netherlands AntillesAN
New CaledoniaNC
New ZealandNZ
NicaraguaNI
NigerNE
NigeriaNG
NiueNU
Norfolk IslandNF
Northern Mariana IslandsMP
NorwayNO
OmanOM
PakistanPK
PalauPW
Palestinian Territory, OccupiedPS
PanamaPA
Papua New GuineaPG
ParaguayPY
PeruPE
PhilippinesPH
PitcairnPN
PolandPL
PortugalPT
Puerto RicoPR
QatarQA
RéunionRE
RomaniaRO
Russian FederationRU
RwandaRW
Saint HelenaSH
Saint Kitts And NevisKN
Saint LuciaLC
Saint Pierre And MiquelonPM
Saint Vincent And The GrenadinesVC
SamoaWS
San MarinoSM
Sao Tome And PrincipeST
Saudi ArabiaSA
SenegalSN
SerbiaRS
SeychellesSC
Sierra LeoneSL
SingaporeSG
SlovakiaSK
SloveniaSI
Solomon IslandsSB
SomaliaSO
South AfricaZA
South Georgia And The South Sandwich IslandsGS
SpainES
Sri LankaLK
SudanSD
SurinameSR
Svalbard And Jan MayenSJ
SwazilandSZ
SwedenSE
SwitzerlandCH
Syrian Arab RepublicSY
TaiwanTW
TajikistanTJ
Tanzania, United Republic OfTZ
ThailandTH
Timor-LesteTL
TogoTG
TokelauTK
TongaTO
Trinidad And TobagoTT
TunisiaTN
TurkeyTR
TurkmenistanTM
Turks And Caicos IslandsTC
TuvaluTV
UgandaUG
UkraineUA
United Arab EmiratesAE
United KingdomGB
United StatesUS
United States Minor Outlying IslandsUM
UruguayUY
UzbekistanUZ
VanuatuVU
VenezuelaVE
Viet NamVN
Virgin Islands, BritishVG
Virgin Islands, U.S.VI
Wallis And FutunaWF
Western SaharaEH
YemenYE
ZambiaZM
ZimbabweZW

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.

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 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
select, data-*, lang Universally supported

Bottom line: You do not need a special browser API for country codes — use standard HTML values consistently.

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.

Try a country select in the editor

Pick a country from the dropdown and see its ISO alpha-2 code—plain HTML, no CSS.

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