Cnippet

OTP Field

Component

About

A set of input boxes for entering a one-time passcode or verification code, with optional grouping separators, large size, and disabled states.

Built with React and Tailwind. Copy the prompt and paste it into Claude Code, Cursor or Lovable: your agent adds OTP Field to your project and fits it to your theme.

Code

How OTP Field is used: the demo's code. The component's own source comes with a free account.

Usage.tsx

import { Label } from "@/components/ui/label";
import {
  OTPField,
  OTPFieldInput,
  OTPFieldSeparator,
} from "@/components/ui/otp-field";

function slots(from: number, count: number, total: number) {
  return Array.from({ length: count }, (_, i) => (
    <OTPFieldInput
      aria-label={`Character ${from + i + 1} of ${total}`}
      key={from + i}
    />
  ));
}

export default function OTPFieldDemo() {
  return (
    <div className="flex flex-col items-start gap-5">
      <div className="flex flex-col gap-2">
        <Label>Verification code</Label>
        <OTPField aria-label="Verification code" length={6}>
          {slots(0, 3, 6)}
          <OTPFieldSeparator />
          {slots(3, 3, 6)}
        </OTPField>
      </div>
      <div className="flex flex-col gap-2">
        <Label>PIN (large)</Label>
        <OTPField aria-label="PIN" length={4} size="lg">
          {slots(0, 4, 4)}
        </OTPField>
      </div>
      <div className="flex flex-col gap-2">
        <Label>Disabled</Label>
        <OTPField aria-label="Disabled code" disabled length={6}>
          {slots(0, 6, 6)}
        </OTPField>
      </div>
    </div>
  );
}

Dependencies

More by Cnippet

View all
  • Team

    Team

    1.4K
  • Davincho Hero-1

    Davincho Hero-1

    716
  • Aero Hero-3

    Aero Hero-3

    633
  • Random Letter Swap Navigation

    Random Letter Swap Navigation

    586
  • Features

    Features

    539
  • Services with Animated Hover Modal

    Services with Animated Hover Modal

    492
  • Blogs

    Blogs

    406
  • Aero Hero-1

    Aero Hero-1

    387

Explore more

Part of Cnippet — browse the full library on 21st.dev.