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

length6
number

Number of OTP digits

valueundefined
string

Controlled value

defaultValue""
string

Default value for uncontrolled usage

onValueChangeundefined
(value: string) => void

Callback when value changes

onCompleteundefined
(value: string) => void

Callback when all digits are filled

labelundefined
string

Label text displayed above the input

errorundefined
string

Error message to display

autoFocusfalse
boolean

Auto-focus the first input on mount

disabledfalse
boolean

Whether the input is disabled