Skip to content
caliper ui docs

Components

OTP input

A segmented field for one-time codes with paste support and status.

Free
pnpm dlx shadcn@latest add @caliper/otp-input

Check your email

We sent a 6-digit code to mara.chen@halden.app

0 of 6 digits.

The code expires in 10 minutes. Demo code: 123456.

Installs components/ui/otp-input.tsxDepends on none beyond ReactMotion shared motion tokens

When to use

Use it for

  • Sign-in and verification codes of four to eight digits.
  • You want success and error states on the whole code.

Skip it when

  • The code is long or alphanumeric free text; use an input.

Installation

terminal
pnpm dlx shadcn@latest add @caliper/otp-input

Adds its 4 files to components/ui/, each with its own stylesheet, and installs their packages. No account needed. The first part also adds Caliper UI’s tokens; import them once as in Installation.

Usage

This is the code behind the preview above.

example.tsx
import { useState, type ReactNode } from "react"
import { OtpInput } from "@/components/ui/otp-input"

function Panel({ title, context, className = "max-w-md", children }: { title: string; context: string; className?: string; children: ReactNode }) {
  return (
    <section className={`grid w-full gap-5 rounded-overlay border border-border bg-background p-6 shadow-resting ${className}`}>
      <div className="grid gap-1">
        <p className="font-medium">{title}</p>
        <p className="text-sm text-muted-foreground">{context}</p>
      </div>
      {children}
    </section>
  );
}

export function VerifyCode() {
  const [code, setCode] = useState("");
  const status = code.length < 6 ? "idle" : code === "123456" ? "success" : "error";
  return (
    <Panel title="Check your email" context="We sent a 6-digit code to mara.chen@halden.app" className="max-w-sm">
      <OtpInput label="Sign-in code" value={code} onValueChange={setCode} status={status} className="justify-self-center" />
      <p className="text-center text-sm text-muted-foreground">The code expires in 10 minutes. Demo code: 123456.</p>
    </Panel>
  );
}

API reference

OtpInput

component
PropTypeDefaultDescription
labelstring"One-time code"
lengthnumber6
valuestring—
defaultValuestring""
onValueChange((value: string) => void)—
status"success" | "error" | "idle""idle"
messagestring—Replaces the status line, e.g. why a code was refused or “Checking the code…”.
disabledboolean—
namestring—
classNamestring—

Accessibility

It exposes status semantics, with aria-label and aria-hidden kept in step with state. Changes that matter are announced through a live region.

KeyBehaviour
BackspaceRemoves the previous character or item.
←Moves to the previous item or value.
→Moves to the next item or value.

Motion

Transitions use the shared duration and easing tokens. Under prefers-reduced-motion those tokens collapse to instant and travel distances go to zero, so state changes still happen without movement.

All One-time code examples