Shadcn Input OTP
React OTP input component for 2FA authentication and verification codes. Built with TypeScript and Tailwind CSS for Next.js with smart focus management.
OTP input not working?
Join our Discord community for help from other developers.
Ever tried to type a 6-digit code into separate boxes and wanted to throw your phone? Or watched users give up on 2FA because your OTP input was fighting them every step of the way? Yeah, that's exactly why good OTP inputs matter. This shadcn/ui input brings sanity to authentication flows in your React applications.
Input OTP showcase
Clean, accessible OTP input with automatic focus handling:
Built on input-otp by @guilherme_rodz with smart cursor management and paste support. Styled with Tailwind CSS so it matches your design system instead of looking like separate text boxes glued together.
npx shadcn@latest add input-otp
Why good OTP inputs actually matter for user experience
Here's the thing—authentication is already stressful. Users are trying to log in, reset passwords, or verify their identity. The last thing they need is an OTP input that fights them. Click each box manually? Nope. Paste doesn't work? Frustrating. Mobile keyboard shows letters instead of numbers? Deal-breaker.
Think about how banking apps handle verification codes, or how Stripe processes payment confirmations. Users type one digit, cursor moves automatically. They paste a code, it fills all boxes intelligently. The mobile keyboard shows numbers for numeric codes. It just works, and users focus on what matters instead of battling your interface.
This free shadcn input OTP handles the complex parts—focus management, paste detection, keyboard navigation, accessibility—while you focus on your authentication logic. Whether you're building login systems, payment flows, or security verification in your Next.js applications, OTP inputs that work seamlessly keep users moving through your JavaScript projects.
Common OTP patterns you'll actually use
Simple 4-digit PIN
Basic PIN entry for quick authentication:
6-digit verification code
The classic SMS code layout with separator:
Custom pattern support
Letters and numbers for backup codes:
Multiple visual groups
Enhanced readability with separators:
Controlled with validation
Real-time feedback for users:
Form integration
Works seamlessly with validation:
Features
This free open source OTP input component includes everything you need:
- TypeScript-first - Full type safety with OTP state and validation patterns
- Smart focus management - Automatic cursor advancement and backspace handling
- Paste intelligence - Detects and fills multiple slots from clipboard
- Tailwind CSS styled - Customize with utilities, not fighting component CSS
- Mobile optimized - Appropriate keyboards for different input patterns
- Pattern validation - RegExp support for numbers, letters, or custom formats
- Accessibility built-in - Screen readers, keyboard navigation, focus indicators
- Form library ready - Works with React Hook Form and validation schemas
API Reference
Core Components
Component | Purpose | Key Props |
---|---|---|
InputOTP | Root container | maxLength , value , onChange , pattern , onComplete |
InputOTPGroup | Visual grouping | Groups slots with spacing |
InputOTPSlot | Individual digit | index for position |
InputOTPSeparator | Visual separator | Divides groups |
Common Patterns
Pattern | Use Case | RegExp |
---|---|---|
Numbers only | SMS codes, PINs | REGEXP_ONLY_DIGITS |
Mixed format | Backup codes, tokens | REGEXP_ONLY_DIGITS_AND_CHARS |
Custom | Specific requirements | Your own RegExp pattern |
Input Behavior
Action | Result |
---|---|
Type digit | Enters character, moves to next slot |
Paste code | Fills all slots automatically |
Backspace | Deletes current, moves to previous |
Arrow keys | Navigate between slots |
Production tips
Choose appropriate patterns. This free shadcn/ui OTP input supports different character patterns—use numbers for SMS codes, mixed alphanumeric for backup codes. This TypeScript component validates patterns automatically, but pick what matches your authentication system in your Next.js applications.
Handle mobile keyboards smartly. The component triggers numeric keyboards for digit-only patterns and full keyboards for mixed formats. This open source shadcn input adapts automatically, but test on real devices to ensure the experience feels natural.
Provide clear instructions. Tell users where to find their code—"Check your text messages" or "Open your authenticator app." This JavaScript component handles the input, you handle the context that helps users succeed in your React applications.
Time out gracefully. OTP codes expire. Show countdown timers, provide resend options, and handle expired codes with clear messaging. The Tailwind CSS styled component shows the input—your authentication flow handles the lifecycle.
Consider accessibility. Screen readers announce each slot and its position. Ensure good color contrast and focus indicators. This component provides the foundation—you ensure all users can complete authentication successfully.
Integration with other components
OTP inputs naturally work with Form components for validation and error handling in your React applications. Use Button components for resend actions and form submission with consistent styling.
For loading states, combine with Spinner patterns during code verification. Alert components work well for showing verification errors or success messages. This open source pattern keeps your authentication flows consistent and professional.
When building multi-step auth, pair OTP inputs with Dialog components for modal verification flows or Card components for structured authentication pages. The input handles code entry—other shadcn components handle the surrounding experience.
For security-focused interfaces, use OTP inputs with Badge components to show security levels or Separator components to organize complex authentication forms. Your JavaScript application can compose these components while maintaining clear user flows.
Questions you might have
Shadcn Hover Card
React hover card component for contextual popups and user profile previews. Built with TypeScript and Tailwind CSS for Next.js applications using Radix UI.
Shadcn Input
React input component for forms, search fields, and user data collection. Built with TypeScript and Tailwind CSS for Next.js applications with form validation.