{country}

Writes a country's flag from its ISO 3166 code or English name, optionally with the name beside it.

Pictures and media Single tags

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.

Templateexamples/country/1-flags.pad
<p style="font-size:32px; display:flex; gap:12px">
  {country 'NL'} {country 'FRA'} {country 'Japan'} {country 'br'} {country 'KEN'}
</p>
Resultopen alone

๐Ÿ‡ณ๐Ÿ‡ฑ ๐Ÿ‡ซ๐Ÿ‡ท ๐Ÿ‡ฏ๐Ÿ‡ต ๐Ÿ‡ง๐Ÿ‡ท ๐Ÿ‡ฐ๐Ÿ‡ช

With the name

name writes the English name beside the flag - here visitors per country from the page's PHP.

Templateexamples/country/2-names.pad
<ul style="list-style:none; padding:0">
  {visitors}
  <li>{country $code, name} - {$visits}</li>
  {/visitors}
</ul>
PHPexamples/country/2-names.php
<?php

  $visitors = [
    [ 'code' => 'NL', 'visits' => 18230 ],
    [ 'code' => 'US', 'visits' => 12904 ],
    [ 'code' => 'DE', 'visits' => 8711  ],
    [ 'code' => 'CI', 'visits' => 312   ] ];

?>
Resultopen alone
  • Netherlands - 18230
  • United States - 12904
  • Germany - 8711
  • Cรดte dโ€™Ivoire - 312

See also

  • {map} Draws a choropleth map as inline SVG - every country coloured by a value of its row - of the world or one of its regions.
  • {emoji} An emoji by its GitHub or Slack shortcode, as a labelled image a screen reader names.