Front-end Tutorials

Front-end Tutorials

HTMLCSSSassJavaScriptReactJS
CMS Tutorials

CMS Tutorials

WordPress
Tutorials expand

HTML Country Code

Posted in HTML Tutorial
Updated on Dec 14, 2023
By Mari Selvan
👁️ 1112 - Views
⏳ 4 mins
💬 1 Comment
HTML Country Code

Photo Credit to CodeToFun

What is HTML Country Code?

HTML does not have specific country codes defined within its standard.

However, when it comes to specifying country-related information within HTML, the commonly accepted approach is to use ISO 3166-1 alpha-2 country codes.

These are two-letter codes that represent countries and are widely used across various systems and standards.

For example, if you need to indicate the country of a user or display country-specific information, you can use ISO 3166-1 alpha-2 country codes within your HTML markup or JavaScript code.

Here's an example of how you can use country codes in HTML:

demo.html
Copied
Copy To Clipboard

<!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>
    
    <!-- Additional country sections -->
    
    <script>
      // JavaScript code to handle country-specific logic
      var countryDivs = document.getElementsByClassName('country-info');
      
      // Loop through the country info divs
      for (var i = 0; i < countryDivs.length; i++) {
        var countryDiv = countryDivs[i];
        var country = countryDiv.getAttribute('data-country');
        
        // Perform country-specific operations
        if (country === 'US') {
          // Do something for the United States
        } else if (country === 'GB') {
          // Do something for the United Kingdom
        } else {
          // Handle other countries
        }
      }
    </script>
  </body>
</html>

Here are some examples of ISO 3166-1 alpha-2 country codes for reference:

LanguageISO 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

You can use these country codes in various contexts, such as within form fields, data attributes, or JavaScript functions, to handle country-specific logic or display relevant information.

It's important to note that while ISO 3166-1 alpha-2 codes are widely used, they might not cover all geopolitical entities or regions. In some cases, there are additional codes defined for specific regions or territories.

👨‍💻 Join our Community:

To get interesting news and instant updates on Front-End, Back-End, CMS and other Frameworks. Please Join the Telegram Channel:

Author

author
👋 Hey, I'm Mari Selvan

For over eight years, I worked as a full-stack web developer. Now, I have chosen my profession as a full-time blogger at codetofun.com.

Buy me a coffee to make codetofun.com free for everyone.

Buy me a Coffee

Share Your Findings to All

Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Mari Selvan
Mari Selvan
1 year ago

If you have any doubts regarding this article (HTML Country Code) please comment here. I will help you immediately.

We make use of cookies to improve our user experience. By using this website, you agree with our Cookies Policy
AgreeCookie Policy