Skip to content

PIN Input

Verification code

Enter the 4-digit code we sent to your phone.

Verification code

Code verified.

Verification code

That code isn't right. Check it and try again.

A one-cell-per-character code input (OTP / PIN) with auto-advance, paste spreading and backspace handling.

<script>
import PinInput from "@invisible-ui/svelte/PinInput.svelte";
</script>

In Elements:

<ds-pin-input label="Verification code" name="code" length="6"></ds-pin-input>

The element sends change with detail.value on every edit and complete once every cell is filled.

PropTypeDefaultDescription
valuestring""
lengthnumber6
typePinInputType"numeric"Allowed characters.
maskbooleanfalseObscure entered characters.
disabledbooleanfalseDisable all cells.
invalidbooleanfalseValidation state — colors the cells (red ring) and signals errors.
errorstring | undefinedundefinedError message, shown under the cells and announced. A non-empty one marks the cells invalid, like invalid, and every cell points at it through aria-describedby. The app owns it: a form reset leaves it in place, so the app clears it.
successbooleanfalseValidation success — colors the cells green (e.g. a verified code).
namestring | undefinedundefinedForm field name — the combined code is submitted under it.
label *string—Accessible group name.
onValueChange((value: string) => void) | undefinedundefinedCalled on every change.
onComplete((value: string) => void) | undefinedundefinedCalled when all cells are filled.

A numeric PIN input accepts Arabic-Indic (٠–٩) and Persian (۰–۹) digits, typed or pasted, in every locale. The cells show ASCII digits, and onValueChange and onComplete report ASCII digits.

A non-empty error shows the message under the control with a hazard icon and announces it as an alert. It also marks the cells invalid, as invalid does. Every cell points at it through aria-describedby and takes aria-invalid="true"; the group takes neither. The message is plain text.

<PinInput label="Verification code" length={6} bind:value error={codeError} />

The app owns the message and clears it: a form reset leaves it in place. In Flutter, the validator’s message clears on form reset.

  • A labelled group of single-character inputs; focus auto-advances and paste fills across cells.
  • The arrows follow the layout direction. In a right-to-left layout, ArrowLeft moves to the next cell and ArrowRight to the previous one.
  • A non-empty error adds aria-invalid="true" and an aria-describedby link to the message on every cell.
<PinInput length={4} label="Verification code" />

In React, onComplete reports the code once every cell is filled:

<PinInput label="Verification code" length={6} name="code" onComplete={verify} />

Themeable via --ds-pin-input-*.