What it does
Provide a purpose-built code entry primitive with individual cells that still behave like a single verification value.
The component sanitizes input, advances focus after entry, moves backward on Backspace, and fires onComplete when every cell is filled.
Composition and API
Import OTPInput from the otp-input entrypoint. Use length, allowedCharacters, separatorEvery, size, appearance, mask, name, value, defaultValue, onValueChange, and onComplete to tune the experience.
Common use cases
- Two-factor authentication and passwordless sign-in.
- Payment or wire-transfer approval codes.
- Phone and email verification during onboarding.
- Invite, recovery, and device pairing codes.
Accessibility
OTPInput renders a role=group wrapper with labelled native input cells. Provide label text or an accessible name, use hint for delivery instructions, and keep errorMessage concise so screen reader users hear the actionable state.
Next.js integration notes
Use OTPInput in client components when value changes in the browser. Static defaultValue examples can be rendered on preview pages, while verification calls should run from your own server action or API route after onComplete.
FAQ
Can OTPInput paste a full code?
Yes. Paste into any cell and OTPInput distributes valid characters across the remaining cells.
Does OTPInput support controlled state?
Yes. Use value with onValueChange for controlled state, or defaultValue for uncontrolled state.
Can OTPInput submit with a form?
Yes. Pass name to render a hidden input containing the full sanitized code.