{country}
Writes a country's flag from its ISO 3166 code or English name, optionally with the name beside it.
Syntax
{country 'NL'}
{country $code, name}
Parameters
-
country -
An alpha-2 code (
NL), an alpha-3 code (NLD) or the English name, in any case.
Options
-
name -
Bare option: writes the English name beside the flag; the flag is then decoration (
aria-hidden).
Description
{country} turns a country code into its flag (tags/_lib/country.php). The code may be the two-letter alpha-2 (NL), the three-letter alpha-3 (NLD, as passports and sports use it) or the English name, in any case; the table holds the 249 entries of ISO 3166-1 with the names as CLDR gives them.
The flag is the code written as two regional indicator symbols - text, not an image - which a system with flag emoji draws as the flag and one without (Windows) as the two letters. Alone it is <span class="pad-country" role="img" aria-label="Netherlands">, with the name as its tooltip too. With name the English name is written beside it and the flag becomes decoration, so a screen reader says the name once.
A code that is no country is an error under the strict check, naming the nearest country when the text is close to a name; without the check the text is written as it was given. padCountry ( $code ) answers [ alpha-2, alpha-3, name ] to PHP. To colour countries by a value, see {map}.
Examples
Flags from codes
Alpha-2, alpha-3 and the English name give the same flag; alone each is an image named by its country.
<p style="font-size:32px; display:flex; gap:12px">
{country 'NL'} {country 'FRA'} {country 'Japan'} {country 'br'} {country 'KEN'}
</p>
๐ณ๐ฑ ๐ซ๐ท ๐ฏ๐ต ๐ง๐ท ๐ฐ๐ช
With the name
name writes the English name beside the flag - here visitors per country from the page's PHP.
<ul style="list-style:none; padding:0">
{visitors}
<li>{country $code, name} - {$visits}</li>
{/visitors}
</ul>
<?php
$visitors = [
[ 'code' => 'NL', 'visits' => 18230 ],
[ 'code' => 'US', 'visits' => 12904 ],
[ 'code' => 'DE', 'visits' => 8711 ],
[ 'code' => 'CI', 'visits' => 312 ] ];
?>
- Netherlands - 18230
- United States - 12904
- Germany - 8711
- Cรดte dโIvoire - 312