One-time code input split into single-digit boxes, with auto advance, paste support, and one hidden field for form submit.
<x-markas.input-otp name="code" label="Verification code" />import { InputOTP } from "@/components/markas/InputOTP";
export default function InputOTPExample() {
return <InputOTP name="code" label="Verification code" />;
}<script setup lang="ts">
import { ref } from "vue";
import InputOTP from "@/components/markas/InputOTP.vue";
const code = ref("");
</script>
<template>
<InputOTP v-model="code" name="code" label="Verification code" />
</template><script lang="ts">
import InputOTP from "$lib/components/markas/InputOTP.svelte";
let code = $state("");
</script>
<InputOTP bind:value={code} name="code" label="Verification code" />---
import InputOTP from "@/components/markas/InputOTP.astro";
---
<InputOTP name="code" label="Verification code" />Examples
Four digits
<x-markas.input-otp name="pin" label="Card PIN" :length="4" />import { InputOTP } from "@/components/markas/InputOTP";
export default function Example() {
return <InputOTP name="pin" label="Card PIN" length={4} />;
}<script setup lang="ts">
import { ref } from "vue";
import InputOTP from "@/components/markas/InputOTP.vue";
const pin = ref("");
</script>
<template>
<InputOTP v-model="pin" name="pin" label="Card PIN" :length="4" />
</template><script lang="ts">
import InputOTP from "$lib/components/markas/InputOTP.svelte";
let pin = $state("");
</script>
<InputOTP bind:value={pin} name="pin" label="Card PIN" length={4} />---
import InputOTP from "@/components/markas/InputOTP.astro";
---
<InputOTP name="pin" label="Card PIN" length={4} />States
<div class="grid gap-6">
<x-markas.input-otp name="filled_code" label="Filled" value="482913" />
<x-markas.input-otp name="locked_code" label="Disabled" value="12" disabled />
</div><script lang="ts">
import InputOTP from "$lib/components/markas/InputOTP.svelte";
let filled = $state("482913");
let locked = $state("12");
</script>
<div class="grid gap-6">
<InputOTP bind:value={filled} name="filled_code" label="Filled" />
<InputOTP bind:value={locked} name="locked_code" label="Disabled" disabled />
</div>---
import InputOTP from "@/components/markas/InputOTP.astro";
---
<div class="grid gap-6">
<InputOTP name="filled_code" label="Filled" value="482913" />
<InputOTP name="locked_code" label="Disabled" value="12" disabled />
</div>Verification card
<form class="grid gap-5 rounded-lg border border-line bg-surface p-6">
<div class="grid gap-1">
<p class="text-base font-semibold text-ink">Check your email</p>
<p class="text-sm text-muted">We sent a 6-digit code to ana@example.com. It expires in 10 minutes.</p>
</div>
<x-markas.input-otp name="code" label="Verification code" />
<x-markas.button type="submit" class="w-full">Verify email</x-markas.button>
<p class="text-sm text-muted">Did not get a code? <a href="#" class="font-medium text-primary underline underline-offset-2">Send again</a></p>
</form>Installation
npx markasui@latest add input-otppnpm dlx markasui@latest add input-otpyarn dlx markasui@latest add input-otpbunx --bun markasui@latest add input-otp- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Install the dependency:
npm install alpinejs - Copy the component source below to
resources/views/components/markas/input-otp.blade.php.
- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Copy the component source below to
src/components/markas/InputOTP.tsx.
- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Copy the component source below to
src/components/markas/InputOTP.vue.
- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Copy the component source below to
src/lib/components/markas/InputOTP.svelte.
- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Copy the component source below to
src/components/markas/InputOTP.astro.
- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Copy the component source below to
src/app/markas/input-otp.component.ts.
Usage
<x-markas.input-otp
name="code"
label="Verification code"
x-on:markas-complete="$el.closest('form').requestSubmit()"
/>Needs Alpine.js. Every change dispatches markas-change and a full code dispatches markas-complete, both with the code in $event.detail. Start with a code through value.
Livewire
<x-markas.input-otp label="Code" wire:model.live="code" x-on:markas-complete="$wire.verify()" />wire:model binds the joined code as one string. Listen for markas-complete to verify once every box is filled.
import { useState } from "react";
import { InputOTP } from "@/components/markas/InputOTP";
const [code, setCode] = useState("");
<InputOTP
name="code"
label="Verification code"
value={code}
onValueChange={setCode}
onComplete={(value) => verify(value)}
/>;<script setup lang="ts">
import { ref } from "vue";
import InputOTP from "@/components/markas/InputOTP.vue";
const code = ref("");
</script>
<template>
<InputOTP
v-model="code"
name="code"
label="Verification code"
@complete="(value) => verify(value)"
/>
</template><script lang="ts">
import InputOTP from "$lib/components/markas/InputOTP.svelte";
let code = $state("");
</script>
<InputOTP
bind:value={code}
name="code"
label="Verification code"
oncomplete={(value) => verify(value)}
/>---
import InputOTP from "@/components/markas/InputOTP.astro";
---
<InputOTP name="code" label="Verification code" />
<script>
document.addEventListener("markas-complete", (event) => {
verify((event as CustomEvent<string>).detail);
});
</script>One small script per page handles every field. Like Blade, the fieldset dispatches markas-change and markas-complete events with the code in detail.
import { Component, signal } from "@angular/core";
import { InputOTP } from "./markas/input-otp.component";
@Component({
selector: "app-verify",
imports: [InputOTP],
template: `
<markas-input-otp
[(value)]="code"
name="code"
label="Verification code"
(complete)="verify($event)"
/>
`,
})
export class Verify {
readonly code = signal("");
verify(code: string) {
// Send the code to your API.
}
}- The boxes accept digits only. Pasting a full code fills every box, even with spaces or dashes in it.
namegoes to one hidden input that holds the joined code, so a normal form submit sendscode=123456.- Extra attributes and
classgo to the<fieldset>.disableddisables every box. - Translate the box labels with
digitLabel(default “Digit {index} of {length}”).
Props
| Name | Type | Default | Description |
|---|---|---|---|
length | number | 6 | Number of digit boxes. |
label | string | - | Group label, rendered as the fieldset legend. |
name | string | - | Name of the hidden input that holds the full code for form submit. |
value / defaultValue / v-model / bind:value | string | "" | The code. React accepts value with onValueChange or defaultValue; Vue uses v-model; Svelte bind:value; Angular value or [(value)]; Blade and Astro use value. |
onValueChange / markas-change | (value: string) => void | - | Called on every change with the joined code (React). Blade and Astro dispatch a markas-change event. |
onComplete / @complete / markas-complete | (value: string) => void | - | Called once every box is filled, with the full code. Blade and Astro dispatch a markas-complete event. |
oncomplete | (value: string) => void | - | Svelte only. Called once every box is filled, with the full code. |
complete | output<string> | - | Angular only. Emits the full code once every box is filled. |
digitLabel | string | Digit {index} of {length} | aria-label of each box. {index} and {length} are replaced with numbers. |
Accessibility
- Boxes sit in a fieldset whose legend is the label prop, and each box has an aria-label such as "Digit 1 of 6".
- Typing a digit moves focus to the next box; Backspace clears and moves back; Arrow Left, Arrow Right, Home, and End move between boxes.
- Pasting a code fills all boxes. The first box uses autocomplete=one-time-code so phones can suggest SMS codes.
- Boxes use inputmode=numeric for a number keyboard and accept digits only.
Related components
More form components with the same classes in every framework.
- ButtonButton with primary, secondary, ghost, and danger variants.
- CheckboxNative checkbox with an optional label and description, custom styled without JavaScript.
- ComboboxText input with a filtered suggestion list in a popover, following the WAI-ARIA Combobox pattern with list autocomplete.
- InputText field with a label, hint, and error message wired up through ARIA.
- LabelForm label with consistent styling and optional required or optional markers that screen readers announce correctly.
- Radio GroupGroup of native radios inside a fieldset and legend for picking one of several options.