Card

updated

Impressive. Very nice. Let's see Paul Allen's card. A surface that groups related content, with header, title, description, content and footer parts.

Demo

Upgrade to Pro

Unlimited projects and priority support for your whole team.

$12

per member, per month

Open Props in the corner of the example to try variant and size.

size goes from xs to xl, md by default. Padding, gap and radius grow together. The title and description keep their text size, so a text-* class of your own on them wins.

Bone. Eggshell. Romalian type. Ours come in four:

  • outline (default): a surface with an edge
  • solid: no edge, a small shadow instead; for a card on a plain page
  • soft: a tinted surface, no edge
  • subtle: a tint with an edge; for grouping controls or a card on a card

Switching variants never moves the layout, and an image that reaches the sides never covers the edge.

Installation

Usage

<script setup lang="ts">
import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from '@/components/ui/card'
</script>

<template>
  <Card>
    <CardHeader>
      <CardTitle>Title</CardTitle>
      <CardDescription>Description</CardDescription>
    </CardHeader>
    <CardContent>Content</CardContent>
    <CardFooter>Footer</CardFooter>
  </Card>
</template>

Every part is optional: leave one out, and no gap is left behind.

All the spacing comes from one variable, --card-spacing. size sets it, and a class like [--card-spacing:--spacing(8)] overrides it. Colours are --card and --card-foreground.

Examples

Edge to edge

Want content to reach the edges?

  • A list: px-0 on the part, so the items and their hover reach the sides. Let the items pad themselves, like the Items of the card's size here.
  • An image on top: pt-0 and overflow-hidden on the card.
Edge to edge
A river below a forested mountain

Jacques-Cartier

Three trails start at the visitor centre.

Dividers

Add border-b to the header or border-t to the footer, and it pads itself away from the line.

Divided

Team members

Three people can open this project.

  • Ada LovelaceOwner
  • Alan TuringEditor
  • Grace HopperViewer

API Reference

Every part takes a class that merges with its own.

Data attributes

data-slotAttributesDescription
carddata-variant, data-sizeThe surface.
card-header—Title and description.
card-title—The title.
card-description—Supporting text.
card-content—The main content.
card-footer—Actions.

Accessibility

CardTitle is an h3. Screen reader users skim pages by headings, so set the level that fits with as: h2 for cards right under the page title, div if the title shouldn't be a heading at all.

Changelog

  1. registry 0.22.0

    6784a5e — ScrollArea sizes from its content: max-h-*, flex-1 (with or without min-h-0), a grid row and auto height work, so a Card body or a chip strip needs no fixed height. A ScrollArea with no size now shows its content instead of collapsing, and virtualize without a bounded height or width warns once in development.

    Inside a ScrollArea, a Table's own sideways scrolling turns off, so a sticky TableHeader sticks to the area; give the ScrollArea orientation="both" when the table can be wider than it.

    dd958f2 — border-b on CardHeader and border-t on CardFooter, the Card page's divider recipe, draw in --border instead of the text colour: both parts carry border-border, since Tailwind's preflight leaves borders at currentColor.

  2. registry 0.21.0

    e5495ef — size works the same way everywhere. Every component exports its size type (AlertSize, BadgeSize, CardSize, CheckboxSize, RadioSize, SwitchSize, EmptySize, InputFloatingSize, ItemSize, ListboxSize, SeparatorSize, SliderSize, StepperSize, TabsSize, TextareaSize, TimelineSize) and the props take it without null; Button-based parts take ButtonSize, Input TextControlSize, SelectTrigger SelectSize and Tree TreeSize. ToggleGroup and ToolbarToggleGroup carry data-size on the group as well. Table's row heights moved into tableSize, so a class on DataTable's ui.table overrides --table-row-h at every size, not only at md.

  3. registry 0.19.0

    adf96cd — Parts no longer style themselves from their root's size through group-data-[size=…] variants, which beat any plain class of yours. size is the density of the root, and a class on a part wins:

    - Card, Empty, Alert and Stepper: CardTitle, CardDescription, EmptyTitle, EmptyDescription, AlertTitle, AlertDescription, StepperTitle and StepperDescription keep one text size at every root size (title-md/body-md, title-sm/body-md for Alert, title-sm/body-sm for Stepper). Empty's icon and gaps and Stepper's indicator number still follow the size, through --empty-icon, --empty-header-gap, --empty-content-gap and --stepper-text on the root. - Menu and DrawerMenu labels, Menubar triggers and the Calendar heading, weekday cells and week numbers keep scaling with the size, through --menu-label, --menubar-text, --calendar-heading and --calendar-label (each with a -leading twin) set by the root. - AlertDialog size="sm" centres its text through the content, so text-start on AlertDialogHeader wins; the footer keeps its two-column grid.

  4. registry 0.8.0

    0f257de — Card: outline and subtle draw their edge as a one-pixel ring outside the box instead of a border, so every variant has the same size, as Button's do, and content that reaches the sides, a flush image or a list of items, never covers it.

  5. registry 0.6.0

    4e35ec3 — Card takes size from xs to xl on one --card-spacing (md is the default and replaces default) and variant: outline (unchanged, the default), solid with a small shadow and no border, soft tinted, subtle tinted with a border. ChoiceGroup is the layout behind CheckboxGroup and RadioGroup's variant and orientation, in its own choice-group item; radio-group depends on it instead of on checkbox.