---
title: "Card Field"
description: "Take a card number, expiry date, and security code in one row. The brand sets the groups and the code length, and one line names the first problem."
url: https://gelatinui.com/components/card-field
markdown_url: https://gelatinui.com/components/card-field.md
access: pro
install: "npx shadcn@latest add @gelatin-ui-pro/card-field"
version: "2026-11-09"
index: https://gelatinui.com/llms.txt
docs_index: https://gelatinui.com/docs/llms.txt
---

# Card Field

> Take a card number, expiry date, and security code in one row. The brand sets the groups and the code length, and one line names the first problem.

Page: https://gelatinui.com/components/card-field

## When to use it

Best for: A checkout or billing page that takes one card in a single compact frame.

- Use it when the card number, the expiry, and the code belong together, as in a checkout.
- Use `showErrors` after a submit or a decline, so every problem shows at once.
- Use `labels` to translate the input names and the error texts.

## When not to use it

- For a number, an expiry, or a code in their own fields, use a [Card Number Input](https://gelatinui.com/components/card-number-input.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 `CardFieldLabel`, `CardFieldGroup` (the frame), `CardFieldBrand`, `CardFieldNumber`, `CardFieldExpiry`, `CardFieldCvc`, and `CardFieldError`.
- `onValueChange(value, details)`: `details.complete` is true when every part passes; `details.brand`, `details.number`, `details.expiry`, and `details.problems` hold the rest.
- An error shows for a part after it loses focus with text in it, or for every part with `showErrors`.
- The expiry check uses the time the field mounts. Pass `now` for a fixed date in tests.
- Send the card to your payment provider. Do not log it or keep it in your own state store.

## Anatomy

```text
CardField
├─ CardFieldLabel (0..n)
├─ CardFieldGroup (0..n)
├─ CardFieldBrand (0..n)
├─ CardFieldNumber (0..n)
├─ CardFieldExpiry (0..n)
├─ CardFieldCvc (0..n)
└─ CardFieldError (0..n)
```

## API reference

### CardField

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `disabled` | `boolean` | false |  |
| `value` | `CardValue` |  | The three parts as shown (controlled). Raw digits are formatted: "0829" shows "08/29". |
| `defaultValue` | `Partial<CardValue>` |  | The three parts at first (uncontrolled). |
| `onValueChange` | `function` |  | Runs on every change with the shown parts and the details (brand, raw parts, problems). |
| `now` | `DisplayNow` |  | "Now" for the expiry check (tests, stories). Default: the time the field mounts. |
| `labels` | `Partial<CardLabels>` |  | The words (`CARD_LABELS`): the accessible names of the three inputs and the error texts, to translate them. `{length}` in `cvcIncomplete` is the code length of the brand. |
| `placeholders` | `Partial<Record<CardPart, string>>` |  |  |
| `readOnly` | `boolean` | false |  |
| `showErrors` | `boolean` | false | Show the problems of every part now, as after a submit (a declined payment, a server check). |

### CardFieldLabel

No props of its own: `className`, `children`, and every other prop go to the element it renders.

### CardFieldGroup

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `rounded` | `"default" \| "full"` |  |  |
| `size` | `"default" \| "lg" \| "sm" \| "xs"` |  |  |
| `variant` | `"dashed" \| "default"` |  |  |
| `className` | `string` |  |  |

### CardFieldBrand

| 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. |

### CardFieldNumber

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

### CardFieldExpiry

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

### CardFieldCvc

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

### CardFieldError

No props of its own: `className`, `children`, and every other prop go to the element it renders.

## Styling

| Part | Slot | States | CSS variables | Tokens |
| --- | --- | --- | --- | --- |
| CardField | `card-field` |  |  |  |
| CardFieldLabel | `card-field-label` |  |  |  |
| CardFieldGroup | `card-field-group` |  |  |  |
| CardFieldBrand | `card-field-brand` | `data-pop`, `data-size` |  | `motion-timing` |
| CardFieldNumber | `card-field-number` |  |  |  |
| CardFieldExpiry | `card-field-expiry` |  |  |  |
| CardFieldCvc | `card-field-cvc` |  |  |  |
| CardFieldError | `card-field-error` |  |  |  |

## Usage

Import Card Field and compose its parts.

```tsx title="card-field.tsx"
import { CardField, CardFieldBrand, CardFieldCvc, CardFieldError, CardFieldExpiry, CardFieldGroup, CardFieldLabel, CardFieldNumber } from "@/components/ui/pro/card-field";

export function CardFieldDemo() {
  return (
    <CardField className="w-md max-w-full">
      <CardFieldLabel>Card details</CardFieldLabel>
      <CardFieldGroup><CardFieldBrand /><CardFieldNumber /><CardFieldExpiry /><CardFieldCvc /></CardFieldGroup>
      <CardFieldError />
    </CardField>
  );
}
```

## 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-field
```

It adds 41 registry items: 38 files, 7192 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 Number Input](https://gelatinui.com/components/card-number-input.md)
- [Input Group](https://gelatinui.com/components/input-group.md)
- [Field](https://gelatinui.com/components/field.md)

## Keyboard

| Keys | Action |
| --- | --- |
| Tab | Moves between the number, the expiry, and the code. |
| Backspace | In an empty expiry or code, moves to the end of the part before it. |

## Accessibility

The parts are native inputs in a `fieldset`, each with its own name (`labels` translates them).

Each input has its `autocomplete` value (`cc-number`, `cc-exp`, `cc-csc`), so the browser can fill the card.

The error line names the first problem, and the input with the problem is marked invalid.

## 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% |
