OTP Input
An animated 6-digit OTP verification input with success/error states and smooth animations.
Component preview
Install using CLI
npx shadcn@latest add "https://www.obsidianui.dev/r/otp-input.json"Install Manually
1
Install dependencies
npm install motion lucide-react clsx tailwind-merge
2
Add util file
Create a file lib/utils.ts:
import { ClassValue, clsx } from 'clsx';import { twMerge } from 'tailwind-merge';export function cn(...inputs: ClassValue[]) {return twMerge(clsx(inputs));}
3
Copy the source code
Copy the code into components/block/otp-input.tsx
Usage
Code
import { OTPInput } from "@/components/block/otp-input"export function Demo() {return (<OTPInputcorrectOTP="424242"onSuccess={() => console.log("Verified!")}onError={() => console.log("Invalid OTP")}/>)}
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| correctOTP | string | "424242" | The correct OTP code |
| onSuccess | () => void | - | Callback on success |
| onError | () => void | - | Callback on error |
Last updated on