InputOTP

Accessible one-time password input for authentication.

inputs
form
otp
verification
auth

Preview

Please enter the one-time password sent to your device.

Variants

Default OTP input layout.

Please enter the one-time password sent to your device.

Code

TSX
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import {
      InputOTP,
      InputOTPGroup,
      InputOTPSlot,
    } from "@/components/ui/input-otp"

    export function InputOTPDemo() {
      return (
        <InputOTP maxLength={6}>
          <InputOTPGroup>
            <InputOTPSlot index={0} />
            <InputOTPSlot index={1} />
            <InputOTPSlot index={2} />
            <InputOTPSlot index={3} />
            <InputOTPSlot index={4} />
            <InputOTPSlot index={5} />
          </InputOTPGroup>
        </InputOTP>
      )
    }

API Reference

PropTypeDefaultDescription
maxLengthnumber-Maximum number of characters or digits.
valuestring-The controlled value of the OTP input.
onChangefunction-Event handler called when the input's value changes.
patternRegExp-Regular expression pattern for digit filtering.
disabledboolean-Whether the input is disabled.