Skip to content

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

PropTypeDefaultDescription
valuestring—Current code, making the field controlled.
defaultValuestring""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.
lengthnumber6Number of characters the code holds.
type"numeric" | "alphanumeric""numeric"Which characters are kept when typing or pasting.
maskbooleanfalseHides the entered characters in the slots.
disabledbooleanfalseDisables the hidden input and sets the data-disabled attribute.
autoFocusbooleanfalseFocuses the hidden input when the field mounts.
idstring—Id applied to the rendered root element.
renderReactElement | ((props, state) => ReactElement)—Replace the rendered element while keeping behavior and accessibility wiring.

OtpInput.Slot

PropTypeDefaultDescription
index*number—Position in the code this slot displays.
renderReactElement | ((props, state) => ReactElement)—Replace the rendered element while keeping behavior and accessibility wiring.

OtpInput.HiddenInput

PropTypeDefaultDescription
autoFocusboolean—Focuses this input on mount, overriding the root setting.
renderReactElement | ((props, state) => ReactElement)—Replace the rendered element while keeping behavior and accessibility wiring.

Keyboard

KeyAction
TabMove focus to/from the control
Enter / SpaceActivate 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