Skip to main content

Basic

One text input styled with a wide tracking-otp letter spacing, so the characters look like separate boxes without being separate fields. The phone offers the code from the text message because of autocomplete="one-time-code" and the numeric keypad because of inputmode="numeric". length (6 by default) sets maxlength and pattern, and a small Alpine handler removes anything that is not a digit.

Enter the 6 digit code from your authenticator app.

Enter your 4 digit PIN.

Alphanumeric and masked

kind="alphanumeric" uses inputmode="text", drops one-time-code, and keeps letters and digits in capitals. kind="masked" hides the PIN with type="password" and adds a Show PIN button (aria-pressed) so the person can check what they typed.

Eight letters or numbers.

The PIN is hidden while you type.

States

error sets aria-invalid="true" and points aria-describedby at the message: the border turns red and the message says what is wrong, so colour is not the only cue. success adds a green frame and a message, here with readonly. A disabled input is dimmed and skipped by the keyboard.

That code is not correct. Check it and try again.

Code accepted.

Request a new code to enter it here.

Separator and Resend

separator adds a hyphen (3-3) while the person types, so it stays one input; the value then holds the hyphen, so remove it before you check the code. The page writes the Resend link below the component; it is disabled with a countdown; when it ends, a role="status" message tells a screen reader the code was sent. The countdown is not announced every second.

The hyphen is added for you. Remove it before you check the code.

Did not get a code?

Options reference

The input is plain HTML with Tailwind classes; Alpine only filters the characters and runs the Resend countdown.

Part Value Description
type="text" with inputmode Do not use type="number": it removes leading zeros, adds spinners and accepts e.
inputmode numeric or text Which keyboard the phone shows.
autocomplete one-time-code Lets the phone fill the code from a text message. Use off for recovery codes.
maxlength, pattern length and format For example 6 and [0-9]{6}.
tracking-otp theme value 0.6em Defined in the @theme of the page: --tracking-otp: 0.6em. The left padding (pl-6) is a little larger than the right one to put the text back in the middle.
@input Alpine, optional Removes characters that are not allowed. Without Alpine the pattern still blocks submit.
aria-invalid true Turns the border red; add aria-describedby for the message.
readonly, disabled attributes Success (with green border) and disabled states.