Input OTP

Accessible one-time password component with copy-paste functionality.

Usage

Pattern

Use the pattern prop to define a custom pattern for the OTP input. The input-otp package exports REGEXP_ONLY_DIGITS (digits only), REGEXP_ONLY_DIGITS_AND_CHARS (alphanumeric), and REGEXP_ONLY_CHARS (letters only) for common use cases.

Disabled

1
2
3
4
5
6

Invalid state

Use aria-invalid on the InputOTPGroup to show an error state.

0
0
0
0
0
0

Props

InputOTP

PropTypeDefaultDescription
maxLengthnumber-Maximum number of characters
valuestring-Controlled value
onChange(value: string) => void-Callback when value changes
patternRegExp | string-Pattern to validate input (e.g. REGEXP_ONLY_DIGITS)
disabledbooleanfalseWhether the input is disabled
containerClassNamestring-Additional class for the container
onComplete(value: string) => void-Callback when all slots are filled

InputOTPGroup

PropTypeDefaultDescription
aria-invalidboolean-Marks the group as invalid for error styling

InputOTPSlot

PropTypeDefaultDescription
indexnumber-Zero-based index of the slot

API Reference

See the input-otp documentation for the full API and additional props.