Input OTP

Forms

A one-time password input component with individual character cells. Supports auto-focus, paste handling, and keyboard navigation.

Import

import { InputOTP } from "@/components/ui/input-otp";

Usage

Basic OTP Input

Enter a 6-digit verification code

Different Lengths

Customize the number of digits

4-digit PIN

6-digit Code (default)

8-digit Code

With Auto Focus

First input receives focus on mount

Click preview to see auto-focus behavior

With Error

Display validation errors

Invalid code. Please try again.

Disabled

Disabled state

API Reference

PropTypeDefaultDescription
lengthnumber6Number of OTP digits
valuestringundefinedControlled value
defaultValuestring""Default value for uncontrolled usage
onValueChange(value: string) => voidundefinedCallback when value changes
onComplete(value: string) => voidundefinedCallback when all digits are filled
labelstringundefinedLabel text displayed above the input
errorstringundefinedError message to display
autoFocusbooleanfalseAuto-focus the first input on mount
disabledbooleanfalseWhether the input is disabled

Related Components