Components/Forms/Input OTP
COMPONENT13.13

Input OTP

One-time code field: N joined single-char inputs with auto-advance, paste distribution and a hidden form mirror.


INSTALL

1pnpm dlx @sayagodev/mo add input-otp

Or import the files from the package (no copy):

1import "@sayagodev/mo/css/input-otp.css";2import "@sayagodev/mo/js/input-otp.js";

EXAMPLES

Basic

Enter the 6-digit code sent to your email.

Four digits
Separator
Single field with visual separator (recommended)
Two linked fields (auto-advances to next)
Separator between groups — type across both fields.
Pattern
Disabled
Invalid
Invalid code — try again.

USAGE

1<mo-otp length="6" name="code"></mo-otp>2 3<!-- variants -->4<mo-otp length="4"></mo-otp>5<mo-otp length="8" data-pattern="alphanumeric"></mo-otp>

API

NAMEKINDDESCRIPTION
<mo-otp>elementGenerates cells + optional hidden mirror; emits change
lengthattributeCell count (default 4, clamped 1–12)
nameattributeHidden input mirroring the full value
data-patternattributenumeric (default) · alphanumeric
--mo-otp-cell-sizetokenSlot size hook (2.25rem)

FILES

src/css/input-otp.csssrc/js/input-otp.js
Install:mo add input-otp

THEMING · PLAYGROUND

This is the exact component from the examples above, wearing a completely different theme. Edit the tokens and --mo-* hooks in the editor — autocomplete knows them all — and the preview obeys in real time. Your CSS always wins.

Tokens & hooks — edit live
Global tokens
--muted-foreground--radius
Component hooks
--mo-otp-cell-size

Preview

Código de un solo uso — expira en 5:00.

Your CSS

Try it: type --mo- for the component hooks, or edit any value — the preview obeys in real time.