Entrada de código de uso único: um campo oculto real cuida da digitação, da colagem e do preenchimento automático por SMS, enquanto casas animadas exibem o código com um cursor piscando, um separador e um tremor em caso de erro.
A one-time code from SMS or email must be entered, with paste and autofill support
A two-factor or login verification step needs a clear per-character layout with error feedback
A short numeric PIN must be entered masked
Avoid when
The value is a password or free-length secret rather than a fixed-length code → use Input instead
The code is long or has variable length, like a license key; a plain text field handles it better
Instalação
node scripts/add.mjs otp --out ./src/marvelous
Agente de IA com o servidor MCP do Marvelous UI: install_components({ slugs: ["otp"], target_dir: "<absolute path>/src/marvelous", framework: "react" }).
Accepted characters; “numeric” opens the number pad on mobile.
case
upper | lower
Forces the case of typed characters.
separator
boolean | "3" | "2,4"
Visual separator: in the middle if empty, otherwise after the given positions.
mask
boolean
Masks the characters (•), for a PIN.
placeholder
string
Character(s) shown in empty slots (e.g. “-” or “000000”).
value
string
Initial value (and form reset value).
name
string
Field name in the form.
required
boolean
Invalid until every slot is filled.
invalid
boolean
Error state (red border + shake when set); cleared on the next input.
valid
boolean
Success state (green border and tint); cleared on the next input.
disabled
boolean
Disables input.
label
string
Accessible name when no <label for> is associated.
data-size
sm | lg
Slot size.
Properties
Name
Tipo
Description
value
string
Current code (filtered and truncated).
complete
boolean
Read-only: every slot is filled.
form / validity / validationMessage
-
Native form API (ElementInternals).
Methods
Name
Description
focus()
Focuses the real input.
clear()
Clears the code and the valid/invalid states.
shake()
Plays the shake animation.
checkValidity() / reportValidity()
Native validation.
Events
Name
Description
mv-change
detail: { value, complete } on every change.
mv-complete
detail: { value } when the last slot is filled.
CSS classes
Name
Description
mv-otp-slot / -char / -caret / -separator
Generated parts (data-active, data-filled).
CSS variables
Name
Default
Description
--mv-otp-slot-width
2.75rem
Slot width.
--mv-otp-slot-height
3rem
Slot height.
--mv-otp-gap
var(--mv-space-2)
Space between slots.
--mv-otp-radius
var(--mv-radius-md)
Slot radius.
Accessibility
A single real <input> (autocomplete="one-time-code", numeric inputmode) holds focus and the accessible name (from <label for>, label or aria-label); the visual slots are aria-hidden. Arrow keys, Home/End, Backspace and Delete move between slots; pasting spreads the code. aria-invalid reflects the error state; form-associated element with native validation.