Input OTP
A one-time password input that types into one input and draws each character in its own slot.
InputOTP ports input-otp 1.4.2, which Sveltery UI’s input OTP is built on. One real <input> sits over the slots, so typing, paste, selection and autofill are the browser’s own. For the Base UI part with one input per slot, see OTP Field.
Anatomy
Import the component and draw the slots from its state:
Examples
Slots as children
Without render, children renders. A slot component reads the state with getInputOTPContext():
Patterns
pattern drops input that doesn’t match. REGEXP_ONLY_DIGITS, REGEXP_ONLY_CHARS and REGEXP_ONLY_DIGITS_AND_CHARS are exported:
Reading the input
Rest props go to the input, attachments included:
API reference
Root
Holds the slots and the input that types into them. Rest props go to the input. Renders a <div> element.
defaultValue string ''
- Name
- Description
The code an empty
valuestarts from.- Type
string- Default
''
value string —
- Name
- Description
The code.
- Type
string- Binding
bind:value
containerClass ClassValue | null —
- Name
- Description
Class for the container that holds the slots and the input.
- Type
ClassValue | null
maxlength* number —
- Name
- Description
The number of slots.
- Type
number
noScriptCSSFallback string | null —
- Name
- Description
CSS that shows the plain input when JavaScript is off.
nullleaves it out.- Type
string | null
onComplete function —
- Name
- Description
Called with the value when the last slot fills.
- Type
(value: string) => void
pasteTransformer function —
- Name
- Description
Rewrites pasted text before it is inserted.
- Type
(pasted: string) => string
pattern string | RegExp —
- Name
- Description
Every value must match it, for example
REGEXP_ONLY_DIGITS. Input that doesn't match is dropped.- Type
string | RegExp
placeholder string —
- Name
- Description
Characters shown in the empty slots, one per slot, through
placeholderChar.- Type
string
pushPasswordManagerStrategy 'increase-width' | 'none' 'increase-width'
- Description
Widens the input so a password manager's badge sits outside the slots.
- Type
'increase-width' | 'none'- Default
'increase-width'
textAlign 'left' | 'center' | 'right' 'left'
- Name
- Description
The text alignment of the input.
- Type
'left' | 'center' | 'right'- Default
'left'
render Snippet<[state: InputOTPRootState]> —
- Name
- Description
Renders the slots from the state. Without it,
childrenrenders and reads the state withgetInputOTPContext().- Type
Snippet<[state: InputOTPRootState]>
slots InputOTPSlotState[]
- Name
slots- Description
One entry per slot.
- Type
InputOTPSlotState[]
isFocused boolean
- Name
isFocused- Description
Whether the input is focused.
- Type
boolean
isHovering boolean
- Name
isHovering- Description
Whether the pointer is over the input and it is not disabled.
- Type
boolean