Pallas UI
DocsComponents
Core Concepts
    • Introduction
    • Getting Started
    • Theming
    • Color Tokens
    • Spacing & Sizing
    • Layout Guide
    • AspectRatio
    • Box
    • Flex
    • Grid
    • Shapes
Previews
    • Accordion
    • Alert
    • Avatar
    • Badge
    • Breadcrumb
    • Button
    • Carousel
    • Checkbox
    • Combobox
    • Command
    • Date Picker
    • Form
    • Input
    • Input OTP
    • Label
    • MenuBar
    • Modal
    • Popover
    • Progress
    • Radio Group
    • Segmented
    • Select
    • Separator
    • Sheet
    • Sidebar
    • Skeleton
    • Slider
    • Spinner
    • Steps
    • Switch
    • Tabs
    • Textarea
    • Toast
    • Tooltip
    • Typography
  1. Components
  2. Input OTP

Input OTP

Displays an input field for an OTP code.

-
-
-
-
-
-

Installation

Install the following dependencies

npm install input-otp

Copy and paste the following code into your project

import {
  InputOTPGroup as GroupPrimitive,
  InputOTPRoot as RootPrimitive,
  InputOTPSeparator as SeparatorPrimitive,
  InputOTPSlot as SlotPrimitive,
} from '@pallas-ui/input-otp'
import type { InputOTPProps } from '@pallas-ui/input-otp'
import { type Assign, createStyleContext } from '@pallas-ui/style-context'
import { type InputOTPVariantProps, inputOTP } from '@styled-system/recipes'
import type { JsxStyleProps } from '@styled-system/types'
import type { ComponentProps } from 'react'
import type React from 'react'
 
const { withProvider, withContext } = createStyleContext(inputOTP)
 
// root component
type RootProps = Assign<JsxStyleProps, InputOTPProps>
const InputOTPRoot = withProvider<
  React.ComponentRef<typeof RootPrimitive>,
  RootProps & InputOTPVariantProps
>(RootPrimitive, 'root')
 
// group component
type GroupProps = Assign<JsxStyleProps, ComponentProps<typeof GroupPrimitive>>
const InputOTPGroup = withContext<React.ComponentRef<typeof GroupPrimitive>, GroupProps>(
  GroupPrimitive,
  'group',
)
 
// slot component
const InputOTPSlot = withContext<
  React.ComponentRef<typeof SlotPrimitive>,
  React.ComponentProps<typeof SlotPrimitive>
>(SlotPrimitive, 'slot')
 
// separator component
const InputOTPSep = withContext<
  React.ComponentRef<typeof SeparatorPrimitive>,
  React.ComponentProps<typeof SeparatorPrimitive>
>(SeparatorPrimitive, 'separator')
 
// compose the InputOTP object
export default {
  Root: InputOTPRoot,
  Group: InputOTPGroup,
  Slot: InputOTPSlot,
  Separator: InputOTPSep,
}

Update the import paths to match your project setup

Usage

import { Input } from '@/components/ui/input-otp'
 
// Basic otp input
<InputOTP.Root maxLength={6}>
    <InputOTP.Group>
        <InputOTP.Slot index={0} />
        <InputOTP.Slot index={1} />
        <InputOTP.Slot index={2} />
    </InputOTP.Group>
    <InputOTP.Separator />
    <InputOTP.Group>
        <InputOTP.Slot index={3} />
        <InputOTP.Slot index={4} />
        <InputOTP.Slot index={5} />
    </InputOTP.Group>
</InputOTP.Root>

Examples

Default

-
-
-
-
-
-

Style Variants

Outline
-
-
-
-
-
-
Filled
-
-
-
-
-
-
Underlined
-
-
-
-
-
-
Borderless
-
-
-
-
-
-

Radii Variants

Small
-
-
-
-
-
-
Medium
-
-
-
-
-
-
Large
-
-
-
-
-
-
Full
-
-
-
-
-
-

Size Variants

Small
-
-
-
-
-
-
Medium
-
-
-
-
-
-
Large
-
-
-
-
-
-

With Separator and Separate Groups

-
-
-
–
-
-
-

With Custom Placeholder

X
X
X
X
X
X

Disabled

-
-
-
-
-
-

Success State

Outline
-
-
-
-
-
-
Filled
-
-
-
-
-
-
Underlined
-
-
-
-
-
-
Borderless
-
-
-
-
-
-

Error State

Outline
-
-
-
-
-
-
Filled
-
-
-
-
-
-
Underlined
-
-
-
-
-
-
Borderless
-
-
-
-
-
-

Warning State

Outline
-
-
-
-
-
-
Filled
-
-
-
-
-
-
Underlined
-
-
-
-
-
-
Borderless
-
-
-
-
-
-

Form

-
-
-
-
-
-

API Reference

InputOTP.Root

The root element that wraps the entire component.

PropertyTypeDefaultDescriptionOptions
stylingstringboxVisual style of the otp input fieldbox, filled, underlined, borderless
slotSizestringmdSize of the slotssm, md, lg
shapestringdefaultShape of the slotsdefault, rounded
maxLengthnumber6Number of slots/size of input-
patternstring^[a-zA-Z0-9]*$Regular expression to specify pattern of input code-
dataStatusstringnoneValidation state of the inputnone, success, error, warning
disabledboolean-Disabled state of the inputtrue, false
placeholderstring-Specify a custom placeholder in the slots-

InputOTP.Root also accepts props by the OTPInput component from input-otp:

PropertyTypeDefaultDescriptionOptions
valuestring-Controlled value-
onChange(newValue:
string) => unknown
-Change handler-
onComplete(...args:any[])
=> unknown
-Called when the input is complete-
textAlignstringleftWText alignmentleft, center, right
inputModestringnumericMobile keyboard typenumeric, text, decimal, tel, search, email, url
pasteTransformer(pastedText:string)
=> string
-Paste transform function-
pushPassword-
ManagerStrategy
stringincrease-widthPassword manager badge strategyincrease-width, none
noScriptCSS-
Fallback
string-Fallback for no-JS pages-

InputOTP.Group

The group wrapper element that wraps multiple slots.

InputOTP.Slot

The slot element that represents each individual character input.

PropertyTypeDefaultDescriptionOptions
indexnumber-Index of the slot-

InputOTP.Separator

A separator element that visually separates groups of slots.

Built with ❤️ by the carbonteq team. The source code is available on GitHub.

© 2025 Pallas UI. All rights reserved.