Beautiful credit card
components for React
A lightweight, fully typed React component that renders realistic credit cards with 3D flip animations, automatic issuer detection, and premium visual themes.
Everything you need
Drop-in component with zero configuration required.
3D Flip Animation
Smooth CSS perspective-based flip when focusing the CVC field. 0.7s cubic-bezier transition for a premium feel.
Auto Issuer Detection
Automatically identifies Visa, Mastercard, Amex, Discover, JCB, Diners, Elo, and more from the card number prefix.
Rich Colors Mode
Toggle premium dark gradients with issuer-specific colors, metallic chip, and glowing text shadows.
Internationalization
Supports English, Portuguese (pt-BR), and Spanish locales. Labels like "VALID THRU" adapt automatically.
Zero CSS Required
All styles are inline. No external CSS imports needed. Works with any framework or styling solution out of the box.
Full TypeScript
Written in TypeScript with exported types for Focused, Issuer, CardSizes, and all props. Great DX guaranteed.
Try it yourself
Type in the fields below to see the card update in real time.
Try typing a Visa number (starts with 4), Mastercard (51-55), or Amex (34/37) to see automatic issuer detection.
12 supported issuers
Automatically detected from the card number prefix.
Simple to use
Get started with just a few lines of code.
import { useState } from "react";
import { CreditCard, type Focused } from "react-credit-cards-library";
function PaymentForm() {
const [card, setCard] = useState({
number: "", name: "", expiry: "", cvc: "",
});
const [focus, setFocus] = useState<Focused>("");
return (
<>
<CreditCard
number={card.number}
name={card.name}
expiry={card.expiry}
cvc={card.cvc}
focus={focus}
richColors
/>
<input
name="number"
placeholder="Card Number"
value={card.number}
onChange={(e) => setCard({ ...card, number: e.target.value })}
onFocus={() => setFocus("number")}
/>
{/* ...more inputs for name, expiry, cvc */}
</>
);
}
API Reference
Fully typed props and exported utilities.
CreditCard Props
| Prop | Type | Required | Description |
|---|---|---|---|
| number | string | Yes | Credit card number (raw or formatted) |
| name | string | Yes | Cardholder name displayed on front |
| expiry | string | Yes | Expiry date (e.g. "12/25") |
| cvc | string | Yes | CVC/CVV code shown on back |
| focus | Focused | Yes | Which field is focused ("number" | "name" | "expiry" | "cvc" | "") |
| richColors | boolean | No | Enable premium dark gradient theme |
| locale | "en" | "pt-BR" | "es" | No | Locale for UI labels |
| cardSizes | CardSizes | No | Custom card dimensions (width, height, maxWidth, maxHeight) |
Exports
| Export | Kind | Description |
|---|---|---|
| CreditCard | Component | Main credit card component (React.memo) |
| formatCardNumber | Function | Format a number string with bullet placeholders |
| getCardIssuer | Function | Detect issuer from card number prefix |
| ISSUERS | Constant | Readonly tuple of all supported issuer strings |
| FOCUSED_FIELDS | Constant | Readonly tuple of all valid focus values |
| Focused | Type | "number" | "name" | "expiry" | "cvc" | "" |
| Issuer | Type | Union of all supported issuer names |