Join our Discord Community

Input OTP

A one-time password input component for React and Next.js. Perfect for 2FA authentication, verification codes, and secure login flows with shadcn/ui styling.

Ever tried to type a 6-digit code into separate boxes and wanted to throw your phone? This OTP input actually works the way users expect - cursor jumps automatically, paste works, no fighting with focus.

2FA verification input

Clean, accessible OTP input with automatic focus handling:

Loading component...

Built on input-otp by @guilherme_rodz, styled with Tailwind, and ready to drop into any Next.js auth flow.

npx shadcn@latest add input-otp

Why good OTP inputs matter

You know those OTP inputs where you have to click each box manually? Yeah, this isn't one of those. Type a digit, cursor moves automatically. Copy-paste a code, it fills in all the boxes. Mobile keyboard shows numbers. It just works.

OTP patterns that users actually like

Simple 4-digit PIN

Simple PIN entry:

Loading component...

6-digit with separator

The classic SMS code layout:

Loading component...

Custom patterns

Letters and numbers for backup codes:

Loading component...

Multiple separators

When you need more visual grouping:

Loading component...

Controlled with feedback

Show users what they're typing:

Loading component...

Form integration

Proper form validation:

Loading component...

Built for Next.js auth flows

Works with whatever auth setup you've got - NextAuth.js, Clerk, Auth0, doesn't matter. Hook up the onChange and you're good to go.

API Reference

InputOTP

The root component that manages the OTP input state and behavior.

PropTypeDefaultDescription
maxLengthnumber6Maximum number of characters
valuestring-Controlled input value
onChange(value: string) => void-Change handler for controlled usage
onComplete(value: string) => void-Called when all slots are filled
patternRegExpREGEXP_ONLY_DIGITSRegex pattern for valid characters
disabledbooleanfalseWhether the input is disabled
autoFocusbooleanfalseAuto-focus the first slot on mount
childrenReact.ReactNode-InputOTPGroup and InputOTPSeparator components

InputOTPGroup

Container for grouping OTP slots together visually.

PropTypeDefaultDescription
classNamestring-Additional CSS classes
childrenReact.ReactNode-InputOTPSlot components

InputOTPSlot

Individual character input slot within the OTP.

PropTypeDefaultDescription
indexnumber-Position index in the OTP sequence
classNamestring-Additional CSS classes

InputOTPSeparator

Visual separator between groups of OTP slots.

PropTypeDefaultDescription
classNamestring-Additional CSS classes

Common Patterns

PatternRegExpUse Case
Numbers onlyREGEXP_ONLY_DIGITSSMS codes, PIN numbers
Numbers + LettersREGEXP_ONLY_DIGITS_AND_CHARSBackup codes, complex tokens
CustomYour own RegExpSpecific format requirements

Keyboard Interactions

KeyAction
0-9, A-ZEnter character (if pattern allows)
BackspaceDelete current character, move to previous
DeleteClear current character
Arrow Left/RightNavigate between slots
TabMove to next focusable element
Shift + TabMove to previous focusable element
Ctrl/Cmd + VPaste and auto-fill slots

Accessibility Features

FeatureImplementation
Screen ReadersEach slot is announced with position
Focus ManagementClear focus indicators and logical tab order
ARIA LabelsProper labeling for assistive technology
High ContrastRespects system color preferences
Keyboard NavigationFull keyboard control without mouse
Error StatesScreen readers announce validation errors

Common patterns

Two-factor authentication - TOTP codes from authenticator apps or SMS verification.

Password reset - Email verification codes in your reset flow.

Payment verification - Extra security for transactions.

Account confirmation - Verify email addresses during signup.

Make OTP forms that work

  • Auto-advance focus - Don't make users click each box
  • Allow paste - Let them paste the whole code at once
  • Mobile keyboards - Number pad for digits, full keyboard for mixed codes
  • Clear errors - "Code expired" beats "Invalid code"
  • Resend options - Always include "didn't get it?"
  • Good instructions - Tell them where to find the code