Input OTP
A one-time code, typed one character per slot. Typing moves to the next slot, Backspace goes back, and pasting a whole code fills every slot. The active slot shows the focus outline and a caret.
Install
npx shadcn@latest add @nelumbo/input-otpSix digits
Two groups of three with a dash between them. Click the first slot or the label, then type or paste the code. The value is controlled: the line below shows it as it changes.
We sent a 6-digit code to your phone.
Value: empty (0/6)
Verdicts
The code checks itself when the last character lands. status="success" washes the slots green in a wave; status="error" (or aria-invalid) shakes the code and turns it red, with the error text tied to the input by aria-describedby. Try 123456, then anything else. This one is a connected group: the slots share one bar.
Four-digit PIN
Any length works: set maxLength and give each slot an index. Two groups of two keep a PIN readable.
Letters and digits
REGEXP_ONLY_DIGITS_AND_CHARS accepts letters and digits, useful for recovery codes. Input is kept to that pattern; pasted text that does not match is dropped.
Disabled
The whole code is inert and dimmed. Focus skips it.
Props
| Prop | Type | Default | Notes |
|---|---|---|---|
maxLength | number | Number of slots. Required | |
value / onChange | string / (value) => void | Controlled; onChange gets the whole code | |
pattern | RegExp string | Use REGEXP_ONLY_DIGITS, REGEXP_ONLY_CHARS or REGEXP_ONLY_DIGITS_AND_CHARS | |
onComplete | () => void | Called once every slot is filled | |
status | "success" | "error" | Verdict on a complete code: a green wave, or a shake in red | |
aria-invalid | boolean | false | Same as status="error"; pair with aria-describedby |
disabled | boolean | false | Dims the code and removes it from the tab order |
autoComplete | string | Use "one-time-code" so phones offer the SMS code | |
aria-label / label for | string | Name the hidden input. A visible label with htmlFor works too | |
InputOTPGroup connected | boolean | false | Slots sit on one bar with small inner corners |
InputOTPSlot index | number | Position in the code, starting at 0 | |
InputOTPSeparator | A short dash between groups; not announced as content |