Card

A surface that groups a header, a body and a footer.

Nightly benchmarks
The main branch, timed each night against the last release.
Beta
Runs the suite at 02:00 on the main branch.
Flags any test that slows down by 5% or more.
Posts a chart of the last 30 runs to the team.
import * as stylex from "@stylexjs/stylex"
import { Badge } from "@/components/ui/badge"
import { Button } from "@/components/ui/button"
import {
  Card,
  CardAction,
  CardContent,
  CardDescription,
  CardFooter,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import { HStack, VStack } from "@/components/ui/stack"
import { color, space } from "@/theme/tokens.stylex"
import { CaretRightIcon } from "@phosphor-icons/react/dist/csr/CaretRight"
import { widths } from "@/theme/widths"

const styles = stylex.create({
  footer: { flexDirection: "column", rowGap: space.s2, alignItems: "stretch" },
  chevron: {
    width: space.s4,
    height: space.s4,
    flexShrink: 0,
    marginBlockStart: space.s0_5,
    color: color.mutedForeground,
  },
})

export default function CardDemo() {
  return (
    <Card xstyle={widths.sm}>
      <CardHeader>
        <CardTitle>Nightly benchmarks</CardTitle>
        <CardDescription>
          The main branch, timed each night against the last release.
        </CardDescription>
        <CardAction>
          <Badge variant="secondary">Beta</Badge>
        </CardAction>
      </CardHeader>
      <CardContent>
        <VStack gap={2}>
          <HStack gap={2}>
            <CaretRightIcon aria-hidden="true" {...stylex.props(styles.chevron)} />
            <span>Runs the suite at 02:00 on the main branch.</span>
          </HStack>
          <HStack gap={2}>
            <CaretRightIcon aria-hidden="true" {...stylex.props(styles.chevron)} />
            <span>Flags any test that slows down by 5% or more.</span>
          </HStack>
          <HStack gap={2}>
            <CaretRightIcon aria-hidden="true" {...stylex.props(styles.chevron)} />
            <span>Posts a chart of the last 30 runs to the team.</span>
          </HStack>
        </VStack>
      </CardContent>
      <CardFooter xstyle={styles.footer}>
        <Button>Turn on benchmarks</Button>
        <Button variant="outline">Read the setup guide</Button>
      </CardFooter>
    </Card>
  )
}

Installation

pnpm dlx shadcn@latest add @arene/card

Needs the arene setup first.

Usage

import {
  Card,
  CardAction,
  CardContent,
  CardDescription,
  CardFooter,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
<Card>
  <CardHeader>
    <CardTitle>Weekly digest</CardTitle>
    <CardDescription>A summary of the week's changes.</CardDescription>
    <CardAction>Edit</CardAction>
  </CardHeader>
  <CardContent>
    <p>Sent every Monday at 09:00.</p>
  </CardContent>
  <CardFooter>
    <p>Last sent 3 days ago.</p>
  </CardFooter>
</Card>

Composition

Card
├── CardHeader
│   ├── CardTitle
│   ├── CardDescription
│   └── CardAction
├── CardContent
└── CardFooter

CardHeader is a two-column grid. CardAction sits in the second column and spans both rows, so a title and description stay to its left.

Size

Use size="sm" for a tighter inset and a title one step down.

Default
Sections sit 16px from the edge.
Weekly snapshots. No more manual exports.
Small
12px, and a title one step down.
Weekly snapshots. No more manual exports.
import * as stylex from "@stylexjs/stylex"
import { Button } from "@/components/ui/button"
import {
  Card,
  CardContent,
  CardDescription,
  CardFooter,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import { HStack } from "@/components/ui/stack"

const styles = stylex.create({
  card: { width: "100%", maxWidth: "18rem" },
})

export default function CardSize() {
  return (
    <HStack align="start" gap={4} wrap="wrap" justify="center">
      <Card size="default" xstyle={styles.card}>
        <CardHeader>
          <CardTitle>Default</CardTitle>
          <CardDescription>Sections sit 16px from the edge.</CardDescription>
        </CardHeader>
        <CardContent>Weekly snapshots. No more manual exports.</CardContent>
        <CardFooter>
          <Button>Enable</Button>
        </CardFooter>
      </Card>
      <Card size="sm" xstyle={styles.card}>
        <CardHeader>
          <CardTitle>Small</CardTitle>
          <CardDescription>12px, and a title one step down.</CardDescription>
        </CardHeader>
        <CardContent>Weekly snapshots. No more manual exports.</CardContent>
        <CardFooter>
          <Button size="sm">Enable</Button>
        </CardFooter>
      </Card>
    </HStack>
  )
}

Spacing

Set --arene-card-spacing to change the gap between sections and the inset of every part at once.

Default spacing
Every part sits on the same inset.
The default inset is 16px.
Roomy spacing
Every part sits on the same inset.
This one sets 32px.
import * as stylex from "@stylexjs/stylex"
import { Button } from "@/components/ui/button"
import {
  Card,
  CardContent,
  CardDescription,
  CardFooter,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import { HStack } from "@/components/ui/stack"
import { space } from "@/theme/tokens.stylex"

const styles = stylex.create({
  card: { width: "100%", maxWidth: "18rem" },
  roomy: { width: "100%", maxWidth: "18rem", "--arene-card-spacing": space.s8 },
})

export default function CardSpacing() {
  return (
    <HStack align="start" gap={4} wrap="wrap" justify="center">
      <Card xstyle={styles.card}>
        <CardHeader>
          <CardTitle>Default spacing</CardTitle>
          <CardDescription>Every part sits on the same inset.</CardDescription>
        </CardHeader>
        <CardContent>The default inset is 16px.</CardContent>
        <CardFooter>
          <Button>Apply</Button>
        </CardFooter>
      </Card>
      <Card xstyle={styles.roomy}>
        <CardHeader>
          <CardTitle>Roomy spacing</CardTitle>
          <CardDescription>Every part sits on the same inset.</CardDescription>
        </CardHeader>
        <CardContent>This one sets 32px.</CardContent>
        <CardFooter>
          <Button>Apply</Button>
        </CardFooter>
      </Card>
    </HStack>
  )
}

Bleed content to the card's edges with a negative margin-inline: calc(-1 * var(--arene-card-spacing)), then put the same value back as padding to keep the text on the card's inset. When that content sits above a footer, cancel the section gap less the footer's raised strip with margin-block-end: calc(radius.xl - var(--arene-card-spacing)) on CardContent.

Data sharing agreement
Read the agreement before you join the study.

This agreement covers the survey data held by the Noether Group, including raw responses, derived tables and the notebooks that analyse them.

You may use the data only for the study named in your application. Do not copy it to another workspace or share it with anyone outside the study.

Publications that use the data must cite the dataset by its DOI. Send a draft to the data steward at least two weeks before you submit it.

import * as stylex from "@stylexjs/stylex"
import { Button } from "@/components/ui/button"
import {
  Card,
  CardContent,
  CardDescription,
  CardFooter,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import { VStack } from "@/components/ui/stack"
import { leading, radius, space } from "@/theme/tokens.stylex"
import { widths } from "@/theme/widths"

const styles = stylex.create({
  content: { marginBlockEnd: `calc(${radius.xl} - var(--arene-card-spacing))` },
  panel: {
    marginInline: "calc(-1 * var(--arene-card-spacing))",
    paddingInline: "var(--arene-card-spacing)",
    paddingBlock: space.s4,
    maxHeight: "12rem",
    overflowY: "auto",
    borderBlockStartWidth: 1,
    borderBlockStartStyle: "solid",
    lineHeight: leading.base,
  },
  footer: { justifyContent: "flex-end", columnGap: space.s2 },
})

export default function CardEdgeToEdge() {
  return (
    <Card xstyle={widths.sm}>
      <CardHeader>
        <CardTitle>Data sharing agreement</CardTitle>
        <CardDescription>Read the agreement before you join the study.</CardDescription>
      </CardHeader>
      <CardContent xstyle={styles.content}>
        <VStack gap={4} xstyle={styles.panel}>
          <p>
            This agreement covers the survey data held by the Noether Group, including raw
            responses, derived tables and the notebooks that analyse them.
          </p>
          <p>
            You may use the data only for the study named in your application. Do not copy it to
            another workspace or share it with anyone outside the study.
          </p>
          <p>
            Publications that use the data must cite the dataset by its DOI. Send a draft to the
            data steward at least two weeks before you submit it.
          </p>
        </VStack>
      </CardContent>
      <CardFooter xstyle={styles.footer}>
        <Button variant="outline">Decline</Button>
        <Button>Accept</Button>
      </CardFooter>
    </Card>
  )
}

Image

Put an img first in the card. It runs to the top edge and its corners clip to the card's radius.

A corridor lined with glass-walled offices
Featured
Open lab day
Tour the new building, meet the research groups and see work in progress.
import * as stylex from "@stylexjs/stylex"
import { Badge } from "@/components/ui/badge"
import { Button } from "@/components/ui/button"
import { Card, CardAction, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card"
import { space } from "@/theme/tokens.stylex"
import { widths } from "@/theme/widths"

const styles = stylex.create({
  cover: { width: "100%", aspectRatio: "16 / 9", objectFit: "cover" },
  footer: { columnGap: space.s2 },
})

export default function CardImage() {
  return (
    <Card xstyle={widths.sm}>
      <img
        src="https://images.unsplash.com/photo-1497366754035-f200968a6e72?w=600&auto=format&fit=crop&q=80"
        alt="A corridor lined with glass-walled offices"
        {...stylex.props(styles.cover)}
      />
      <CardHeader>
        <CardAction>
          <Badge variant="secondary">Featured</Badge>
        </CardAction>
        <CardTitle>Open lab day</CardTitle>
        <CardDescription>
          Tour the new building, meet the research groups and see work in progress.
        </CardDescription>
      </CardHeader>
      <CardFooter xstyle={styles.footer}>
        <Button>See the schedule</Button>
        <Button variant="outline">Add to calendar</Button>
      </CardFooter>
    </Card>
  )
}

interop.css pulls the image up with a negative margin keyed on [data-slot="card"] > img:first-child. Without that stylesheet the image sits inside the card's top padding.

API reference

Pass render to replace a part's element or compose it with another component.

Every part renders a div and takes xstyle and className alongside every div attribute.

Card

PropTypeDefault
size"default" | "sm""default"
xstyleStyleXStyles—
classNamestring—

size sets --arene-card-spacing and --arene-card-title-size on the root. Setting either directly overrides it.

CardHeader

A grid of 1fr auto, with a 0.25rem row gap. The second column collapses to nothing without a CardAction.

CardTitle

Reads --arene-card-title-size at weight 500.

CardDescription

Muted text at the card's own size.

CardAction

Pinned to the header's second column and first row, spanning both rows.

CardContent

The card's inset, and nothing else. Vertical rhythm is the root's row gap.

CardFooter

A tray under the card's body. The body's bottom edge rounds over the tray with a hairline shadow. The footer draws that shadow itself, so the body needs no wrapper. It cancels the root's bottom padding, so put it last.

cardStyles

The style maps behind the component. Spread them onto any element.

KeyWhat it is
baseThe surface: fill, ring, radius, shadow, rhythm
sizesdefault and sm, each a pair of variables
headerThe two-column grid
titleThe title's type
descriptionThe muted description
actionThe header's second column
contentThe body's inset
footerThe tray, its raised strip and negative margins

Data attributes

AttributeOnEffect
data-slot="card"the rootWhere interop.css keys a leading image
data-sizethe rootReflects the size prop
data-slot="card-header"the headerTargets the header from a parent
data-slot="card-title"the titleTargets the title from a parent
data-slot="card-description"the descriptionTargets the description from a parent
data-slot="card-action"the actionTargets the action from a parent
data-slot="card-content"the bodyTargets the body from a parent
data-slot="card-footer"the footerTargets the footer from a parent

CSS variables

VariableOnEffect
--arene-card-spacingthe rootThe section gap and every part's inset. 16px, 12px at sm
--arene-card-title-sizethe rootThe title's size. 16px, 14px at sm