OTP Input

OTP Input: One-time-code input with a gliding focus ring, digits that roll in per slot, error shake and a success check draw. Free MIT React & Next.js source with Motion and Tailwind CSS, live preview, CLI install and docs.

Install OTP Input

npx motion-ui-skill add otp-input

Components install as source into your project. The interactive page also includes preview, code, documentation and install tabs.

Dependencies

  • clsx
  • motion
  • react
  • tailwind-merge

Source files

OTP Input

One-time-code input with a gliding focus ring, digits that roll in per slot, error shake and a success check draw.

Install

npx motion-ui-skill add otp-input

Dependencies

  • clsx
  • motion
  • react
  • tailwind-merge

Usage

"use client";

import { useState } from "react";
import { OTPInput, type OTPStatus } from "@/components/motion/otp-input";

const CODE = "123456";

export function OTPInputPreview() {
  const [value, setValue] = useState("");
  const [status, setStatus] = useState<OTPStatus>("idle");

  return (
    <div className="flex flex-col items-center gap-4">
      <OTPInput
        label="Verification code"
        hint={`Enter ${CODE} to verify.`}
        successMessage="Verified."
        errorMessage="Wrong code, try again."
        value={value}
        status={status}
        onChange={(v) => {
          setValue(v);
          if (status !== "idle") setStatus("idle");
        }}
        onComplete={(v) => setStatus(v === CODE ? "success" : "error")}
      />
    </div>
  );
}

API Reference

OTPInput

Prop Type Default Required Description
length number 6 No Number of slots. Default 6.
value string — No —
defaultValue string — No —
onChange ((value: string) => void) — No —
onComplete ((value: string) => void) — No Fires once every slot is filled.
label string — No Optional label rendered above the slots.
hint string — No Helper text shown below the slots while idle.
successMessage string — No Message shown below the slots when status is "success".
errorMessage string — No Message shown below the slots when status is "error".
status "error" | "success" | "idle" idle No External validation feedback. "error" shakes, "success" draws a check.
mask boolean false No Render dots instead of the typed digits.
disabled boolean false No —
autoFocus boolean false No —
aria-label string One-time passcode No Accessible label for the underlying input.
className string — No —

Browse this category