Skip to main content

<primer-input-card-number>

Secure, PCI-compliant input for card numbers. Automatically detects and displays card network (Visa, Mastercard, etc.) as user types.

Quick Reference

Parent<primer-card-form>
Propertieslabel, placeholder, aria-label
FeaturesNetwork detection, auto-formatting

Examples

Default

<primer-card-form>
  <primer-input-card-number></primer-input-card-number>
</primer-card-form>

Custom Labels

<primer-input-card-number
  label="Credit Card Number"
  placeholder="Enter your card number"
  aria-label="Your credit card number"
></primer-input-card-number>

No Placeholder

<primer-input-card-number placeholder=""></primer-input-card-number>

In Custom Layout

<primer-card-form>
  <div slot="card-form-content">
    <primer-input-card-number></primer-input-card-number>
    <div style="display: flex; gap: 8px;">
      <primer-input-card-expiry></primer-input-card-expiry>
      <primer-input-cvv></primer-input-cvv>
    </div>
    <button type="submit">Pay</button>
  </div>
</primer-card-form>

Properties

PropertyAttributeTypeDefaultDescription
labellabelstring"Card Number"Label text
placeholderplaceholderstring"4111 1111 1111 1111"Placeholder text
ariaLabelaria-labelstringValue of labelScreen reader label
Setting to empty string "":
  • label: Reverts to default
  • placeholder: Shows no placeholder
  • aria-label: Uses label value

Card Network Detection

Automatically detects:
NetworkExample Prefix
Visa4xxx
Mastercard5xxx
Amex34xx, 37xx
Discover6011
Displays network logo and adjusts formatting (e.g., Amex uses different spacing).

Validation

Validates:
  • Number length matches detected network (e.g., 16 for Visa, 15 for Amex)
  • At least one digit entered
Errors display automatically on submit or blur.

Events

<primer-input-card-number> does not emit its own events. Validation and submission are managed by the parent <primer-card-form>.

Relevant Parent Events

EventEmitted byHow it affects this input
primer:card-submit<primer-card-form-submit> or external dispatchTriggers validation — if this input is invalid, an error message displays below it
primer:card-error<primer-card-form>Emitted when any card input fails validation — payload includes all validation errors
primer:card-success<primer-card-form>Emitted when the form submits successfully

Reacting to card validation errors

const cardForm = document.querySelector('primer-card-form');

cardForm.addEventListener('primer:card-error', (event) => {
  const { errors } = event.detail;
  errors.forEach(err => console.log(err.field, err.message));
});

CSS Properties

This component uses the shared Input Styling Tokens.

Layout

PropertyDescriptionDefault
--primer-space-smallGap between input and network icon8px

Typography

PropertyDescriptionDefault
--primer-typography-body-large-sizeInput text size16px
--primer-typography-body-large-weightInput text weight400
--primer-typography-body-small-sizeLabel text size12px

Colors

PropertyDescription
--primer-color-text-primaryInput text color
--primer-color-text-placeholderPlaceholder text color
--primer-color-text-disabledDisabled text color
--primer-color-text-negativeError message color

Border & Background

PropertyDescription
--primer-radius-smallInput border radius
--primer-color-border-outlined-defaultDefault border
--primer-color-border-outlined-focusFocus border
--primer-color-border-outlined-errorError border
--primer-color-background-outlined-defaultDefault background

Animation

PropertyDescriptionDefault
--primer-animation-durationTransition duration200ms
--primer-animation-easingTransition easingcubic-bezier(0.44, 0, 0.4, 1)

States

StateDescriptionVisual Change
DefaultInitial stateStandard border and background
HoverMouse over inputBorder darkens slightly
FocusInput is focusedBlue border, increased width
FilledValid card number enteredNetwork icon displayed
ErrorInvalid input or validation failedRed border, error message below
DisabledForm or input disabledMuted colors, no interaction

Usage Guidelines

Do

  • Place inside <primer-card-form>
  • Use for card number collection only

Don’t

  • Don’t use <primer-card-network-selector> separately (internal component)
  • Don’t place outside card form context

Content Guidelines

Label

DoDon’t
”Card number""Credit card number” (not all cards are credit)
Use sentence case”CARD NUMBER”

Placeholder

DoDon’t
1234 1234 1234 1234 (formatted example)“Enter your card number” (redundant with label)
Empty placeholder (clean look)A partial number like 4111

Error messages

DoDon’t
”Enter a valid card number""Invalid"
"Card number is incomplete""Error in field”