OTP Field
A one-time password input composed of individual character slots.
Enter the 6-character code we sent to your device.
Usage guidelines
- Form controls must have an accessible name: give it one with a
<label>element or the Field parts. See Labeling an OTP field.
Anatomy
Import the primitives and assemble the parts:
@using Blazix.Primitives
<OtpFieldRoot>
<OtpFieldInput />
</OtpFieldRoot>Examples
Labeling an OTP field
Use a native <label> whose for matches the first input's id. Each input
has an aria-label such as "Character 2 of 6", so assistive technology announces which slot is focused.
Add aria-describedby to the root when supporting text should be announced with the field.
<div>
<label for="verification-code">Verification code</label>
<OtpFieldRoot Length="6" aria-describedby="verification-code-description">
<OtpFieldInput id="verification-code" />
<OtpFieldInput />
<OtpFieldInput />
<OtpFieldInput />
<OtpFieldInput />
<OtpFieldInput />
</OtpFieldRoot>
<p id="verification-code-description">Enter the 6-character code we sent to your device.</p>
</div>Submitting on completion
Set AutoSubmit to submit the owning form as soon as every slot is filled, or use
OnValueComplete to react to completion without submitting.
Alphanumeric verification codes
Use ValidationType="OtpValidationType.Alphanumeric" for recovery, backup or invite codes that mix letters and numbers.
Accept letters and numbers for backup codes such as A7C9XZ.
Grouped layouts
Wrap groups of inputs in your own layout elements, with a separator between them, to present the code in smaller
chunks such as 123-456.
Masked entry
Use Mask when the code should be obscured while it's typed.
Use Mask to obscure the code on shared screens.
API Reference
OtpFieldRoot
Renders a <div> element.
Other attributes are passed to the element it renders.
OtpFieldInput
Renders a <input> element.
Other attributes are passed to the element it renders.