InputOTP

A composable one-time-code input with native editing and form behavior.

Installation

This component is primitive-agnostic — same source under both flavors.

Basic

Inspect

Grouping

Inspect

Controlled Form

Inspect

Use 482731 for this example.

Disabled, Read-only, and Compact

Inspect

API Reference — InputOTP

PropTypeDefaultDescription
maxLengthnumber6Code length and automatic slot count.
valuestring—Controlled code value. Omit it to use defaultValue or internal state.
defaultValuestring""Initial value for uncontrolled use.
onChange(value: string) => void—Called with the complete current code after edits.
onComplete(value: string) => void—Called whenever an edit changes the code to a complete value.
disabledbooleanfalseDisables the native input and dims the slots.
readOnlybooleanfalseKeeps the code focusable and selectable without editing.
invalidbooleanfalseApplies the error treatment and aria-invalid state.
successbooleanfalseApplies the verified success treatment.
namestring—Native form field name.
requiredboolean—Native required validation for form submission.
autoComplete"one-time-code" | string"one-time-code"Native autocomplete hint for verification codes.
inputMode"numeric" | "text" | string"numeric"Native keyboard hint; numeric mode enables the default numeric filter.
size"default" | "compact"—Follows the shared size context, or pins this control to a step.
filter"numeric" | "none""numeric" unless inputMode="text"Normalizes Unicode digits and filters non-digits, or preserves free-form text.
"aria-label"string"One-time code"Accessible name for the single native input.

API Reference — Slot Parts

PropTypeDefaultDescription
InputOTPGroupchildren—Groups adjacent slots into one visual run.
InputOTPSlotindex: number—Displays the character at this zero-based position.
InputOTPSeparatorchildren?en dashDecorative separator between slot groups.