Skip to content

Input OTP

Get Ritla UI

One-time code boxes, 4 to 6. Typing moves to the next box, paste fills them all, and phones offer the code from the SMS.

Ritla scan of this preview: 40 of 41 checks3 breakpointsScanned Known misread of our own scanner: R023

Open in Figma

Preview

Mirrored is the same English content laid out right to left: it separates a mirroring bug from a translation one.

PreviewCode
EnglishMirroredArabic
LTR →

Installation

  1. Add the component

    npx ritla add input-otp

    Also works with shadcn: npx shadcn@latest add @ritla/input-otp

  2. Dependencies it brings

    @base-ui/react

  3. Or copy by hand

    Installing by hand copies the component's source into your project. The source comes with a Ritla UI license, so the CLI is the short way to the same files.

Usage

input-otp.tsx
import { InputOTP } from "@/components/ui/input-otp";<InputOTP label="Verification code" onValueComplete={verify} />

Examples

Length and states

length: 4, 5 or 6. An error marks every box.

EnglishMirroredArabic
LTR →

API reference

InputOTP

PropTypeDefaultDescription
labelReactNodeNoneFigma's Label.
length4 | 5 | 66Figma's Show 5th and Show 6th.
value / defaultValuestringNoneThe code, in Western digits (0123456789).
onValueChange(value: string) => voidNoneOn every change.
onValueComplete(value: string) => voidNoneOnce every box is filled.
autoSubmitbooleanfalseSubmit the form when the code is complete.
required / helperText / error / disabled / readOnly / name…NoneAs on Input Field.

Accessibility

Keyboard

Keys are written for left-to-right. In right-to-left the arrow keys swap: the one pointing toward the reading direction moves forward.

KeyAction
0…9Types the digit and moves to the next box.
BackspaceDeletes and moves back a box.
ArrowLeftArrowRightBetween boxes, the same visual way in Arabic (the boxes read left to right).

ARIA

  • The first box takes the label; the others are “Digit 2 of 6”, in the page language.
  • autocomplete="one-time-code" and inputmode="numeric" for a number pad and the SMS suggestion.

Arabic and RTL notes

Mirrors

  • The group starts at the inline start (the right), with the label.

Does not mirror

  • The boxes read left to right: the first digit in the left box, as the code is written in the SMS.
Numerals
Typed Arabic-Indic (٠١٢٣٤٥٦٧٨٩) and Persian digits are stored as Western digits (0123456789), so the code works from an Arabic keyboard.
Arabic typography
label-16, centered in each box.

Checks it passes

The Ritla checks this component satisfies by construction. Used as documented, it does not bring these defects onto your page.

  • R050Arabic text falling back past the declared font family (measured, declared, or a webfont that failed to load)
  • R051letter-spacing applied to Arabic text (breaks the connected script)
  • R020Forced-LTR container, or a bidi override, over Arabic content
  • R021Unisolated bidi hazards: phones, emails, Latin tokens inside Arabic text
  • R042Clipped text: content wider than its box with overflow hidden and no ellipsis
  • R043Fixed-pixel-width container whose Arabic text exceeds the space