---
title: "Card Number Input"
description: "A field for a card number. The first digits set the brand badge, the digit groups, and the length, and a checksum finds typing errors."
url: https://gelatinui.com/components/card-number-input
markdown_url: https://gelatinui.com/components/card-number-input.md
access: pro
install: "npx shadcn@latest add @gelatin-ui-pro/card-number-input"
version: "2026-11-09"
index: https://gelatinui.com/llms.txt
docs_index: https://gelatinui.com/docs/llms.txt
---

# Card Number Input

> A field for a card number. The first digits set the brand badge, the digit groups, and the length, and a checksum finds typing errors.

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

## When to use it

Best for: A card number in its own field, with the brand badge and the groups of the brand.

- Use it when the number has its own label, as in a checkout with separate fields.
- Use `onValueChange` details (`brand`, `complete`, `valid`) to set the code length or show the last four.

## 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 brand badge with no input, use a [Card Brand](https://gelatinui.com/components/card-brand.md).

## Notes for agents

- The parts are `CardNumberInputBrand` and `CardNumberInputControl`. With no children it renders both.
- Check the number in a `Field`: `validate={(v) => cardNumber().valid(String(v)) ? null : "This card number is not valid."}` with a preset made once at module level.
- `details.brand?.id` goes to `CardCodeInput brand`, so the code takes 4 digits for Amex.

## Anatomy

```text
CardNumberInput
├─ CardNumberInputBrand (0..n)
└─ CardNumberInputControl (0..n)
```

## API reference

### CardNumberInput

| 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 card number shows and can be copied, but not changed (the Base UI name). |
| `value` | `string` |  | The shown number (controlled). Raw digits show formatted: "4242424242424242". |
| `defaultValue` | `string` | "" | The first shown number (uncontrolled). |
| `onValueChange` | `function` |  | Runs on every change with the shown number, the digits, the checks, and the brand. |

### CardNumberInputBrand

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `className` | `string` |  |  |
| `align` | `"block-end" \| "block-start" \| "inline-end" \| "inline-start"` |  |  |
| `children` | `function \| ReactNode` |  | Your own mark (a logo set of your own) in place of the badge; a function gets the brand. |

### CardNumberInputControl

| 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"` |  |  |

## Styling

| Part | Slot | States | CSS variables | Tokens |
| --- | --- | --- | --- | --- |
| CardNumberInput | `card-number-input` |  |  |  |
| CardNumberInputBrand | `card-number-input-brand` | `data-pop`, `data-size` |  | `motion-timing` |
| CardNumberInputControl | `card-number-input-control` |  |  |  |

## Usage

Put the brand badge and the control in the input, inside a Field with a label and an error.

The sample also uses `field`, which this add does not write. One command adds them with this item:

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

```tsx title="card-number.tsx"
import { useState } from "react";

import {
  CardNumberInput,
  CardNumberInputBrand,
  CardNumberInputControl,
} from "@/components/ui/pro/card-number-input";
import { Field, FieldError, FieldLabel } from "@/components/ui/field";

export function CardNumber() {
  const [invalid, setInvalid] = useState(false);
  return (
    <Field name="card" invalid={invalid}>
      <FieldLabel>Card number</FieldLabel>
      <CardNumberInput
        onValueChange={(_value, details) => {
          setInvalid(details.complete && !details.valid);
        }}
      >
        <CardNumberInputBrand />
        <CardNumberInputControl />
      </CardNumberInput>
      <FieldError match>This card number is not valid.</FieldError>
    </Field>
  );
}
```

## 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-number-input
```

It adds 33 registry items: 30 files, 6230 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

- [Card Brand](https://gelatinui.com/components/card-brand.md)
- [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 Brand](https://gelatinui.com/components/card-brand.md)
- [Card Field](https://gelatinui.com/components/card-field.md)
- [Card Code Input](https://gelatinui.com/components/card-code-input.md)
- [Field](https://gelatinui.com/components/field.md)

## Accessibility

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

The brand badge is decorative. Say the brand in text when it matters.

## Motion

| Part | Motion |
| --- | --- |
| Brand badge | popup · 150ms · ease-panel (0.2, 0.4, 0.2, 1) · a new brand badge fades in and scales from 90% |
| Rejected key | indicator · the frame moves 2px to each side and back when the mask rejects a key |
