Skip to content
Browse docs and components

OTP Input

otp-input

A one-time code field drawn as a box per character over one real input, so typing, paste, SMS autofill, Android keyboards and screen readers all just work. Overwrites in place, shakes on a wrong code, draws a check on a right one.

Responsive

Install

$npxshadcnadd@forme/otp-input

Adds the component, its registry dependencies, and the token stylesheet you import once.

API reference

Read from the source, so it is the API of the file you install. A prop marked * is required.

OtpInput

A one-time code field, drawn as one box per character.

PropTypeDefaultDescription
label*string—Visible label.
lengthnumber6Number of characters. Six is the common case.
valuestring—
defaultValuestring""
onChange(value: string) => void—
onComplete(value: string) => void—Called whenever the code becomes complete, including after a correction. Submit from here.
mode"numeric" | "alphanumeric""numeric"Digits only by default. Pass "alphanumeric" for codes like A7K2QX.
groupSizenumber—Draws a separator after this many characters, e.g. 3 for 123 456.
descriptionstring—Help text under the field. Replaced by error or a success message.
errorstring—Marks the code wrong: the boxes shake once and the message is announced.
successboolean | string—Marks the code accepted and draws a check. A string is shown as the message.
maskbooleanfalseShows dots instead of the characters.
disabledboolean—
autoFocusboolean—
namestring—
classNamestring—