---
title: "Card Expiry Input"
description: "A field for the card expiry date as MM/YY. It accepts months 01 to 12, fixes pasted dates, and marks a card that has expired."
url: https://gelatinui.com/components/card-expiry-input
markdown_url: https://gelatinui.com/components/card-expiry-input.md
access: pro
install: "npx shadcn@latest add @gelatin-ui-pro/card-expiry-input"
version: "2026-11-09"
index: https://gelatinui.com/llms.txt
docs_index: https://gelatinui.com/docs/llms.txt
---

# Card Expiry Input

> A field for the card expiry date as MM/YY. It accepts months 01 to 12, fixes pasted dates, and marks a card that has expired.

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

## When to use it

Best for: The expiry of a card in its own field, MM/YY, with a check for a past month.

- Use it when the expiry has its own label, next to the number and the code.
- Use `details.expired` from `onValueChange` to say why a full date is not valid.

## 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 full date with a calendar, use a [Date Picker](https://gelatinui.com/components/date-picker.md).

## Notes for agents

- A paste or an autofill of "4/28" or "04/2028" becomes "04/28".
- A past month stays as typed and is not valid. Check it in a `Field` with `cardExpiry().valid`.
- The check uses the display now (a locale provider), else the mount time. Pass `now` for a fixed date in tests.

## Anatomy

```text
CardExpiryInput
└─ CardExpiryInputControl (0..n)
```

## API reference

### CardExpiryInput

| 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 date shows and can be copied, but not changed (the Base UI name). |
| `value` | `string` |  | The shown expiry (controlled). "0829" shows "08/29". |
| `defaultValue` | `string` | "" | The first shown expiry (uncontrolled). |
| `onValueChange` | `function` |  | Runs on every change with the text, `{ month, year }`, the checks, and `expired`. |
| `now` | `DisplayNow` |  | "Now" for the expired check (tests, stories). Default: the display now, else the mount time. |

### CardExpiryInputControl

| 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 |
| --- | --- | --- | --- | --- |
| CardExpiryInput | `card-expiry-input` |  |  |  |
| CardExpiryInputControl | `card-expiry-input-control` |  |  |  |

## Usage

Put the input in a Field with a label and an error; `details.expired` tells you when to show the 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-expiry-input @gelatin-ui/field
```

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

import { CardExpiryInput, CardExpiryInputControl } from "@/components/ui/pro/card-expiry-input";
import { Field, FieldError, FieldLabel } from "@/components/ui/field";

export function CardExpiry() {
  const [expired, setExpired] = useState(false);
  return (
    <Field name="expiry" invalid={expired}>
      <FieldLabel>Expiry</FieldLabel>
      <CardExpiryInput
        onValueChange={(_value, details) => {
          setExpired(details.expired);
        }}
      >
        <CardExpiryInputControl />
      </CardExpiryInput>
      <FieldError match>This card has expired.</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-expiry-input
```

It adds 28 registry items: 25 files, 5419 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 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-exp"` and a number keypad.

The "MM/YY" guide shows the slots still to fill while the input has focus.

## Motion

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