Card Input
Card number, expiry date and security code in one field, formatted as the brand prints them and checked as they are typed.
Attributes
| Name | Type | Default | Description |
|---|---|---|---|
brands | string[] | [] | The brands accepted, by id (visa, mastercard, amex, discover, diners, jcb, unionpay, maestro). Empty accepts all. As an attribute, a ;-separated list. |
name | string | — | Form field name: the form receives name[number], name[expiry] and name[cvc]. With none, the card is not submitted. |
required | boolean | false | Asks for a card before the form submits. |
disabled | boolean | false | Turns the field off; as for a disabled form control, nothing is submitted. |
readonly | boolean | false | Shows the card without letting it be edited. |
label | string | — | The accessible name of the group. Inside a c2-form-field, the field's label names it. |
Slots
| Name | Description |
|---|---|
brand | The mark shown while no brand is detected. Defaults to a card outline. |
brand-visa | The mark of a Visa card, in place of its text badge. Likewise brand-mastercard, brand-amex, brand-discover, brand-diners, brand-jcb, brand-unionpay and brand-maestro. |
Events
| Name | Type | Description |
|---|---|---|
card-change | CustomEvent<CardChangeDetail> | Fired after every edit, with { brand, complete, error, last4 } and never the number. |
input | InputEvent | Fired as any part is typed in. |
change | Event | Fired when a part that was changed loses focus. |
CSS parts
Shadow DOM styling hooks used with ::part(name). Prefer CSS custom properties when they cover the change.
| Name | Description |
|---|---|
field | The box around the three parts. |
brand | The brand mark. |
badge | The text badge of a detected brand. |
number | The card number input. |
expiry | The expiry date input. |
cvc | The security code input. |
error | The line with the problem, hidden inside a c2-form-field, which shows it instead. |
CSS custom properties
Grouped by semantic target and state from --c2-<component>__<target>__<state>--<property>. Click a group to collapse it; click a name to copy it.
| Name | Type | Default | Description |
|---|---|---|---|
--c2-card-input--font-size | font-size | 14px | |
--c2-card-input--color | color | #18181b | |
--c2-card-input--height | pixel | 40px | |
--c2-card-input--padding | padding | 0 12px | |
--c2-card-input--border | border | 1px solid #d4d4d8 | |
--c2-card-input--border-radius | border-radius | 6px | |
--c2-card-input--background | color | #ffffff | |
--c2-card-input--gap | pixel | 12px | Space between the parts. |
--c2-card-input__focus--border | border | 1px solid #0265dc | |
--c2-card-input__focus--outline | outline | 2px solid rgba(2, 101, 220, 0.4) | |
--c2-card-input__error--border | border | 1px solid #dc2626 | |
--c2-card-input__error--color | color | #dc2626 | The problem line and the part at fault. |
--c2-card-input__error--font-size | font-size | 12px | |
--c2-card-input__placeholder--color | color | #71717a | |
--c2-card-input__disabled--opacity | opacity | 0.38 | |
--c2-card-input__expiry--width | width | 7ch | |
--c2-card-input__cvc--width | width | 5ch | |
--c2-card-input__brand--color | color | #71717a | The card outline shown while no brand is detected. |
--c2-card-input__badge--background | color | #f4f4f5 | |
--c2-card-input__badge--color | color | #18181b | |
--c2-card-input__badge--font-size | font-size | 10px | |
--c2-card-input__badge--font-weight | font-weight | 600 | |
--c2-card-input__badge--border-radius | border-radius | 4px | |
Text and languages
The text the component shows, in English. It shows another language when the app adds one with addTranslations, under card-input, and the nearest lang asks for it; any message not translated stays in English. {0}, {1}… stand for the values a message carries. Languages guide.
| Key | English | Values |
|---|---|---|
label | Card details | — |
number | Card number | — |
expiry | Expiry date (MM / YY) | — |
cvc | Security code | — |
numberPlaceholder | 1234 1234 1234 1234 | — |
expiryPlaceholder | MM / YY | — |
cvcPlaceholder | CVC | — |
valueMissing | Please enter your card details. | — |
numberIncomplete | Your card number is incomplete. | — |
numberInvalid | Your card number is invalid. | — |
unsupported | {0} cards are not accepted. | {0} brand |
unsupportedUnknown | This card type is not accepted. | — |
expiryIncomplete | Your card's expiry date is incomplete. | — |
expiryInvalid | Your card's expiry month is invalid. | — |
expiryPast | Your card's expiry date is in the past. | — |
cvcIncomplete | Your card's security code is incomplete. | — |