Input
OTP Input
NewA one-time code field with a cell per digit, a blinking caret and paste support.
npx motionsnack add otp-inputCustomize
<OtpInput />Props
24 properties
| Property | Type | Default | Description |
|---|---|---|---|
| value | string | - | Controlled value. Leave undefined to let the component manage it. |
| defaultValue | string | '' | Value on first render when uncontrolled. |
| onChange | (value: string) => void | - | Called with the code on every change. |
| onComplete | (value: string) => void | - | Called once all cells are filled. |
| errorColor | string | undefined | Error colour for both themes. Undefined uses the per-theme pair (#dc2626 light, #ef4444 dark). |
| lengthLabel | string | '{n} digits' | Length read after the label to screen readers. |
| resendLabel | string | 'Resend code' | Text of the resend button. |
| resendCountdownLabel | string | 'Resend code in {time}' | Resend button text while it counts down. |
| onResend | () => void | - | Called when the resend button is pressed. |
| cellSize | number | - | Deprecated: use height. |
| gap | number | - | Deprecated: the gap is fixed at 8px. |
| name | string | - | Name submitted with a form. |
| id | string | generated | Id of the input. |
| className | string | '' | Extra classes on the wrapper. |
| label | string | 'Verification code' | Label above the cells. Empty hides it. |
| length | number | 6 | Number of characters in the code. |
| split | boolean | true | Put a dash in the middle of the code (even lengths only). |
| mode | 'numeric' | 'alphanumeric' | 'numeric' | Digits only, or letters and digits. |
| helperText | string | 'We sent a 6-digit code to your e-mail.' | Small text under the cells. Empty hides it. |
| error | string | '' | Error message. Any text turns the cell borders red and replaces the helper text. |
| disabled | boolean | false | Disables the field. |
| showResend | boolean | false | Show a Resend code button with a 30s countdown. |
| height | number | 48 | Width and height of one cell (48, or 40 compact). |
| radius | number | 12 | Corner radius of a cell. |
About OTP Input
OTP Input asks for a verification code from an e-mail or a text message. Each character has its own cell; typed digits pop in and the active cell shows a blinking caret and the library's clear focus outline. Under the cells sits one real input, so pasting a whole code, autofill from a text message and screen readers all work without extra code. A dash can split the code in the middle, the length runs from 2 to 10 and letters can be allowed. When the last cell is filled onComplete fires; an error message turns the cell borders red and shows the message under them.
What's included
- One cell per character, 2 to 10 long
- Paste and SMS autofill through one real input
- Blinking caret and focus outline on the active cell
- Optional dash in the middle
- onComplete when the code is full
- Error state with red borders and a message
- Light and dark look
- Type
- Animated React input component
- Library
- Components · Input
- Stack
- Next.js, React, Tailwind CSS
- Added
- 2026-11-23
- Install
npx motionsnack add otp-input