Card

Container for content with header, body, and footer sections.

Installation

Add the Card component using the CLI:

shadcnblazor component add card

Usage

Displays a card with header, content, and footer. Use Header, ChildContent, and Footer child content to compose the card. When Header or Footer are provided, they render as distinct sections with borders and consistent padding.

Login to your account

Enter your email below to login to your account

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<Card Class="w-[350px]">
    <Header>
        <h3 class="text-lg font-semibold">Login to your account</h3>
        <p class="text-sm text-muted-foreground">Enter your email below to login to your account</p>
    </Header>
    <ChildContent>
        <div class="space-y-4">
            <div class="space-y-2">
                <label for="email" class="text-sm font-medium">Email</label>
                <Input id="email" Type="email" Placeholder="m@example.com" />
            </div>
            <div class="space-y-2">
                <div class="flex items-center justify-between">
                    <label for="password" class="text-sm font-medium">Password</label>
                    <Button Variant="@Variant.Link" Size="@Size.Sm" Class="px-0 text-xs">Forgot your password?</Button>
                </div>
                <Input id="password" Type="password" />
            </div>
        </div>
    </ChildContent>
    <Footer>
        <div class="flex flex-col gap-2 w-full">
            <Button Variant="@Variant.Default" Class="w-full">Login</Button>
            <Button Variant="@Variant.Outline" Class="w-full">Login with Google</Button>
        </div>
    </Footer>
</Card>

Examples

Size

Use the Size parameter set to CardSize.Sm for a more compact card. The small size variant uses smaller spacing.

Small Card

This card uses the small size variant.

The card component supports a size prop that can be set to "sm" for a more compact appearance.

1
2
3
4
5
6
7
8
9
<Card Size="@CardSize.Sm" Class="w-[350px]">
    <Header>
        <h3 class="text-lg font-semibold">Small Card</h3>
        <p class="text-sm text-muted-foreground">This card uses the small size variant.</p>
    </Header>
    <ChildContent>
        <p class="text-sm text-muted-foreground">The card component supports a size prop that can be set to "sm" for a more compact appearance.</p>
    </ChildContent>
</Card>

Image

Add an image in the Header slot to create a card with an image. Use HeaderClass="p-0" for a full-bleed image.

Event cover

Design systems meetup

A practical talk on component APIs, accessibility, and shipping faster.

Featured
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<Card Class="w-[350px]" HeaderClass="p-0">
    <Header>
        <img src="https://placehold.co/400x200" alt="Event cover" class="aspect-video w-full object-cover rounded-t-xl" />
    </Header>
    <ChildContent>
        <div class="flex items-start justify-between gap-2">
            <div>
                <h3 class="text-lg font-semibold">Design systems meetup</h3>
                <p class="text-sm text-muted-foreground">A practical talk on component APIs, accessibility, and shipping faster.</p>
            </div>
            <Badge Variant="@Variant.Secondary">Featured</Badge>
        </div>
    </ChildContent>
    <Footer>
        <Button Variant="@Variant.Default" Class="w-full">View Event</Button>
    </Footer>
</Card>

Variants

Use the Variant parameter to switch between Default (card background) and Outline (transparent with border).

Default

Uses the card background color.

Outline

Transparent background with border.

1
2
3
4
5
6
7
8
9
10
<div class="flex flex-col gap-4 w-fit">
    <Card Variant="@CardVariant.Default" Class="w-[350px] gap-2">
        <h3 class="text-lg font-semibold">Default</h3>
        <p class="text-sm text-muted-foreground">Uses the card background color.</p>
    </Card>
    <Card Variant="@CardVariant.Outline" Class="w-[350px] gap-2">
        <h3 class="text-lg font-semibold">Outline</h3>
        <p class="text-sm text-muted-foreground">Transparent background with border.</p>
    </Card>
</div>

API Reference

Card

A container card with optional header and footer sections.

Properties

Name Type Description
AdditionalAttributes Dictionary<string, Object>
ChildContent RenderFragment The main content of the card.
Class string
ContentClass string Additional CSS classes for the content section.
Footer RenderFragment Optional footer content rendered below the main content.
FooterClass string Additional CSS classes for the footer section.
Header RenderFragment Optional header content rendered above the main content.
HeaderClass string Additional CSS classes for the header section.
Size CardSize The size/spacing of the card sections.
Variant CardVariant The visual style variant of the card.

Methods

Method Returns Description
Equals bool
GetHashCode int
GetType Type
SetParametersAsync Task
ToString string
Mobile support for API reference coming soon.

Loading...

An unhandled error has occurred. Reload 🗙