---
title: "Card · Ark UI — StyleX Blocks"
description: "Content containers with elevated, outline, subtle, and solid variants — Root resolves variant and size once and every part inherits them through context."
url: "https://stylexblocks.com/components/ark-ui/card/"
agent:
  instructions: "Use this search API to find relevant components and blocks across this site with keywords or natural-language queries, instead of crawling individual pages. Results are returned in Markdown."
  endpoint: "https://stylexblocks.com/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://developers.cloudflare.com/ai-search/how-to/search-for-agents/"
---

# Card

Content containers with elevated, outline, subtle, and solid variants — Root resolves variant and size once and every part inherits them through context.

- Behavior engine: Ark UI
- Also available for: [Base UI](https://stylexblocks.com/components/base-ui/card.md), [UI SDK](https://stylexblocks.com/components/ui-sdk/card.md)
- Category: Layout
- Variants: elevated, outline, subtle, solid
- Sizes: sm, md, lg
- HTML page: https://stylexblocks.com/components/ark-ui/card/

## Install

Configure the project once (sets the behavior engine and import aliases):

```sh
npx stylexblocks init
```

Then add the item as source you own:

```sh
npx stylexblocks add card
```

Equivalent: `npx shadcn add @stylexblocks/card`. Registry item JSON: https://stylexblocks.com/r/ark-ui/card.json

## Usage

```tsx
import { Card } from "#components/ui/ark-ui/card.tsx";
import { Button } from "#components/ui/ark-ui/button.tsx";

export function Example() {
  return (
    // variant/size resolve once on Root; every part inherits them via context
    <Card.Root variant="elevated" size="md">
      <Card.Header>
        <Card.Title>Project settings</Card.Title>
        <Card.Description>Manage tokens and themes.</Card.Description>
      </Card.Header>
      <Card.Body>Rename the project or transfer ownership.</Card.Body>
      <Card.Footer>
        <Button variant="surface" size="sm">Cancel</Button>
        <Button variant="solid" size="sm">Save</Button>
      </Card.Footer>
    </Card.Root>
  );
}

// composition works per part — e.g. render the title as a link:
// <Card.Title asChild><a href="/settings">Project settings</a></Card.Title>
```

## Source

`components/ui/ark-ui/card.tsx`

```tsx
import * as stylex from "@stylexjs/stylex";
import { createSlotRecipeContext } from "#lib/ark-ui/create-slot-recipe-context.tsx";
import { defineSlotRecipe } from "#lib/recipe-props.ts";
import { colorPalette } from '@stylexblocks/ui/color-palette.stylex.ts'
import { fontSizes } from '@stylexblocks/ui/tokens/font-sizes.stylex.ts'
import { fontWeights } from '@stylexblocks/ui/tokens/font-weights.stylex.ts'
import { semanticColors } from '@stylexblocks/ui/semantic-tokens/colors.stylex.ts'
import { semanticRadii } from '@stylexblocks/ui/semantic-tokens/radii.stylex.ts'
import { semanticShadows } from '@stylexblocks/ui/semantic-tokens/shadows.stylex.ts'
import { spacing } from '@stylexblocks/ui/tokens/spacing.stylex.ts'

const cardRoot = stylex.create({
  base: {
    display: 'flex',
    flexDirection: 'column',
    position: 'relative',
    minWidth: 0,
    wordWrap: 'break-word',
    borderRadius: semanticRadii.panel,
    '--card-radius': semanticRadii.panel,
    '--card-concentric-radius':
      'max(0px, calc(var(--card-radius) - var(--card-padding)))',
    color: semanticColors.fg,
    textAlign: 'start',
  },
})

const cardRootSizes = stylex.create({
  sm: {
    '--card-padding': spacing._2_5,
  },
  md: {
    '--card-padding': spacing._4,
  },
  lg: {
    '--card-padding': spacing._6,
  },
})

const cardRootVariants = stylex.create({
  elevated: {
    backgroundColor: semanticColors.bgPanel,
    boxShadow: semanticShadows.md,
    borderWidth: '0.5px',
    borderColor: semanticColors.borderEmphasized,
  },
  outline: {
    backgroundColor: semanticColors.bgPanel,
    borderWidth: '1px',
    borderColor: semanticColors.border,
  },
  subtle: {
    backgroundColor: colorPalette.muted,
  },
  solid: {
    backgroundColor: colorPalette.solid,
    color: colorPalette.contrast,
  },
})

const cardTitle = stylex.create({
  base: {
    fontWeight: fontWeights.medium,
  },
})

const cardTitleSizes = stylex.create({
  sm: {
    fontSize: fontSizes.sm,
  },
  md: {
    fontSize: fontSizes.md,
  },
  lg: {
    fontSize: fontSizes.lg,
  },
})

const cardDescription = stylex.create({
  base: {
    color: semanticColors.fgMuted,
    fontSize: fontSizes.sm,
  },
})

const cardDescriptionVariants = stylex.create({
  solid: {
    color: `color-mix(in oklch, ${colorPalette.contrast} 80%, transparent)`,
  },
})

const cardHeader = stylex.create({
  base: {
    paddingInline: 'var(--card-padding)',
    paddingTop: 'var(--card-padding)',
    display: 'flex',
    flexDirection: 'column',
    gap: spacing._1_5,
  },
})

const cardBody = stylex.create({
  base: {
    padding: 'var(--card-padding)',
    flex: 1,
    display: 'flex',
    flexDirection: 'column',
  },
})

const cardFooter = stylex.create({
  base: {
    display: 'flex',
    alignItems: 'center',
    gap: spacing._2,
    paddingInline: 'var(--card-padding)',
    paddingBottom: 'var(--card-padding)',
  },
})

export type CardSize = keyof typeof cardRootSizes

export type CardVariant = keyof typeof cardRootVariants

// defineSlotRecipe validates the shape at compile time: default values must
// exist in the axis maps, and slot keys must be `styles` or a declared axis
const cardSlotRecipe = defineSlotRecipe({
  slots: {
    root: { styles: cardRoot, sizes: cardRootSizes, variants: cardRootVariants },
    header: { styles: cardHeader },
    title: { styles: cardTitle, sizes: cardTitleSizes },
    description: { styles: cardDescription, variants: cardDescriptionVariants },
    body: { styles: cardBody },
    footer: { styles: cardFooter },
  },
  defaultVariants: { variant: "elevated", size: "md" },
});

/**
 * Card — recipe and component colocated in one file. `<Card.Root variant
 * size>` resolves the recipe once and every part inherits it through
 * context; each part composes via `asChild`.
 */
const { withProvider, withContext } = createSlotRecipeContext(cardSlotRecipe);

export const Card = {
  // slot names resolve mechanically from the recipe maps above
  Root: withProvider("div", "root", "CardRoot"),
  Header: withContext("div", "header", "CardHeader"),
  Title: withContext("h3", "title", "CardTitle"),
  Body: withContext("div", "body", "CardBody"),
  Footer: withContext("div", "footer", "CardFooter"),
  // or an explicit resolver when a slot styles only some variants —
  // TypeScript errors here the moment `solid` leaves the map above
  Description: withContext(
    "p",
    (v) => [
      cardDescription.base,
      v.variant === "solid" && cardDescriptionVariants.solid,
    ],
    "CardDescription",
  ),
};
```
