Docs
OTP Input
OTP Input

A secure one-time password input component with auto-focus, validation, masking options, and Zod integration for authentication flows.

-

Enter the 6-digit verification code

Overview

The OTP Input component provides a secure and user-friendly way to capture one-time passwords and verification codes, essential for authentication flows and security verification. It features auto-focus navigation, paste handling, optional masking, and customizable grouping with separators. Perfect for creating modern authentication experiences with seamless keyboard navigation and accessibility support.

Installation

pnpm dlx shadcn@latest add https://deltacomponents.dev/r/otp-input.json

Usage

"use client"
 
import { OtpInput } from "@/registry/inputs/otp-input"
 
export function Component() {
  return (
    <OtpInput
      label="Verification Code"
      name="verificationCode"
      length={6}
      required
      separator
      groupSize={3}
      hint="Enter the 6-digit verification code"
      onComplete={(value) => console.log("OTP completed:", value)}
    />
  )
}

API Reference

Props

PropTypeDefaultDescription
labelstring-Label for the OTP input field (required)
namestring-Name of the input field for form submission (required)
descriptionstringundefinedDescription text below the label
hintstringundefinedHint text below the OTP input
errorstringundefinedError message to display
requiredbooleanfalseWhether the field is required
pendingbooleanfalseWhether the field is in a loading state
defaultValuestring""Default value for the OTP input
valuestringundefinedControlled value
disabledbooleanfalseWhether the OTP input is disabled
lengthnumber6Length of the OTP code
idstringnameID for the OTP input element
variant"default" | "pill""default"Visual variant of the input
coloredBorderbooleanfalseWhether to show colored border (pill variant)
inputType"numeric" | "alphabetic" | "alphanumeric""alphanumeric"Input type validation with error animation
successbooleanfalseWhether the OTP is in a success state (green border animation)
labelVariant"default" | "muted""default"Label text styling variant
containerClassNamestring""CSS classes for the container
labelClassNamestring""CSS classes for the label
maskCharstring"•"Character to display when input is masked
maskbooleanfalseWhether to mask the input (like a password)
autoFocusbooleanfalseWhether to auto-focus the first input on mount
separatorbooleanfalseWhether to render with separator between groups
groupSizenumber3Size of each group of digits
autoSubmitbooleanfalseWhether to auto-submit form when OTP is completed
schemaZodType<string>undefinedZod schema for validation
onValidate(isValid: boolean, value: string, error?: string) => voidundefinedValidation callback
onChange(value: string) => voidundefinedCallback when OTP value changes
onComplete(value: string) => voidundefinedCallback when OTP is completed

Examples

Pill Variant

Rounded pill variant with muted background styling.

Enter the 6-digit code

Autofill Support

OTP input with enhanced autofill support for SMS verification codes.

Enter 6 digits to see auto-complete

Short OTP

A 4-digit PIN input with grouping and separator for quick verification.

-

Enter your 4-digit PIN

Numeric Only

Numeric-only OTP input with number pattern validation.

Enter only numbers (0-9)

OTP Input Validation

Try entering wrong character types to see error animations. Complete valid codes to see success animations.

Numeric Only (6 digits)

Try entering letters to see error animation

Enter only numbers (0-9)

Alphabetic Only (4 letters)

Try entering numbers to see error animation

Enter only letters (A-Z)

Alphanumeric (6 characters)

Try entering special characters to see error animation

Enter letters and numbers only