Components
OTP Input
One box per digit for one-time codes.
<OtpInput />Installation
npx shadcn@latest add https://ui.zjkm.tech/r/otp-input.jsonimport { OtpInput } from "@/components/otp-input"Using JavaScript? Set tsx: false in components.json and the CLI converts it.
New to shadcn? Run npx shadcn@latest init first. The CLI needs components.json and the @/ import alias.
Usage
One box per digit. Typing moves to the next box, Backspace moves back, and pasting a code fills every box. The first box asks the browser to autofill codes from SMS, and the group has a name for screen readers.
import { OtpInput } from "@/components/otp-input";
export function Verify({ verify }: { verify: (code: string) => void }) {
return <OtpInput length={6} onComplete={verify} />;
}Props
| Prop | Type | Default | Description |
|---|---|---|---|
length | number | 6 | Number of digits. |
label | string | "One-time code" | Accessible name of the group. |
onComplete | (code: string) => void | Called when every box is filled. | |
className | string | Classes for the group. |
It has no animation, so reduced motion changes nothing.