docs/components/input-otp
Sections
Components
Utilities
Forms
Hooks
Copy Markdown
Accessible one-time password input.
PreviewCode
CLIManual
pnpmbunnpmyarn
pnpm dlx shadcn@latest add @shark/input-otp
InputOTP
├── InputOTPSlot
└── InputOTPSeparator
import {
InputOTP,
InputOTPSeparator,
InputOTPSlot,
} from "@/components/ui/input-otp";
<InputOTP>
<InputOTPSlot index={0} />
<InputOTPSlot index={1} />
<InputOTPSlot index={2} />
<InputOTPSeparator />
<InputOTPSlot index={3} />
<InputOTPSlot index={4} />
<InputOTPSlot index={5} />
</InputOTP>
Use value and onValueChange to control the input.
PreviewCode
Enter the code 1234
❌
Use the disabled prop to disable the input.
PreviewCode
Use the invalid prop to mark the input as invalid and show error styling.
PreviewCode
Use four InputOTPSlot elements for a 4-digit OTP.
PreviewCode
Add InputOTPSeparator between groups of slots.
PreviewCode
Use the placeholder prop to show a placeholder in each slot.
PreviewCode
Use the blurOnComplete prop to blur the input when all slots are filled.
PreviewCode
Use the mask prop to mask the input value.
PreviewCode
Pass *:data-[slot=input-otp-input]:size-* and *:data-[slot=input-otp-input]:text-* to InputOTP to override slot dimensions and text size.
PreviewCode
| Prop | Type | Default |
|---|---|---|
withFakeCaret | boolean | false |
value | string | - |
defaultValue | string | - |
onValueChange | ({ value, valueAsString }) => void | - |
disabled | boolean | - |
invalid | boolean | - |
otp | boolean | true |
blurOnComplete | boolean | - |
mask | boolean | - |
Single OTP slot. Use index to specify position, 0 is the first slot.
| Prop | Type | Default |
|---|---|---|
index | number | required |
Visual separator between slots.
For a complete list of props, see the Ark UI documentation.
[
Previous page
Input Group ](/docs/components/input-group)[
Next page
Input ](/docs/components/input)
On This Page
InstallationAnatomyUsageControlledStatesDisabledInvalidExamplesFour DigitsSeparatorWith PlaceholderBlur on CompleteMaskCustom SizeAPI ReferenceInputOTPInputOTPSlotInputOTPSeparator