Forms
Input OTP
One-time codes, one box per digit.
Verify a code
One box per digit, one real input underneath. Type, paste the whole code, or let SMS autofill it. onComplete fires once when every box is full.
Enter the 6-digit code we sent to a•••@northwind.com
Try 482913, or paste any 6 digits
When to use
- Two-factor and email/SMS verification codes, invite codes and short PINs.
- Fixed-length codes of 4 to 8 characters.
- Not for passwords or free text (use an input), or for codes of unknown length.
Groups
groups splits the boxes with a separator: [3, 3] reads 123 – 456. The total replaces length.
Authenticator app code
Letters and digits
pattern="alphanumeric" accepts letters too, and the mobile keyboard switches from numeric to text. Pass name to submit it with a form.
Sizes and states
Boxes are 32×40, 40×48 and 48×56. invalid turns the border red and sets aria-invalid.
API
InputOTP
| Prop | Type | Default | Description |
|---|---|---|---|
| length | number | 6 | Number of characters. Ignored when groups is set. |
| groups | number[] | — | Boxes per group, e.g. [3, 3]. |
| separator | ReactNode | — | Shown between groups. Default: a short dash. |
| pattern | 'digits' | 'alphanumeric' | 'digits' | Allowed characters; anything else is dropped on type and paste. |
| value / defaultValue | string | — | The code so far. |
| onValueChange | (value: string) => void | — | Called on every change. |
| onComplete | (value: string) => void | — | Called once when all boxes are filled. |
| invalid | boolean | — | Error state. |
| size | 'sm' | 'md' | 'lg' | 'md' | Box size. |
| ...props | InputHTMLAttributes | — | Forwarded to the real input: name, disabled, autoFocus, aria-label (default “One-time code”). |
Keyboard
| Key | Action |
|---|---|
| 0–9 (or letters) | Fills the active box and moves on. |
| Backspace | Deletes the previous character. |
| Left / Right | Move between boxes. |
| Home / End | First box / the next empty box. |
| Ctrl/Cmd + V | Pastes and fills all boxes; separators and spaces are ignored. |
Accessibility
- A single text input with autocomplete="one-time-code", so screen readers, password managers and SMS autofill treat it as one field. Give it an aria-label.
- The boxes are decorative (aria-hidden); the value is read from the input.
- inputMode and pattern bring up the numeric keypad on phones. Font size stays 16px so iOS does not zoom.
Motion
- The active box takes the focus ring; an empty active box shows a blinking caret.
- Reduced motion: the caret stays visible and still.