Back to components
ElementFormFree

Input OTP React component

A one-time-code input with individual animated cells, paste and autofill support, numeric or alphanumeric mode, masking, grouped cells, error shake and success states.

About the Input OTP component

Input OTP is a one-time code field drawn as a row of separate boxes, one per character. A blinking caret marks the next box, characters pop in as they are typed, and the boxes turn green on success or red with a short shake on error. Under the boxes it is a single real input with autocomplete="one-time-code", so SMS code autofill on phones and pasting a whole code both fill every box at once.

length sets the number of boxes (6 by default) and type picks numeric, which also opens the number keypad on phones, or alphanumeric. value or defaultValue with onValueChange hold the code, and onComplete fires when the last box is filled. mask hides the characters as dots, groupSize splits the boxes into groups such as 3 and 3, and status with errorText or helperText shows the result. label, size, autoFocus and disabled set the rest.

When to use it

Use Input OTP for one-time passcodes: two-factor login, email verification and phone confirmation. The digits appear in separate boxes, but under the hood it's a single input with autocomplete="one-time-code", so SMS autofill on iOS and Android and pasting a whole code both just work.

Use onComplete to verify the code the moment the last digit is entered, and the error and success states to show the result in place.

Installation

Add the Input OTP component to your project with the shadcn CLI. It lands in components/input-otp.tsx as plain React + Tailwind CSS source you own and can edit.

Install
Copied!
npx shadcn@latest add @reactframe/input-otp

Or copy the source by hand and install its dependencies:

Install
Copied!
npm install motion clsx tailwind-merge

More Form components

Number Input
Free
Image Cropper
Free
Password Input
Free
Signature Pad
Free
Checkbox Group
Free
Rich Text Editor
Free