HTML ISO Country Codes Reference

HTML allows developers to include country-specific information using ISO country codes. These codes are essential for personalizing content, improving localization, and enhancing user experience on the web. At The Coding College, we’ve prepared a detailed guide on how to use these codes effectively.

What are ISO Country Codes?

ISO country codes are standardized two-letter codes that represent countries. They are defined by the ISO 3166-1 alpha-2 standard and are widely used in HTML, localization, and internationalization.

Why Use ISO Country Codes in HTML?

  1. Localization: Serve country-specific content dynamically.
  2. SEO Benefits: Boost your site’s visibility in country-based searches.
  3. Consistency: Maintain a global standard for representing countries.

Common ISO Country Codes

CountryISO Code
United StatesUS
United KingdomGB
CanadaCA
AustraliaAU
IndiaIN
GermanyDE
FranceFR
JapanJP
ChinaCN
BrazilBR

How to Use ISO Country Codes in HTML

ISO country codes are often used in the lang attribute alongside language codes to provide country-specific content.

Example:

<!DOCTYPE html>
<html lang="en-US">
<head>
  <title>Country-Specific Content</title>
</head>
<body>
  <h1>Welcome to The Coding College</h1>
  <p lang="en-GB">Welcome to The Coding College - British English version.</p>
  <p lang="en-US">Welcome to The Coding College - American English version.</p>
</body>
</html>

In the example above:

  • lang="en-US" specifies English content for the United States.
  • lang="en-GB" specifies English content for the United Kingdom.

Full List of ISO Country Codes

CountryISO CodeCountryISO Code
AfghanistanAFMalaysiaMY
ArgentinaARMexicoMX
BelgiumBENetherlandsNL
EgyptEGNew ZealandNZ
FinlandFISouth AfricaZA
GreeceGRSouth KoreaKR
ItalyITSwedenSE
KenyaKESwitzerlandCH
RussiaRUTurkeyTR

For a complete list, refer to the official ISO website or our tutorials at The Coding College.

Using ISO Country Codes for Personalization

You can use ISO country codes to dynamically tailor your website content based on the user’s location. For example:

  1. Detect the user’s country using their IP address.
  2. Serve relevant content using ISO country codes.

Example:

const userCountry = "IN"; // Example: Detected country code
if (userCountry === "IN") {
  document.body.innerHTML = "<h1>Welcome, India!</h1>";
} else if (userCountry === "US") {
  document.body.innerHTML = "<h1>Welcome, USA!</h1>";
}

Best Practices for ISO Country Codes

  1. Combine with Language Codes: Use lang attributes for country-specific languages (e.g., en-US, fr-CA).
  2. SEO Optimization: Use ISO country codes in URL structures for regional targeting (e.g., example.com/us/).
  3. Use Standard Codes: Stick to ISO 3166-1 alpha-2 for compatibility across platforms.

Conclusion

ISO country codes are powerful tools for creating globally accessible and regionally relevant content. By incorporating these codes into your HTML, you enhance accessibility, SEO, and user satisfaction.

For more HTML tips and resources, visit The Coding College and take your web development skills to the next level!

Leave a Comment