Skip to content
h v3.13.3
Search the docs
Find a component, section or page.

Input OTP

Accessible one-time password component with copy-paste functionality.

Installation

pnpm add @heyramzi/ui bits-ui

Usage

import * as InputOTP from "@heyramzi/ui/shadcn/input-otp";
<InputOTP.Root maxlength={6} aria-label="Verification code">
  {#snippet children({ cells })}
    <InputOTP.Group>
      {#each cells.slice(0, 3) as cell (cell)}
        <InputOTP.Slot {cell} />
      {/each}
    </InputOTP.Group>
    <InputOTP.Separator />
    <InputOTP.Group>
      {#each cells.slice(3, 6) as cell (cell)}
        <InputOTP.Slot {cell} />
      {/each}
    </InputOTP.Group>
  {/snippet}
</InputOTP.Root>

Keyboard and accessibility

  • It's one real input under the boxes, so typing, Backspace and paste work as in any text field.
  • It asks for a one-time code, so a phone can fill it from a text message.
  • Give the root an aria-label, like "Verification code". The boxes are drawn, not read.

API reference

InputOTP.Root

ref bindable HTMLElement | null
Default null
inputRef bindable PinInput.Root
Default null
class string
value bindable string
Default ""
...rest
Every prop of PinInput.Root from bits-ui
Prop Type Default
ref bindable HTMLElement | null null
inputRef bindable PinInput.Root null
class string
value bindable string ""
...rest Every prop of PinInput.Root from bits-ui

InputOTP.Group

ref bindable HTMLDivElement | null
Default null
class string
children Snippet
...rest
Every prop of HTMLAttributes<HTMLDivElement> from svelte/elements
Prop Type Default
ref bindable HTMLDivElement | null null
class string
children Snippet
...rest Every prop of HTMLAttributes<HTMLDivElement> from svelte/elements

InputOTP.Slot

ref bindable HTMLElement | null
Default null
cell PinInput.Cell
class string
...rest
Every prop of PinInput.Cell from bits-ui
Prop Type Default
ref bindable HTMLElement | null null
cell PinInput.Cell
class string
...rest Every prop of PinInput.Cell from bits-ui

InputOTP.Separator

ref bindable HTMLDivElement | null
Default null
children Snippet
...rest
Every prop of HTMLAttributes<HTMLDivElement> from svelte/elements
Prop Type Default
ref bindable HTMLDivElement | null null
children Snippet
...rest Every prop of HTMLAttributes<HTMLDivElement> from svelte/elements