Copy to clipboard
<InputOTP maxLength={6}>
<InputOTPGroup>
<InputOTPSlot index={0} />
<InputOTPSlot index={1} />
<InputOTPSlot index={2} />
</InputOTPGroup>
<InputOTPSeparator />
<InputOTPGroup>
<InputOTPSlot index={3} />
<InputOTPSlot index={4} />
<InputOTPSlot index={5} />
</InputOTPGroup>
</InputOTP>
<InputOTP maxLength={6}>
<InputOTPGroup>
<InputOTPSlot index={0} />
<InputOTPSlot index={1} />
<InputOTPSlot index={2} />
</InputOTPGroup>
<InputOTPSeparator />
<InputOTPGroup>
<InputOTPSlot index={3} />
<InputOTPSlot index={4} />
<InputOTPSlot index={5} />
</InputOTPGroup>
</InputOTP> <InputOTP maxLength={6}>
<InputOTPGroup>
<InputOTPSlot index={0} />
<InputOTPSlot index={1} />
<InputOTPSlot index={2} />
</InputOTPGroup>
<InputOTPSeparator />
<InputOTPGroup>
<InputOTPSlot index={3} />
<InputOTPSlot index={4} />
<InputOTPSlot index={5} />
</InputOTPGroup>
</InputOTP>
Installation
Copy to clipboard
npx bearnie add input-otp
npx bearnie add input-otp npx bearnie add input-otp
bunx bearnie add input-otp
bunx bearnie add input-otp bunx bearnie add input-otp
pnpm dlx bearnie add input-otp
pnpm dlx bearnie add input-otp pnpm dlx bearnie add input-otp
yarn dlx bearnie add input-otp
yarn dlx bearnie add input-otp yarn dlx bearnie add input-otp
Usage
import {
InputOTP,
InputOTPGroup,
InputOTPSlot,
InputOTPSeparator,
} from "@/components/bearnie/input-otp"<InputOTP maxLength={6}>
<InputOTPGroup>
<InputOTPSlot index={0} />
<InputOTPSlot index={1} />
<InputOTPSlot index={2} />
</InputOTPGroup>
<InputOTPSeparator />
<InputOTPGroup>
<InputOTPSlot index={3} />
<InputOTPSlot index={4} />
<InputOTPSlot index={5} />
</InputOTPGroup>
</InputOTP> Pattern
Use the pattern prop to define what characters are allowed in the OTP input.
Digits only (default)
Copy to clipboard
<InputOTP maxLength={6} pattern="digits">
<InputOTPGroup>
<InputOTPSlot index={0} />
<InputOTPSlot index={1} />
<InputOTPSlot index={2} />
<InputOTPSlot index={3} />
<InputOTPSlot index={4} />
<InputOTPSlot index={5} />
</InputOTPGroup>
</InputOTP>
<InputOTP maxLength={6} pattern="digits">
<InputOTPGroup>
<InputOTPSlot index={0} />
<InputOTPSlot index={1} />
<InputOTPSlot index={2} />
<InputOTPSlot index={3} />
<InputOTPSlot index={4} />
<InputOTPSlot index={5} />
</InputOTPGroup>
</InputOTP> <InputOTP maxLength={6} pattern="digits">
<InputOTPGroup>
<InputOTPSlot index={0} />
<InputOTPSlot index={1} />
<InputOTPSlot index={2} />
<InputOTPSlot index={3} />
<InputOTPSlot index={4} />
<InputOTPSlot index={5} />
</InputOTPGroup>
</InputOTP>
Alphanumeric
Use pattern="alphanumeric" to accept both letters and numbers.
Copy to clipboard
<InputOTP maxLength={6} pattern="alphanumeric">
<InputOTPGroup>
<InputOTPSlot index={0} />
<InputOTPSlot index={1} />
<InputOTPSlot index={2} />
<InputOTPSlot index={3} />
<InputOTPSlot index={4} />
<InputOTPSlot index={5} />
</InputOTPGroup>
</InputOTP>
<InputOTP maxLength={6} pattern="alphanumeric">
<InputOTPGroup>
<InputOTPSlot index={0} />
<InputOTPSlot index={1} />
<InputOTPSlot index={2} />
<InputOTPSlot index={3} />
<InputOTPSlot index={4} />
<InputOTPSlot index={5} />
</InputOTPGroup>
</InputOTP> <InputOTP maxLength={6} pattern="alphanumeric">
<InputOTPGroup>
<InputOTPSlot index={0} />
<InputOTPSlot index={1} />
<InputOTPSlot index={2} />
<InputOTPSlot index={3} />
<InputOTPSlot index={4} />
<InputOTPSlot index={5} />
</InputOTPGroup>
</InputOTP>
Examples
Separator
Use the InputOTPSeparator component to add a separator between input groups.
Copy to clipboard
<InputOTP maxLength={6}>
<InputOTPGroup>
<InputOTPSlot index={0} />
<InputOTPSlot index={1} />
<InputOTPSlot index={2} />
</InputOTPGroup>
<InputOTPSeparator />
<InputOTPGroup>
<InputOTPSlot index={3} />
<InputOTPSlot index={4} />
<InputOTPSlot index={5} />
</InputOTPGroup>
</InputOTP>
<InputOTP maxLength={6}>
<InputOTPGroup>
<InputOTPSlot index={0} />
<InputOTPSlot index={1} />
<InputOTPSlot index={2} />
</InputOTPGroup>
<InputOTPSeparator />
<InputOTPGroup>
<InputOTPSlot index={3} />
<InputOTPSlot index={4} />
<InputOTPSlot index={5} />
</InputOTPGroup>
</InputOTP> <InputOTP maxLength={6}>
<InputOTPGroup>
<InputOTPSlot index={0} />
<InputOTPSlot index={1} />
<InputOTPSlot index={2} />
</InputOTPGroup>
<InputOTPSeparator />
<InputOTPGroup>
<InputOTPSlot index={3} />
<InputOTPSlot index={4} />
<InputOTPSlot index={5} />
</InputOTPGroup>
</InputOTP>
Disabled
Use the disabled prop to disable the input.
Copy to clipboard
<InputOTP maxLength={6} disabled>
<InputOTPGroup>
<InputOTPSlot index={0} />
<InputOTPSlot index={1} />
<InputOTPSlot index={2} />
<InputOTPSlot index={3} />
<InputOTPSlot index={4} />
<InputOTPSlot index={5} />
</InputOTPGroup>
</InputOTP>
<InputOTP maxLength={6} disabled>
<InputOTPGroup>
<InputOTPSlot index={0} />
<InputOTPSlot index={1} />
<InputOTPSlot index={2} />
<InputOTPSlot index={3} />
<InputOTPSlot index={4} />
<InputOTPSlot index={5} />
</InputOTPGroup>
</InputOTP> <InputOTP maxLength={6} disabled>
<InputOTPGroup>
<InputOTPSlot index={0} />
<InputOTPSlot index={1} />
<InputOTPSlot index={2} />
<InputOTPSlot index={3} />
<InputOTPSlot index={4} />
<InputOTPSlot index={5} />
</InputOTPGroup>
</InputOTP>
Invalid
Use invalid on the slots to show an error state.
Copy to clipboard
<InputOTP maxLength={4}>
<InputOTPGroup>
<InputOTPSlot index={0} invalid />
<InputOTPSlot index={1} invalid />
<InputOTPSlot index={2} invalid />
<InputOTPSlot index={3} invalid />
</InputOTPGroup>
</InputOTP>
<InputOTP maxLength={4}>
<InputOTPGroup>
<InputOTPSlot index={0} invalid />
<InputOTPSlot index={1} invalid />
<InputOTPSlot index={2} invalid />
<InputOTPSlot index={3} invalid />
</InputOTPGroup>
</InputOTP> <InputOTP maxLength={4}>
<InputOTPGroup>
<InputOTPSlot index={0} invalid />
<InputOTPSlot index={1} invalid />
<InputOTPSlot index={2} invalid />
<InputOTPSlot index={3} invalid />
</InputOTPGroup>
</InputOTP>
Four digits
A common pattern for PIN codes.
Copy to clipboard
<InputOTP maxLength={4}>
<InputOTPGroup>
<InputOTPSlot index={0} />
<InputOTPSlot index={1} />
<InputOTPSlot index={2} />
<InputOTPSlot index={3} />
</InputOTPGroup>
</InputOTP>
<InputOTP maxLength={4}>
<InputOTPGroup>
<InputOTPSlot index={0} />
<InputOTPSlot index={1} />
<InputOTPSlot index={2} />
<InputOTPSlot index={3} />
</InputOTPGroup>
</InputOTP> <InputOTP maxLength={4}>
<InputOTPGroup>
<InputOTPSlot index={0} />
<InputOTPSlot index={1} />
<InputOTPSlot index={2} />
<InputOTPSlot index={3} />
</InputOTPGroup>
</InputOTP>
Custom separator
You can pass custom content to the separator.
Copy to clipboard
-
<InputOTP maxLength={6}>
<InputOTPGroup>
<InputOTPSlot index={0} />
<InputOTPSlot index={1} />
<InputOTPSlot index={2} />
</InputOTPGroup>
<InputOTPSeparator>
<span class="text-muted-foreground">-</span>
</InputOTPSeparator>
<InputOTPGroup>
<InputOTPSlot index={3} />
<InputOTPSlot index={4} />
<InputOTPSlot index={5} />
</InputOTPGroup>
</InputOTP>
<InputOTP maxLength={6}>
<InputOTPGroup>
<InputOTPSlot index={0} />
<InputOTPSlot index={1} />
<InputOTPSlot index={2} />
</InputOTPGroup>
<InputOTPSeparator>
<span class="text-muted-foreground">-</span>
</InputOTPSeparator>
<InputOTPGroup>
<InputOTPSlot index={3} />
<InputOTPSlot index={4} />
<InputOTPSlot index={5} />
</InputOTPGroup>
</InputOTP> <InputOTP maxLength={6}>
<InputOTPGroup>
<InputOTPSlot index={0} />
<InputOTPSlot index={1} />
<InputOTPSlot index={2} />
</InputOTPGroup>
<InputOTPSeparator>
<span class="text-muted-foreground">-</span>
</InputOTPSeparator>
<InputOTPGroup>
<InputOTPSlot index={3} />
<InputOTPSlot index={4} />
<InputOTPSlot index={5} />
</InputOTPGroup>
</InputOTP>
Anatomy
InputOTP- The main container that manages OTP stateInputOTPGroup- Groups slots together with connected stylingInputOTPSlot- Individual input slot for each digitInputOTPSeparator- Visual separator between groups
Props
InputOTP
| Prop | Type | Default | Description |
|---|---|---|---|
| maxLength | number | required | Maximum length of the OTP (number of slots) |
| pattern | digits | alphanumeric | string | digits | Pattern to validate input |
| disabled | boolean | false | Disables all slots |
| value | string | - | Initial value |
| name | string | - | Name attribute for form submission |
| class | string | - | Additional CSS classes |
InputOTPGroup
| Prop | Type | Default | Description |
|---|---|---|---|
| class | string | - | Additional CSS classes |
InputOTPSlot
| Prop | Type | Default | Description |
|---|---|---|---|
| index | number | required | Index of the slot (0-based) |
| invalid | boolean | false | Shows error state |
| class | string | - | Additional CSS classes |
InputOTPSeparator
| Prop | Type | Default | Description |
|---|---|---|---|
| class | string | - | Additional CSS classes |