Card
A container component for grouping related content and actions.
Card Title
Card description goes here.
Card content
Installation
Install the component Card in your project using the CLI.
Card.tsx
pnpm dlx behsseui@latest add CardInstall the component manually.
Create a ui folder at the root of the project, then a component folder inside it, and finally a Card.tsx file in that folder.
Copy and paste the following code into your project.
ui/components/Card.tsx
1import { cn } from "@/lib/utils"23interface CardProps extends React.HTMLAttributes<HTMLDivElement> {}45function Card({ className, ...props }: CardProps) {6 return (7 <div8 className={cn(9 "rounded-lg border border-border bg-card text-card-foreground shadow-sm",10 className11 )}12 {...props}13 />14 )15}1617interface CardHeaderProps extends React.HTMLAttributes<HTMLDivElement> {}1819function CardHeader({ className, ...props }: CardHeaderProps) {20 return (21 <div22 className={cn("flex flex-col space-y-1.5 p-6", className)}23 {...props}24 />25 )26}2728interface CardTitleProps extends React.HTMLAttributes<HTMLHeadingElement> {}2930function CardTitle({ className, ...props }: CardTitleProps) {31 return (32 <h333 className={cn("text-2xl font-semibold leading-none tracking-tight", className)}34 {...props}35 />36 )37}3839interface CardDescriptionProps extends React.HTMLAttributes<HTMLParagraphElement> {}4041function CardDescription({ className, ...props }: CardDescriptionProps) {42 return (43 <p44 className={cn("text-sm text-muted-foreground", className)}45 {...props}46 />47 )48}4950interface CardContentProps extends React.HTMLAttributes<HTMLDivElement> {}5152function CardContent({ className, ...props }: CardContentProps) {53 return (54 <div55 className={cn("p-6 pt-0", className)}56 {...props}57 />58 )59}6061interface CardFooterProps extends React.HTMLAttributes<HTMLDivElement> {}6263function CardFooter({ className, ...props }: CardFooterProps) {64 return (65 <div66 className={cn("flex items-center p-6 pt-0", className)}67 {...props}68 />69 )70}7172export { Card, CardHeader, CardTitle, CardDescription, CardContent, CardFooter }73Usages
Different variants and use cases for the Card component.
Default
A basic card with header, title, description and content.
Card Title
Card description goes here.
Card content
Default.tsx
<Card>
<CardHeader>
<CardTitle>Card Title</CardTitle>
<CardDescription>Card description goes here.</CardDescription>
</CardHeader>
<CardContent>
<p>Card content</p>
</CardContent>
</Card>Simple
A simple card with only content.
A simple card with only content.
Simple.tsx
<Card>
<CardContent className="pt-6">
<p>A simple card with only content.</p>
</CardContent>
</Card>