StartFoundationsComponentsContent

Country select

A country select lets people choose one country by typing to filter. The full list of countries, their names in the user's language, and their flags are built in; the value is a two-letter country code.

Stable Figma
OverviewUsageAPIAccessibility
<tk-field label="Country">
  <tk-country-select name="country"></tk-country-select>
</tk-field>

Put it in a Field to give it a label, helper, and error. Without a Field, set aria-label. You don't write any options.

Anatomy

Part What it is
tk-country-select the element; one Tab stop
field a text input: shows the chosen country, or what people type
flag leads the field and each option; decorative
clear button appears while the field has text
chevron turns over while the menu is open
menu every country, sorted by name in the user's language
option one country; a check marks the chosen one

Countries and names

<tk-country-select aria-label="Pays" locale="fr" value="DE"></tk-country-select>
  • The list covers all 249 ISO 3166-1 countries and territories, plus Kosovo (XK).
  • Names come from the browser in the page's language (lang on <html>), or the browser's language when it isn't set. locale sets the language for one field; the list re-sorts for it.
  • The value is the upper-case alpha-2 code, such as GB or US. A lower-case value is converted. Store and submit the code, not the name.
  • Flags load the first time one is shown, from the library's own files. Until then, their space is kept empty, so nothing shifts.

Filtering

  • Type part of a name, in any case and anywhere in the name: "kingdom" finds "United Kingdom".
  • Accents don't matter: "curacao" finds "Curaçao".
  • The two-letter code works too: "gb" finds the United Kingdom.
  • Nothing is chosen until people choose an option. Leaving the field restores the chosen country. People can't add a country that isn't in the list.

Dial codes

<tk-field label="Phone country">
  <tk-country-select dial-code value="NL"></tk-country-select>
</tk-field>

dial-code adds the calling code to each name: "Netherlands (+31)". Typing digits, such as "44", then finds countries by code. Territories with no calling code show none.

Compact

<tk-country-select
  compact
  dial-code
  aria-label="Country calling code"
  autocomplete="tel-country-code"
  value="US"
></tk-country-select>

compact shrinks the field to the flag and the calling code, to sit beside a number field. Use it with dial-code. The clear button is hidden, and the menu stays wide enough for full names. The field fits about five characters, so a typed name scrolls inside it; read the matches in the menu. Focusing the field selects the code, so typing replaces it.

Name a compact field with aria-label: a visible label above it would name the whole row. bare also removes the field's border, background, focus ring, and chevron, for use inside another field's box. Phone input does all this for you.

Sizes

<tk-country-select aria-label="Country" value="JP"></tk-country-select>
<tk-country-select size="large" aria-label="Country" value="JP"></tk-country-select>
size Height Text Flag
medium (default) 32px Body Small (14/20) 24×16px
large 36px Body Medium (16/24) 30×20px

States

<tk-country-select aria-label="Country" value="IT" disabled></tk-country-select>
<tk-country-select aria-label="Country" value="IT" readonly></tk-country-select>

The states are Combobox's. Hover doesn't change the field; keyboard focus colors and thickens its border.

  • disabled: can't be focused or opened, and isn't submitted.
  • readonly: shows the country and submits it, but can't be edited or opened. The flag stays; the clear button and chevron are hidden.
  • Error: set error on the Field.