Skip to content

Props

All props are passed directly to the <TelInput> component. Props marked bindable support Svelte’s bind: syntax.

PropTypeDefaultBindableDescription
valuestring''YesE.164 formatted phone number (e.g. +36301234567). Source of truth for storage.
countryCountryCode | nullnullYesISO 3166 Alpha-2 country code (e.g. 'HU', 'US'). Auto-detected from value when not set.
validbooleantrueYesWhether the current input is a valid phone number.
validationErrorValidationErrornullYesGranular reason when valid is false. See ValidationError.
detailedValueDetailedValue | nullnullYesFull parsed result with multiple formats. See DetailedValue.
elHTMLInputElementYesReference to the underlying <input> element.
defaultCountryCountryCode | nullnullNoCountry to restore when api.reset() is called. If not set, reset clears country to null.
initialFormat'international' | 'national''international'NoControls how the phone number is displayed on initial render and on externally-driven value changes. 'national' strips the dial code from the visible input while keeping value in E.164.
placeholderFormat'international' | 'national'undefinedNoControls the format of the auto-generated placeholder (when autoPlaceholder is enabled). Falls back to initialFormat when not set. See placeholderFormat.
optionsTelInputOptions{}NoConfiguration object. See Options.

Forwarded to the underlying <input type="tel">:

PropTypeDefaultDescription
idstringAuto-generatedSets the id attribute.
namestring | nullnullSets the name attribute.
classstring''CSS class(es) applied to the input.
disabledbooleanfalseDisables the input and the parser.
readonlyboolean | nullnullMakes the input read-only.
requiredboolean | nullnullMarks the input as required. Empty input = invalid.
placeholderstring | nullnullCustom placeholder. Overrides autoPlaceholder.
sizenumber | nullnullHTML size attribute.
autocompletestring | nullnullHTML autocomplete attribute (e.g. 'tel').

Any other standard HTML input attributes are spread onto the element — including aria-* attributes.

Always stored in E.164 format — the international standard. Example: +12154567890.

<script>
let phoneNumber = $state('');
</script>
<TelInput bind:value={phoneNumber} />
<p>Stored: {phoneNumber}</p>

Accepts any ISO 3166 Alpha-2 country code. Auto-detection behavior:

  • value is +44... and country not set → auto-detects GB
  • country explicitly set → used for formatting and validation
  • User types a different dial code → country updates to match (unless lockCountry is true)

Behavior depends on validateOn and required:

Input staterequired not setrequired set
Emptytruefalse
Partial / invalidfalsefalse
Valid numbertruetrue

When valid is false, this tells you why:

ErrorMeaning
'REQUIRED'Empty input with required set
'TOO_SHORT'Not enough digits
'TOO_LONG'Too many digits
'NOT_A_NUMBER'Doesn’t look like a phone number
'INVALID_COUNTRY'Country code not recognized
'INVALID_LENGTH'Length doesn’t match any valid pattern
'COUNTRY_NOT_ALLOWED'Country not in allowedCountries
'INVALID'Fallback
nullNo error (valid)

Country to restore when api.reset() is called without { country: true }:

<TelInput defaultCountry="US" bind:country bind:value />
<!-- reset() restores country to 'US', not null -->

Controls how the phone number is displayed on initial render and whenever the value prop is changed externally by a parent component.

ValueDisplayvalue binding
'international' (default)+1 215 456 7890+12154567890
'national'215 456 7890+12154567890

The stored value is always E.164 regardless of this setting. initialFormat only affects what the user sees in the input field. So the original format does not affect how the user chooses to enter the phone number; the user can type it in any format (national or international).

Example — show national format on load:

<script>
let phone = $state('+12154567890');
let country = $state('US');
</script>
<!-- Input shows "215 456 7890", but phone.value stays "+12154567890" -->
<TelInput
bind:value={phone}
bind:country
initialFormat="national"
/>

External value changes re-apply initialFormat: if the parent sets value programmatically (e.g. via a preset button), the display is updated in the requested format — not left in whatever state the user had reached.

Controls the format of the auto-generated example placeholder shown when the input is empty (requires autoPlaceholder: true in options, which is the default).

placeholderFormatinitialFormatResulting placeholder
not setnot set / 'international'+1 201 555 0123
not set'national'201 555 0123
'international'any+1 201 555 0123
'national'any201 555 0123

Priority rule: placeholderFormat always wins when explicitly set. When omitted, initialFormat is used as the fallback.

This lets you decouple the placeholder appearance from how the value is initially displayed:

<!-- Show value in national format, but placeholder in international format -->
<TelInput
bind:value
bind:country
initialFormat="national"
placeholderFormat="international"
/>
<!-- Show value in international format, but placeholder without the dial code -->
<TelInput
bind:value
bind:country
initialFormat="international"
placeholderFormat="national"
/>

aria-invalid is automatically set to "true" when valid is false. You can override it explicitly if needed. All aria-* attributes pass through to the input element.