OTP Input
Form-associated one-time-code field with one cell per character, paste and SMS autofill, grouping and masking.
Attributes
| Name | Type | Default | Description |
|---|---|---|---|
value | string | — | Current code. Characters outside mode are dropped and the value is cut to length. |
length | number | 6 | Number of cells, i.e. the length of a complete code. |
mode | OtpInputMode | numeric | Characters accepted: numeric (digits, numeric keypad) or alphanumeric (letters and digits). |
group | number | 0 | Splits the cells into groups of this size with a separator between them, e.g. 3 for 123-456. 0 disables. |
masked | boolean | false | Shows a dot instead of each entered character. |
placeholder | string | — | Single character shown in every empty cell. |
name | string | — | Form field name. |
autocomplete | string | one-time-code | Browser autocomplete hint. one-time-code lets iOS/Android offer a code received by SMS. |
required | boolean | false | Requires a complete code before the form can be submitted. |
readonly | boolean | false | Prevents editing while keeping the value in form submission. |
disabled | boolean | false | Prevents interaction and excludes the value from form submission. |
error | boolean | false | Applies the visual error state and sets aria-invalid. |
help | string | — | Helper text shown below the cells. |
error-text | string | — | Message shown below the cells while error is set. |
aria-label | string | null | null | Accessible name forwarded to the native input. Defaults to "Verification code". |
Slots
| Name | Description |
|---|---|
supporting-text | Rich helper content below the cells. help and error-text are plain-text shortcuts. |
Events
| Name | Type | Description |
|---|---|---|
complete | CustomEvent<OtpInputCompleteDetail> | Fired when user input fills every cell; detail.value is the code. |
input | InputEvent | Re-dispatched when typing, deleting or pasting changes the value. |
change | Event | Re-dispatched when an edited value is committed on blur. |
CSS custom properties
Grouped by semantic target and state from --c2-<component>__<target>__<state>--<property>. Click a group to collapse it; click a name to copy it.
| Name | Type | Default | Description |
|---|---|---|---|
--c2-otp-input--gap | pixel | 8px | |
--c2-otp-input--font-family | font-family | inherit | |
--c2-otp-input__cell--width | pixel | 40px | |
--c2-otp-input__cell--height | pixel | 44px | |
--c2-otp-input__cell--border | border | 1px solid #bcbcc6 | |
--c2-otp-input__cell--border-radius | border-radius | 6px | |
--c2-otp-input__cell--color | color | #18181b | |
--c2-otp-input__cell--background | color | #ffffff | |
--c2-otp-input__cell--font-size | font-size | 20px | |
--c2-otp-input__cell--font-weight | font-weight | 600 | |
--c2-otp-input__cell__hover--border | border | 1px solid #a1a1aa | |
--c2-otp-input__cell__focus--border | border | 1px solid #0265dc | |
--c2-otp-input__cell__focus--outline | outline | 2px solid rgba(2, 101, 220, 0.4) | |
--c2-otp-input__cell__focus--outline-offset | pixel | 0px | |
--c2-otp-input__cell__error--border | border | 1px solid #dc2626 | |
--c2-otp-input__cell__read-only--background | color | #fafafa | |
--c2-otp-input__placeholder--color | color | #71717a | |
--c2-otp-input__caret--color | color | #18181b | |
--c2-otp-input__caret--width | pixel | 1px | |
--c2-otp-input__caret--height | pixel | 20px | |
--c2-otp-input__caret--animation-duration | time | 1s | |
--c2-otp-input__separator--color | color | #71717a | |
--c2-otp-input__separator--width | pixel | 8px | |
--c2-otp-input__separator--height | pixel | 2px | |
--c2-otp-input__disabled--opacity | opacity | 0.38 | |
--c2-otp-input__supporting-text--gap | pixel | 4px | |
--c2-otp-input__supporting-text--font-size | font-size | 12px | |
--c2-otp-input__supporting-text--line-height | pixel | 16px | |
--c2-otp-input__supporting-text--color | color | #71717a | |
--c2-otp-input__supporting-text__error--color | color | #dc2626 | |