Skip to main content

Overview

The Card component provides a structured way to display content in a self-contained container. It’s built with composition in mind, allowing you to combine different parts like headers, titles, descriptions, content areas, and footers to create rich card layouts.

Use Cases

  • Product listings and feature cards
  • User profile cards and dashboard widgets
  • Article previews and blog post summaries
  • Settings panels and configuration sections
  • Call-to-action containers

Installation

The Card component is included with the UI package. Make sure you have @zayne-labs/ui-react installed:

Basic Usage

Component Parts

The Card component is composed of several parts that can be used together:

Card.Root

The root container for the card. Renders as an article element by default.
Props:
  • as - Change the rendered element (default: "article")
  • asChild - Merge props with child element using Slot pattern
  • className - Custom CSS classes
  • All standard HTML attributes for the element type

Card.Header

Container for the card’s header section. Renders as a header element by default.

Card.Title

The main heading for the card. Renders as an h3 element by default with semibold styling.

Card.Description

A muted text description. Renders as a p element with muted foreground color.

Card.Content

The main content area of the card. Renders as a div by default.

Card.Action

A button element for card actions. Renders as a button by default.
Container for the card’s footer section. Renders as a footer element by default.

Examples

Product Card

User Profile Card

Minimal Card

Using asChild with Custom Elements

Styling

All Card parts accept className props and include data attributes for styling:

Data Attributes

Each part includes these data attributes:
  • data-scope="card" - Identifies the component scope
  • data-part - Identifies the specific part (root, header, title, etc.)
  • data-slot - Identifies the slot name (card-root, card-header, etc.)

CSS Example

Polymorphic Components

Most Card parts support the as prop to change the rendered element:

Accessibility

  • The Card.Root renders as a semantic article element by default
  • Card.Header and Card.Footer use semantic header and footer elements
  • Card.Title uses heading elements (h3 by default) for proper document outline
  • Card.Action includes type="button" by default

API Reference

For detailed prop types and advanced usage, see the Card API Reference.