React OTP Input

The MFA step, done properly: separate monospaced digit cells that auto-advance as you type, accept a full paste anywhere in the row, navigate with arrows, and delete backwards naturally. The first cell carries autocomplete="one-time-code" so mobile keyboards offer the SMS code. onComplete fires exactly once when the last digit lands.

Two-factor authentication

Enter the 6-digit code from your authenticator app. Paste works too.

Didn't get a code? Use a backup method

Incorrect code. 2 attempts remaining.

Installation

npx shadcn@latest add otp-input.json

Usage

Loading...

Props

PropTypeDefaultDescription
lengthnumber6Number of digit cells
valuestringControlled value (uncontrolled if omitted)
onChange(value: string) => voidFires on every edit
onComplete(value: string) => voidFires when all cells are filled
invalidbooleanfalseError styling on all cells
autoFocusbooleanfalseFocus the first cell on mount