StartFoundationsComponentsContent

Phone input

A phone input takes an international phone number: a country code picker joined to a number field that formats as you type. It is a bare box; wrap it in a Field for a label, help text, and errors.

Stable Figma
OverviewUsageAPIAccessibility
<tk-field label="Phone number" required>
  <tk-phone-input name="phone" country="US"></tk-phone-input>
</tk-field>

Anatomy

Part What it is
tk-phone-input the element; two Tab stops, the prefix and the number
field part the bordered box around both segments
prefix part a compact Country select: a flag and the dial code, opens a searchable country list
number part the native <input type="tel"> for the national number

The label, help text, and error message come from a Field. The prefix names itself "Country calling code"; change it with country-label.

Sizes

<tk-phone-input aria-label="Medium phone input" country="GB"></tk-phone-input>
<tk-phone-input aria-label="Large phone input" country="GB" size="large"></tk-phone-input>
size Height
medium (default) 32px
large 36px

The phone input fills its container's width.

States

<tk-phone-input aria-label="Office phone" value="+12133734253" readonly></tk-phone-input>
<tk-phone-input aria-label="Office phone" value="+12133734253" disabled></tk-phone-input>
<tk-field label="Phone number" error="Enter a phone number, like 07700 900 982">
  <tk-phone-input name="phone" country="GB" value="+44770"></tk-phone-input>
</tk-field>

The box doesn't change on hover. Focus on either segment lights the one shared border, which grows thicker inward.

  • readonly: people can read and copy the number, but not edit it.
  • disabled: both segments can't be focused or edited, and nothing is submitted.
  • Error: set error on the Field. The border turns red and stays red while focused.
  • Required: set required on the Field; it adds the asterisk and makes the number required.

Formatting and value

  • The number formats as you type, grouped the way each country writes it. To keep raw digits, set the format property to false in code; the attribute can't turn it off.
  • Typing a + code switches the country. The field never adds a code you didn't type.
  • The placeholder is an example number for the selected country, unless you set placeholder.
  • value is the full number in E.164 format, such as +12133734253. It's what the form submits under name and what you should store. Setting value fills both segments.
  • country is the selected country's two-letter code; nationalNumber is the number without the country code. Detecting a country from location or language is up to you.

Validation

The phone input doesn't check the number unless you ask. Then you decide when to show an error on the Field.

  • validate: an invalid number blocks the form from submitting. It doesn't turn the box red or show a message.
  • checkPhoneValidity(): returns { valid, reason }. Call it on blur or submit, and turn the result into the Field's error.

Use validation to tell people what's wrong, never to rewrite what they typed.

Label, help text, and errors

<tk-phone-input aria-label="Mobile number" country="DE"></tk-phone-input>
  • Wrap the phone input in a Field. The Field's label, help text, and error name and describe the number field.
  • Without a visible label, set aria-label (or aria-labelledby) on the phone input.
  • A placeholder is never a label: it disappears as soon as people type.