OTP Input, animated React component
A six-box one-time-code field: digits spring in as you type, the boxes ripple while the code is checked, shake on a wrong code, and fold into a Verified pill on success.
- Free
- Inputs & Controls
- Spring
Play with it
Move the controls and watch it change. Copy code gives you a snippet with only the props you changed.
Didn’t get it?
Props
| Prop | Type | Default | What it does |
|---|---|---|---|
| length | number | 6 | Number of digits. The boxes split into two groups at the middle. |
| verify | (code: string) => boolean | Promise<boolean> | — | Return true when the code is valid. Runs once every box is filled. |
| onVerified | (code: string) => void | — | Called after a code verifies. |
| onResend | () => void | — | Called when “Resend code” is pressed. |
| autoplay | string | — | Types this code by itself, on a loop, until someone clicks in. |
| accent | string | "#0071e3" | Focus ring, caret and success colour. |
Add it to your project
- 1
Prepare your project
You need Tailwind CSS and the
@/import alias. If shadcn isn't set up yet, initialise it once:npx shadcn@latest init
Then add the Nexus registry to your
components.json(theregistrieskey is the part that matters):{ "$schema": "https://ui.shadcn.com/schema.json", "style": "default", "rsc": true, "tsx": true, "tailwind": { "css": "src/app/globals.css", "baseColor": "neutral", "cssVariables": true, "prefix": "" }, "aliases": { "components": "@/components", "utils": "@/lib/utils", "ui": "@/components/ui", "lib": "@/lib", "hooks": "@/hooks" }, "registries": { "@nexus-labs": "https://www.nexus-ui.com/api/registry/{name}" } } - 2
Add the component
Run this from your project root. It adds the component, the utilities it uses and its packages.
npx shadcn@latest add @nexus-labs/otp-input
- 3
Check what was added
With the standard aliases, these files land in your project:
components/otp-input/index.tsotp-input.tsx - 4
Copying by hand? Install the packages
Skip this if you used the command above.
npm install framer-motion
- 5
Use it in a page
Import it and render it. The Code tab above has the full example.
// app/page.tsx import { OtpInput } from "@/components/otp-input"; export default function Page() { return ( <main> <OtpInput /> </main> ); }