Skip to content

OTP Input for Angular

AngularAuthentication UI

Entry for one-time passcodes, PINs, MFA codes, and recovery codes: one native <input> holds the code and N aria-hidden visual cells mirror it. Numeric or alphanumeric, paste distribution (spaces and dashes are dropped), autocomplete=“one-time-code”, overwrite typing, masking, grouping, and a complete event.

  • One field, many cellsA single native input drawn as cells, so paste and autofill just work.
  • SMS autofillThe one-time-code hint lets phones fill codes from messages.
  • Numeric or alphanumericChoose the character set, uppercase letters, and the code length.
  • Grouped and maskedSplit long codes into groups and mask them like a password.
  • Complete eventFires once every cell is filled, ready to verify the code.

Behavior, design tokens, and limitations are described on the OTP Input page; this page covers the Angular API.

import { Component } from '@angular/core';
import { FormControl, ReactiveFormsModule } from '@angular/forms';
import { AuiOtpInput } from '@absoluteui/angular/otp-input';
@Component({
selector: 'app-verify',
imports: [ReactiveFormsModule, AuiOtpInput],
template: `<aui-otp-input label="Verification code" [required]="true" [formControl]="code" (completed)="verify()"></aui-otp-input>`,
})
export class VerifyComponent {
readonly code = new FormControl('', { nonNullable: true });
verify(): void {
// Send this.code.value to your server.
}
}
Terminal window
npm install @absoluteui/angular @absoluteui/components @absoluteui/core @absoluteui/theme

Setup with provideAbsoluteUI() is covered in Getting started. Styles are included with the component.

import { AuiOtpInput } from '@absoluteui/angular/otp-input';

Defaults for every instance: provideAbsoluteUIConfig({ components: { otpInput: { ... } } }) (see Configuration).

Class AuiOtpInput; template reference #ref="auiOtpInput".

Server rendering: Renders on the server; the browser re-creates it after hydration.

Angular forms: implements ControlValueAccessor and Validator; the form value is string. Bind [formControl], formControlName, or [(ngModel)]; validation messages of the component report through the aui error key. See Forms.

Input Type Default Description
label string Required. Visible label (required accessible name).
hideLabel boolean false Visually hide the label.
length number '6' Number of characters (1..32).
type OtpInputType 'numeric' Allowed characters.
mask boolean false Show dots instead of characters (PINs); the input becomes type=password.
uppercase boolean false Alphanumeric only: convert letters to upper case.
groupSize number Visual group size (separators are presentation only).
name string Form field name.
description string Help text, referenced by aria-describedby.
required boolean false A code is required.
disabled boolean false Disabled.
readOnly boolean false Read-only.
autocomplete "off" | "one-time-code" 'one-time-code' Autofill hint.
validate (value: string) => string | null Consumer validation of a complete code.
icons Partial<OtpInputIcons> Icon slot overrides.
validationTiming ValidationTiming 'blur' When validation messages first appear; afterwards they update live.
locale string 'en-US' Message and number-formatting locale.
Model Type Change output Description
[(value)] string (valueChange) The value: [(value)] without forms; with Angular forms, bind the form control instead.
Output Payload Description
(valueInput) OtpInputValueDetail User edited the code (the code is not in the detail). Re-emits aui-input.
(changed) OtpInputValueDetail User committed the value (native change). Re-emits aui-change.
(completed) OtpInputCompleteDetail The code became complete through user input (typing, paste, or autofill). Re-emits aui-complete.
Property Type Description
complete Signal<boolean> Every cell filled.

Call them through a viewChild query or a template reference.

Method Description
getFormValue(): string | undefined The code.
clear(): void Empty the code and focus the field (after a rejected code).
reportValidity(): boolean | undefined Show messages now (marks the control submitted) and return validity.
setCustomError(message: string | null): void External error (server, cross-field rule); null clears it.
focus(): void Move focus to the primary focusable element.
reset(): void Restore the initial value and clear dirty/touched/submitted state.

Pattern: One native <input> with <label for>; visual cells are aria-hidden presentation. Chosen over N single-character inputs: one-time-code autofill and password managers fill one field, paste/undo/selection stay native, screen readers hear one labelled field with a length hint instead of N unlabelled boxes, and fast typing never loses characters to focus changes.

The Angular component renders the framework-neutral component, so its keyboard support, roles, WCAG 2.2 criteria, budgets, and import cost apply unchanged: see OTP Input: Accessibility and performance.