The Card component is a flexible container with support for multiple sections (header, body, footer, image), visual variants, configurable padding, and hover effects. Perfect for displaying grouped content, articles, product listings, and more.
import { Card, CardHeader, CardBody, CardFooter, CardImage } from '@/components/Card';import { Button } from '@/components/Button';<Card variant="default" hoverable> <CardImage src="https://images.unsplash.com/photo-1618005182384-a83a8bd57fbe" alt="Abstract art" /> <CardHeader> <h3 className="text-lg font-semibold">Card Title</h3> <p className="text-sm text-muted-foreground">Card subtitle</p> </CardHeader> <CardBody> <p className="text-muted-foreground"> This is the main content of the card. It can contain any elements you need. </p> </CardBody> <CardFooter> <Button size="sm" variant="primary"> Learn More </Button> </CardFooter></Card>
{/* No padding - use sub-component padding */}<Card padding="none"> <CardHeader>Header has its own padding</CardHeader> <CardBody>Body has its own padding</CardBody></Card>{/* Small padding */}<Card padding="sm"> <p>Content with small padding</p></Card>{/* Medium padding */}<Card padding="md"> <p>Content with medium padding</p></Card>{/* Large padding */}<Card padding="lg"> <p>Content with large padding</p></Card>
Use elevated for featured or important content that should stand out
Use hoverable for interactive cards
When a card is clickable or leads to another page, set hoverable={true} to provide visual feedback. Consider wrapping the entire card in a link or button for better accessibility.
Maintain consistent structure
Use the same sub-components in the same order across similar cards for visual consistency (e.g., always CardImage → CardHeader → CardBody → CardFooter).
Provide meaningful alt text
Always include descriptive alt text for CardImage to ensure accessibility for screen reader users and when images fail to load.
Consider padding carefully
The padding="none" default allows sub-components to control their own spacing. Use card-level padding when you have custom content that doesn’t use sub-components.