shadcn.io is an independent project built on shadcn/ui
On this page9 sections
Credit Card draws a payment card: a chip, the number, the cardholder's name, the expiry and a network mark on the front, and a magnetic stripe with the security code on the back. Inside its flipper it turns over on hover or tap. Put it beside a checkout form to mirror what is being typed, or on a wallet page to show saved cards.
It collects nothing. Take the card itself through your payment provider's fields, and build the rest of the form with Field and Input.
Installation
Anatomy

Usage
import {
CreditCard, CreditCardBack, CreditCardChip, CreditCardCvv,
CreditCardExpiry, CreditCardFlipper, CreditCardFront,
CreditCardMagStripe, CreditCardName, CreditCardNetwork,
CreditCardNumber,
} from "@/components/ui/credit-card";The chip, the stripe and the network mark place themselves inside each face. The number, the name and the expiry are yours to lay out, here in a block along the bottom of the front.
<CreditCard>
<CreditCardFlipper>
<CreditCardFront>
<CreditCardChip />
<div class="absolute inset-x-0 bottom-0 flex flex-col gap-[3.5cqw]">
<CreditCardNumber>4532 •••• •••• 7890</CreditCardNumber>
<div class="flex gap-[6cqw] pe-[22cqw]">
<CreditCardName>Jane Cooper</CreditCardName>
<CreditCardExpiry>12/28</CreditCardExpiry>
</div>
</div>
<CreditCardNetwork type="visa" />
</CreditCardFront>
<CreditCardBack>
<CreditCardMagStripe />
<CreditCardCvv class="absolute end-0 top-[44%]">123</CreditCardCvv>
</CreditCardBack>
</CreditCardFlipper>
</CreditCard>Accessibility
CreditCardFlipper is a div with the button role, in the tab order, and aria-pressed tells which side is up: pressed while the back shows. The face turned away gets aria-hidden, so a screen reader hears only the side in view. A button takes its name from its content, so the number, name, expiry and network on that side are read as one label, and an aria-label on the flipper would replace all of it. Without a flipper the card is plain text that takes no focus. The network mark is an image named for its network, and the chip and stripe are hidden.
- Tab
- Moves focus to the card, when it has a flipper.
- Enter
- Turns the card to its other side.
- Space
- Turns the card to its other side.
Demos
Checkout
A card above fields for the number, name, expiry and CVV, drawing each value as typed, with the network's mark once the first digits name it. The side is held in flipped and onFlippedChange: focusing the CVV turns the card over, except an Amex card, whose code is on the front, and leaving that field turns it back. trigger is click, so a passing pointer leaves it alone.
Colors
Two fronts restyled with a class each: a gradient on the theme's primary color with a Mastercard mark, and the card surface with a border and an Amex mark, its chip and logo muted. The parts draw in currentColor, so the text color set on a face recolors them with it. A brand gradient suits a card your product issues, and the plain surface a saved card in a list.
Networks
Three fronts, one for each type, visa, mastercard and amex, each with the last four digits and a name. Each mark is a simple shape in the card's own color, named for screen readers. These cards have no flipper, so they never turn and take no focus, which suits a list of saved cards where a radio or a button beside each one does the choosing.
FAQ
How do I make the Credit Card flip on click instead of hover?
Set trigger to click on CreditCardFlipper. The default, hover, turns the card while a mouse rests on it, and in both modes a tap, a click, Enter or Space toggles it. Click alone suits a card beside a form, as in the Checkout demo, where a pointer crossing the card on its way to a field shouldn't turn it.
The turn is a 700ms rotation around the vertical axis, mirrored on a right-to-left page, and under reduced motion it becomes an instant swap. For a card that never turns, leave the flipper out and put only CreditCardFront inside CreditCard, as the Networks demo does.
How do I flip the credit card from my own code in Solid?
Pass flipped and update it in onFlippedChange, which receives the new side as a boolean, true for the back.
Once the side lives in your state, anything can turn the card: the Checkout demo shows the back while the CVV field has focus. An uncontrolled card keeps its own state, and defaultFlipped set to true starts it on the back.
How do I show the card number on the Credit Card as someone types it?
Keep the digits in state and pass them to CreditCardNumber formatted as a card prints them. The Checkout demo strips everything but digits from the field, pads the value with dots to the network's length and groups it as that network does, so the card fills in from the left as digits arrive.
The number is always set left to right, in a monospaced font with tabular figures, so it reads the same on a right-to-left page. American Express numbers have 15 digits, grouped 4, 6 and 5, and a four-digit code printed on the front, so the demo keeps an Amex card on its front while that code is typed.
Which card networks can the Credit Card show?
CreditCardNetwork draws three simple marks in the card's text color, for Visa, Mastercard and American Express, picked with type and announced by that name. It doesn't read the number, so choose type from the first digits yourself, as the Checkout demo does: 4 is Visa, 51 to 55 or 2221 to 2720 is Mastercard, and 34 or 37 is Amex.
The marks are stand-ins, not the networks' official logos. For those, or for another network, pass the artwork as the children of CreditCardNetwork, which replaces the mark, and set aria-label to the network's name when it isn't one of the three.
How do I put my bank's logo on the Credit Card?
Put it inside CreditCardLogo on the front. The part is a square, 11% of the card's width, in the top corner on the end side (top right on a left-to-right page) inside the face's margin. An svg placed in it is stretched to fill the square.
An icon drawn in currentColor takes the face's text color, and a text color class on CreditCardLogo overrides it, as the muted logo in the Colors demo shows. An img keeps its own colors and isn't resized for you, so give it the square's full width and height. The logo is read with the rest of the card, so give an image the bank's name as its alt text, or mark an icon aria-hidden as the demos do.
How do I make the Credit Card bigger or smaller?
Give CreditCard a width, or let it fill its container, up to the 384px of its max-w-96 class. It keeps the 85.6 by 53.98 mm shape of a real bank card, and its text, chip, corners and marks are sized in container query units, so all of it scales with the width.
To go past 384px, add a larger max-w class next to the width. safeArea on a face sets the margin kept clear inside its edge, 6% of the card's width by default, as a number of pixels or any CSS length.
How do I change the colors of the Credit Card?
Add classes to CreditCardFront and CreditCardBack. By default each face is bg-foreground with text-background, a dark card on a light page and a light one on a dark page. The chip, the stripe and the network mark draw in currentColor, so a text color on the face recolors them as well, and a class on one part, such as a muted chip, overrides it there.
The Colors demo shows a primary gradient and a bordered card on the page's own surface. To change every card at once, edit the faces' shared classes in the component's file.
Is it safe to show a card number with the Credit Card component?
The component only draws the text you give it and sends nothing anywhere, so the question is how the number reaches it. For a saved card, show the last four digits only, as the Networks demo does.
For a card being entered, the fields that hold the full number should be your payment provider's hosted fields, so the number never passes through your own code. Those fields don't give your page the digits. Stripe's card Element, for one, reports the brand as it changes and the last four digits once the card is saved, and that is what the card can show.
API Reference
CreditCard
<div> data-slot="credit-card"
asChild?(props: ParentProps) => JSX.Element
Render your own element: a function that gets the part's props to spread on it.
- Type
(props: ParentProps) => JSX.Element
class?string
Merged with the part's classes.
CreditCardFlipper
flipped?boolean
Whether the back is showing (controlled).
defaultFlipped?boolean
The face to start on when uncontrolled: true shows the back.
- Default
false
onFlippedChange?(flipped: boolean) → void
Called with the new side whenever it would flip.
- Parameters
flipped– boolean- Returns
void
trigger?"click" | "hover"
What flips the card. hover turns it while a mouse is over it, and a
tap, a click, Enter or Space toggles it; click only toggles.
- Type
"click" | "hover"- Default
"hover"
class?string
Merged with the part's classes.
CreditCardFront
<div> data-slot="credit-card-front"
safeArea?number | string
The space kept clear inside the edge, as real cards keep it: pixels, or any CSS length.
- Type
number | string- Default
"6cqw"
class?string
Merged with the part's classes.
CreditCardBack
<div> data-slot="credit-card-back"
safeArea?number | string
The space kept clear inside the edge, as real cards keep it: pixels, or any CSS length.
- Type
number | string- Default
"6cqw"
class?string
Merged with the part's classes.
CreditCardChip
<svg> data-slot="credit-card-chip"
class?string
Merged with the part's classes.
CreditCardLogo
<div> data-slot="credit-card-logo"
class?string
Merged with the part's classes.
CreditCardNetwork
<div> data-slot="credit-card-network"
type?CreditCardNetworkType
The card network, drawn as a simple mark in the card's own color and named for screen readers. Children replace the mark with your own artwork.
- Default
"visa"
class?string
Merged with the part's classes.
data-type?string
Mirrors type.
CreditCardMagStripe
<div> data-slot="credit-card-mag-stripe"
class?string
Merged with the part's classes.
CreditCardNumber
<p> data-slot="credit-card-number"
class?string
Merged with the part's classes.
CreditCardName
<p> data-slot="credit-card-name"
class?string
Merged with the part's classes.
CreditCardExpiry
<p> data-slot="credit-card-expiry"
class?string
Merged with the part's classes.
CreditCardCvv
<p> data-slot="credit-card-cvv"
class?string
Merged with the part's classes.













