OTP input
Input for one-time codes, with one slot per character.
- Browsers
- Chrome 123+Firefox 121+Safari 17.5+
- Tier
- 2
- Bundle compressed
- 1.53 kB
- Forced layout budget
- 0 ms
- Axe budget
- 0
- SSR compatible
- Yes
- Published contract
- Test harness
Playground
OTP Input
Default
API
OtpInput.Root
| Prop | Type | Default | Description |
|---|---|---|---|
value | string | — | Current code, making the field controlled. |
defaultValue | string | "" | Starting code for the uncontrolled field. |
onValueChange | (value: string) => void | — | Called with the code whenever it changes. |
onComplete | (value: string) => void | — | Called once the code reaches the configured length. |
length | number | 6 | Number of characters the code holds. |
type | "numeric" | "alphanumeric" | "numeric" | Which characters are kept when typing or pasting. |
mask | boolean | false | Hides the entered characters in the slots. |
disabled | boolean | false | Disables the hidden input and sets the data-disabled attribute. |
autoFocus | boolean | false | Focuses the hidden input when the field mounts. |
id | string | — | Id applied to the rendered root element. |
render | ReactElement | ((props, state) => ReactElement) | — | Replace the rendered element while keeping behavior and accessibility wiring. |
OtpInput.Slot
| Prop | Type | Default | Description |
|---|---|---|---|
index* | number | — | Position in the code this slot displays. |
render | ReactElement | ((props, state) => ReactElement) | — | Replace the rendered element while keeping behavior and accessibility wiring. |
OtpInput.HiddenInput
| Prop | Type | Default | Description |
|---|---|---|---|
autoFocus | boolean | — | Focuses this input on mount, overriding the root setting. |
render | ReactElement | ((props, state) => ReactElement) | — | Replace the rendered element while keeping behavior and accessibility wiring. |
Keyboard
| Key | Action |
|---|---|
| Tab | Move focus to/from the control |
| Enter / Space | Activate when focused (button-like controls) |
Accessibility
Uses semantic HTML where possible. Inspect rendered markup in the playground — ARIA is added only when native elements are insufficient.
Styling hooks
data-disabled