---
title: "Card Code Input"
description: "A field for the card security code: 3 digits, or 4 for American Express. An optional card mark shows where the code is on the card."
url: https://gelatinui.com/components/card-code-input
markdown_url: https://gelatinui.com/components/card-code-input.md
access: pro
install: "npx shadcn@latest add @gelatin-ui-pro/card-code-input"
version: "2026-11-09"
index: https://gelatinui.com/llms.txt
docs_index: https://gelatinui.com/docs/llms.txt
---

# Card Code Input

> A field for the card security code: 3 digits, or 4 for American Express. An optional card mark shows where the code is on the card.

Page: https://gelatinui.com/components/card-code-input

## When to use it

Best for: The security code of a card in its own field, 3 digits or 4 for Amex.

- Use it when the code has its own label, next to the number and the expiry.
- Pass `brand` from the card number, so the length follows it.
- Add `CardCodeInputHint` to show where the code is printed.

## When not to use it

- For the number, expiry, and code in one frame, use a [Card Field](https://gelatinui.com/components/card-field.md).
- For a one-time code from a text message, use an [Input OTP](https://gelatinui.com/components/input-otp.md).

## Notes for agents

- The parts are `CardCodeInputControl` and `CardCodeInputHint`. With no children it renders only the control.
- `length` wins over `brand`. Extra digits are cut when the length drops.
- The hint shows the back of a card, or the front for Amex. Say the place in a `FieldDescription`.

## Anatomy

```text
CardCodeInput
├─ CardCodeInputControl (0..n)
└─ CardCodeInputHint (0..n)
```

## API reference

### CardCodeInput

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `className` | `string` |  |  |
| `rounded` | `"default" \| "full"` | "default" |  |
| `size` | `"default" \| "lg" \| "sm" \| "xs"` | "default" |  |
| `variant` | `"dashed" \| "default"` |  |  |
| `disabled` | `boolean` | false | Turns the control off; the frame fades to 50% with it (the Base UI name). |
| `readOnly` | `boolean` | false | The code shows and can be copied, but not changed (the Base UI name). |
| `value` | `string` |  | The shown code (controlled). |
| `defaultValue` | `string` | "" | The first shown code (uncontrolled). |
| `onValueChange` | `function` |  | Runs on every change with the digits and the checks. |
| `brand` | `CardBrandId \| null` | null | The brand of the card number: Amex takes 4 digits, printed on the front. |
| `length` | `3 \| 4` |  | A fixed length, when you do not know the brand. Wins over `brand`. |

### CardCodeInputControl

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `className` | `string` |  |  |
| `guide` | `boolean` |  | The ghost guide of the slots still to fill, while the input has focus. Default `true`. |
| `rawName` | `string` |  | Also submit the raw value under this name (a hidden input), next to the shown one. |
| `rejectFeedback` | `boolean` |  | Nudge the field 2px when the mask rejects a key. Default `true`. |
| `onReject` | `function` |  | Runs when the mask rejects a key (a letter in a number, a 13th month). |
| `ref` | `Ref<HTMLInputElement>` |  |  |
| `rounded` | `"default" \| "full"` |  |  |
| `size` | `"default" \| "lg" \| "sm" \| "xs"` |  |  |

### CardCodeInputHint

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `className` | `string` |  |  |

## Styling

| Part | Slot | States | CSS variables | Tokens |
| --- | --- | --- | --- | --- |
| CardCodeInput | `card-code-input` |  |  |  |
| CardCodeInputControl | `card-code-input-control` |  |  |  |
| CardCodeInputHint | `card-code-input-hint` |  |  | `motion-timing` |

## Usage

Import Card Code Input and compose its parts.

```tsx title="card-code-input.tsx"
import { CardCodeInput, CardCodeInputControl, CardCodeInputHint } from "@/components/ui/pro/card-code-input";

export function CardCodeInputDemo() {
  return (
    <CardCodeInput className="w-full">
      <CardCodeInputControl />
      <CardCodeInputHint />
    </CardCodeInput>
  );
}
```

## Compose

Rules:

- Compose the parts (`compose-parts`): Build each item from its named parts as children, and pass your text and icons in as parts.
- Every state is designed (`every-state`): Give each view of data its loading, empty, and error states: a skeleton in the final layout, an `Empty` with an illustration and one next action, and an error that says what failed and how to retry.

## Add it

```bash
npx shadcn@latest add @gelatin-ui-pro/card-code-input
```

It adds 27 registry items: 24 files, 5414 lines, and the npm packages `@base-ui/react`, `@mantine/hooks`, `@maskito/core`, `@maskito/kit`, `@maskito/react`, `@phosphor-icons/react`, `clsx`, `motion`, `tailwind-merge`, `tailwind-variants`.

## Built on

- [Input Group](https://gelatinui.com/components/input-group.md)
- [Masked Input](https://gelatinui.com/components/masked-input.md)

## For AI agents

- Every item, one file: https://gelatinui.com/llms.txt
- MCP server (`search_items`, `get_item`, `get_install_plan`): https://gelatinui.com/mcp

## Related

- [Card Field](https://gelatinui.com/components/card-field.md)
- [Card Number Input](https://gelatinui.com/components/card-number-input.md)
- [Card Expiry Input](https://gelatinui.com/components/card-expiry-input.md)
- [Field](https://gelatinui.com/components/field.md)

## Accessibility

It is a native input with `autocomplete="cc-csc"` and a number keypad.

The hint is decorative. The words in the help text tell where the code is.

## Motion

| Part | Motion |
| --- | --- |
| Rejected key | indicator · the frame moves 2px to each side and back when the mask rejects a key |
