Skip to content
Knowns UI
Get ProSign in

Card Input

A card field for the number, expiry and security code. The number groups for its brand as it is typed with the caret kept, the brand shows as a neutral glyph, and each field checks itself and says what is wrong. Split into labelled fields, or one row where expiry and code fold in after a valid number.

On this page
Used for
  • Add or update a card in billing settings
  • The card step of a checkout
  • A trial that asks for a card
  • Pay a single invoice

Examples

Layout
Size

Inline

Errors

American Express

Disabled

Installation

npx knowns-ui@latest add card-input
For Claude Code, Cursor or Codex: installs it and wires the props to your own data.

Props

value / defaultValue
{ number, expiry, cvc, name? }
The formatted text of each field ("4242 4242 4242 4242", "08 / 29"). Controlled with value, or uncontrolled from defaultValue.
onChange
(value, details) => void
Every edit. details: { brand, digits, last4, expiry: { month, year } | null, complete, errors }.
onComplete
(details) => void
Once, when an edit makes every field check out.
onFieldBlur
(field) => void
A field lost focus: number, expiry, cvc or name.
layout
"split" | "inline"
Default"split"
Split: labelled fields, number then expiry and code. Inline: one row, expiry and code fold in after a valid number.
size
"sm" | "md" | "lg"
Default"md"
28, 32 or 36px high, the same as Input; taller on touch screens.
showErrors
boolean
Defaultfalse
Show every current error now, e.g. after a submit. Otherwise a field shows its error once it is left with text in it.
errors
{ number?, expiry?, cvc?, name? }
The errors to show in place of the field's own, e.g. from your form or a decline.
autoAdvance
boolean
Defaulttrue
Move to the expiry when the number is done, and to the code when the expiry is.
askName
boolean
Defaultfalse
Ask for the name on the card too.
label / labels
ReactNode | null / { number?, expiry?, cvc?, name? }
Default"Card" / -
The inline row's label (the split group's name for screen readers), and the field labels.
disabled
boolean
Defaultfalse
Every field off.
now
number
DefaultDate.now()
For the expiry check.
ref
{ focus(field?) }
Focus a field, or the first one with an error. Opens the inline fold when needed.

Accessibility

  • Each field has a name (a visible label in split, an aria-label in inline that says the format and the code length) and the autocomplete browsers and password managers fill: cc-number, cc-exp, cc-csc, cc-name.
  • The number, expiry and code open the numeric keypad on a phone (inputMode numeric); autocorrect and spellcheck are off.
  • An error is tied to its field (aria-invalid, aria-describedby), so it is read when the field gets focus.
  • The brand is not only a picture: the number field's description says it ("American Express").
  • Inline, the folded expiry and code are inert until they show, so Tab never lands on a hidden field. Moving focus on after the number is a focus change a screen reader announces.

What it handles

  1. 01Spaces the number the brand's way as it is typed or pasted (4-4-4-4, American Express 4-6-5, Diners 4-6-4) and keeps the caret after the digit you typed, even mid-number; Backspace and Delete step over the spaces.
  2. 02Shows the brand as a neutral text glyph from the first digits (Visa, Mastercard, American Express, Discover, JCB, UnionPay, Diners), never a logo, and sizes the security code for it.
  3. 03Checks the number (length and Luhn), the expiry against this month and the code's length, in words a person can act on, under the field they belong to.
  4. 04Formats the expiry as MM / YY as it is typed, reads an autofilled 12/2027, and steps back over the slash.
  5. 05Moves focus on when the number and the expiry are done, so the whole card is typed in one go.
  6. 06Hands back the parsed card on every change (brand, digits, last 4, month and year, complete, errors) and calls onComplete once it all checks out.

States

First render
Nothing moves; a saved card shows with its fields open
none
Brand found
The glyph changes to the brand's letters
instant
Inline, number checks out
Expiry and code fold in from the right: the column opens and they slide 6px and fade in
180ms ease out
Inline, number cleared
They fold back out, while empty
120ms ease out
Field left with an error
The words show under it and the ring turns red
instant
Reduced motion
The fields appear and go at once
0ms

Works with

When to use

When to use

  • Adding or replacing a card in billing settings, inside your own form and save button.
  • The card step of your own checkout or a trial sign-up, in one row or as labelled fields.

When not to use

  • A whole pay step with email, name, wallets and the pay button: use Payment Form.
  • Showing the card on file: use Receipt Card.

Using with AI

Use Copy page for AI above to give your assistant this page, Copy prompt under the install command to have it installed and wired to your data, or connect the Knowns UI MCP server and just ask:

  • Add the Knowns UI Card Input to my app and wire it to my own data.
  • I need adding or replacing a card in billing settings, inside your own form and save button. Set that up with the Knowns UI Card Input.
  • Which Card Input props do I need for a minimal setup? Show me a short example.

With the server connected, your assistant calls get_component({ name: "card-input" }) and search_docs({ query: "card input" }).

Need help?

Stuck on Card Input, or found something off? We read every message.