Payment Card
Credit or debit card at ISO size, with embossed text and a flippable back.
- Dependencies (1)
Features
- Every part sits where the ISO standards place it, and scales with the card.
- Detects Visa or Mastercard from the first digits of a number.
- Hides every digit but the last four.
- Optional tilt and glare that follow the pointer.
Use cases
- Live preview beside a checkout form.
- Saved payment methods on an account page.
- Hero illustration for a card or banking product.
Installation
pnpm dlx shadcn@latest add @ncdai/payment-card
Usage
import {
PaymentCard,
PaymentCardBack,
PaymentCardBrand,
PaymentCardChip,
PaymentCardContactless,
PaymentCardCvv,
PaymentCardExpiry,
PaymentCardFront,
PaymentCardGlare,
PaymentCardIssuer,
PaymentCardMagstripe,
PaymentCardName,
PaymentCardNumber,
PaymentCardSignature,
PaymentCardTilt,
} from "@/components/payment-card"<PaymentCardTilt>
<PaymentCard flipped={flipped}>
<PaymentCardFront className="bg-primary text-primary-foreground">
<PaymentCardIssuer>Acme Bank</PaymentCardIssuer>
<PaymentCardChip />
<PaymentCardContactless />
<PaymentCardNumber value="4242 4242 4242 4242" />
<PaymentCardExpiry>12/30</PaymentCardExpiry>
<PaymentCardName>NGUYEN CHANH DAI</PaymentCardName>
<PaymentCardBrand brand="visa" />
<PaymentCardGlare />
</PaymentCardFront>
<PaymentCardBack className="bg-primary text-primary-foreground">
<PaymentCardMagstripe />
<PaymentCardSignature />
<PaymentCardCvv>123</PaymentCardCvv>
<PaymentCardBrand brand="visa" />
<PaymentCardGlare />
</PaymentCardBack>
</PaymentCard>
</PaymentCardTilt>Move or resize any part with className. Parts take the face's text color.
PaymentCardTilt and PaymentCardGlare are optional, but the glare needs the tilt.
Composition
Use the following composition to build a PaymentCard
PaymentCardTilt (optional)
└── PaymentCard
├── PaymentCardFront
│ ├── PaymentCardIssuer
│ ├── PaymentCardChip
│ ├── PaymentCardContactless
│ ├── PaymentCardNumber
│ ├── PaymentCardExpiry
│ ├── PaymentCardName
│ ├── PaymentCardBrand
│ └── PaymentCardGlare (optional)
└── PaymentCardBack
├── PaymentCardMagstripe
├── PaymentCardSignature
├── PaymentCardCvv
├── PaymentCardBrand
└── PaymentCardGlare (optional)API reference
PaymentCard
Prop
Type
PaymentCardNumber
Prop
Type
PaymentCardExpiry
Prop
Type
PaymentCardBrand
Prop
Type
PaymentCardTilt
Prop
Type
getPaymentCardBrand
getPaymentCardBrand("4242 4242 4242 4242") // "visa"
getPaymentCardBrand("5555 5555 5555 4444") // "mastercard"
getPaymentCardBrand("3782 822463 10005") // nullData attributes
| Attribute | Element | Present when |
|---|---|---|
data-flipped | PaymentCard | The back is facing out. |
data-brand | PaymentCardBrand | Always, visa or mastercard. |
Examples
Checkout
The card turns over while the CVC field has focus.
Saved cards
Accessibility
- The face turned away is
inert. - Screen readers read only the last four digits of a masked number.
- Tilt ignores touch, so scrolling never moves the card.
- With
prefers-reduced-motion, the card crossfades instead of turning and does not tilt. The glare stays.
References
- ISO/IEC 7810 — card size and corner radius
- ISO/IEC 7816 — chip contact position
License and usage
- Free to use and modify in both personal and commercial projects.
- Attribution is appreciated but not required.
- Released under the MIT License.
Every component here is built and maintained by one person. If you enjoy using them, you can sponsor my work.