OTP Input
OtpInputBlock handles it all automatically: seamless copy/pasting, ArrowLeft and ArrowRight navigation, intuitive Backspace handling that smoothly shifts focus backward, and built-in hooks for both onChange and onComplete.OTP Input
Paste, arrow-key and backspace handling are built in.
value- and
onChangework with the assembled string, not an array — the internal per-box state syncs to it. onComplete- fires once every box is filled, which saves you comparing lengths yourself.
Installation
New project? Follow the installation guide to set up Tailwind CSS, shadcn, the cn helper and lucide-react, register the @algorize-ui registry once, then copy your styles from the Themes page.
Install OTP Input
components/ is written into your project. Copy any snippet from a Usage tab above and it runs.
Install dependencies
Nothing beyond the shared setup — OTP Input needs only the cn helper and lucide-react, which the installation guide already put in place.
Examples
Underlined
- Use
variant"underlined" - to reduce each box to a baseline rule.
Features
Customizable
Easily adapt the component's styling and behavior to fit your application's unique design system.
Accessible
Built with accessibility in mind, ensuring all users can interact with your application effectively.
Responsive
Fully responsive design that looks and works great across desktop, tablet, and mobile devices.
Performant
Optimized for maximum performance with minimal re-renders and efficient state management.
Best Practices & Guidelines
Usage Guidelines
Follow standard design principles when implementing this component. Ensure proper contrast, spacing, and context within your layout.
Props Reference
| Component | Prop | Type | Default | Description |
|---|---|---|---|---|
OtpInputBlock | length | number | 6 | The number of individual input boxes to generate for the OTP code. |
OtpInputBlock | value | string | "" | The controlled string value. The internal array state automatically
syncs with this value. |
OtpInputBlock | onChange | (value: string) => void | undefined | Fires every time a single digit is added, changed, or removed,
returning the newly assembled string. |
OtpInputBlock | onComplete | (value: string) => void | undefined | A convenience callback that fires automatically as soon as all input
boxes have been filled. |
OtpInputBlock | variant | "default" | "filled" | "underlined" | "default" | Determines the structural styling and border treatment of the
individual input boxes. |
OtpInputBlock | color | "indigo" | "rose" | "emerald" | "zinc" | string | "primary" | The theme color applied to the borders, text, and focus rings. Fully
supports custom hex codes. |
OtpInputBlock | mask | boolean | false | If true, converts the underlying HTML inputs to
type="password" to obscure the characters. |
OtpInputBlock | disabled | boolean | false | If true, disables all interactions across all input boxes and reduces
their overall opacity. |