Input OTP

One-time password input with per-character slots. Used for 2FA, email verification, and sign-in codes. Built on vue-input-otp.

Default

Six-digit OTP.

Dark previewReplay previewOpen in new tab

Usage

Import the parts you need from the component's folder.

ts
import {
  InputOTP,
  InputOTPGroup,
  InputOTPSlot,
  InputOTPSeparator,
} from "@/components/ui/input-otp";

With separator

Split slots into groups for readability.

Dark previewReplay previewOpen in new tab

Controlled

Bind v-model and read the value back as it's typed.

Dark previewReplay previewOpen in new tab

Entered: nothing yet

Digits only

Restrict input to digits with the pattern prop (REGEXP_ONLY_DIGITS).

Dark previewReplay previewOpen in new tab

Alphanumeric

Allow letters and digits via REGEXP_ONLY_DIGITS_AND_CHARS.

Dark previewReplay previewOpen in new tab

Four digits

A shorter code by lowering maxlength to 4.

Dark previewReplay previewOpen in new tab

Disabled

Prevent interaction with the disabled prop.

Dark previewReplay previewOpen in new tab

Invalid

Flag an error state with aria-invalid on the slots.

Dark previewReplay previewOpen in new tab
1
2
3

That code is incorrect.

Form

Pair with a Label and submit Button inside a form.

Dark previewReplay previewOpen in new tab

API Reference

InputOTP

PropTypeDefaultDescription
modelValuestring—Code value. Supports v-model.
maxlengthnumber6Total number of slots.
patternstring—Regex pattern for allowed characters.
disabledbooleanfalseDisable input.
EventDescription
completeFires when all slots are filled with valid characters.
update:modelValueFires as characters are entered. Enables v-model.
SlotDescription
defaultScoped slot exposing { slots } so you can render the groups and per-slot state.

InputOTPSlot

PropTypeDefaultDescription
indexnumber—Position of this slot within the code (0-based).

InputOTPGroup / InputOTPSeparator

PropTypeDefaultDescription
classstring—Group wraps a run of slots; Separator draws a divider (default slot overrides the dash).