Enter the 6-digit code. Paste works too.
Playground
Change the props and copy the code. The controls come from the component's TypeScript types.
Props
length6
group3
import { OtpInput } from "@/components/ui/otp-input";<OtpInput />Installation
$ pnpm dlx shadcn@latest add @synccn/otp-inputFirst time in this project? Connect synccn with one command.
Usage
import { OtpInput } from "@/components/ui/otp-input";<OtpInput length={6} onComplete={verify} />API reference
Generated from the component's TypeScript types, so it always matches the code.
OtpInput
One-time code field. Supports paste, arrows, backspace and a grouped layout.
PropTypeDescription
- length
numberDefault
6Number of digits.
- group
numberDefault
3Digits per group, separated by a dash. 0 for none.
- onComplete
(code: string) => voidCalled when every digit is filled.
- invalid
booleanShows the error style.
- className
stringExtra classes for the root element.
Dependencies
Read from the component's imports when the site builds. The CLI installs all of these for you.
Helpers
- lib/utilscn (merges class names)
npm packages
- clsx for cn()
- tailwind-merge for cn()
Keyboard
- ←or→Move between boxes
- BackspaceClear the box, or go back to the previous one
Accessibility
- Pasting a whole code fills every box. The boxes share one group label.
From the source
Read from this component's code when the site builds, so it can't drift.
- ARIA roles: group
- ARIA attributes: aria-label
- Keys handled: ArrowLeft, ArrowRight, Backspace
More inputs
ButtonSeven variants, four sizes and a built-in loading state.InputText field with optional leading icon and invalid state.TextareaMulti-line field that grows with its content and counts characters.CheckboxChecked, unchecked and indeterminate, with label and description.SwitchToggle with a springy thumb in three sizes.Radio GroupPick one option, shown as dots or as selectable cards.