Card

A container for grouping related content and actions.

CardExample
Project Update
Deploy your new project in one click.

Your project is ready for deployment. Review the settings and click deploy to go live.

Examples

With action

Use CardAction to place an action button in the header.

CardWithActionExample
Notifications
Manage your notification preferences.

You have 3 unread notifications. Review them to stay up to date.

Use direction="column" on CardFooter to stack buttons vertically.

CardColumnFooterExample
Subscribe
Get the latest updates delivered to your inbox.

Join our newsletter for weekly insights and product updates.

You can wrap the footer in motion.div with AnimatePresence to animate it in and out when conditions change.

CardMotionFooterExample
Profile Settings
Update your profile information.

Installation

Copy the source code below into your project:

tsx
import { mergeProps, useRender } from "@base-ui/react";
import { cn } from "@/lib/utils";

function Card({ className, ...props }: useRender.ComponentProps<"div">) {
  const cardElement = useRender({
    defaultTagName: "div",
    props: {
      ...mergeProps<"div">(props, {
        className: cn(
          "relative flex flex-col rounded-3xl border border-transparent bg-card p-1 dark:border-border",
          className,
        ),
      }),
      "data-slot": "card",
    },
  });
  return cardElement;
}

function CardHeader({ className, ...props }: useRender.ComponentProps<"div">) {
  const cardHeaderElement = useRender({
    defaultTagName: "div",
    props: {
      ...mergeProps<"div">(props, {
        className: cn(
          "@container/card-header grid auto-rows-min grid-rows-[auto_auto] items-start gap-1.5 p-5 has-data-[slot=card-action]:grid-cols-[1fr_auto] [.border-b]:pb-6",
          className,
        ),
      }),
      "data-slot": "card-header",
    },
  });
  return cardHeaderElement;
}

function CardTitle({ className, ...props }: useRender.ComponentProps<"div">) {
  const cardTitleElement = useRender({
    defaultTagName: "div",
    props: {
      ...mergeProps<"div">(props, {
        className: cn("text-lg leading-none font-semibold", className),
      }),
      "data-slot": "card-title",
    },
  });
  return cardTitleElement;
}

function CardDescription({ className, ...props }: useRender.ComponentProps<"div">) {
  const cardDescriptionElement = useRender({
    defaultTagName: "div",
    props: {
      ...mergeProps<"div">(props, {
        className: cn("text-sm text-muted-foreground", className),
      }),
      "data-slot": "card-description",
    },
  });
  return cardDescriptionElement;
}

function CardAction({ className, ...props }: useRender.ComponentProps<"div">) {
  const cardActionElement = useRender({
    defaultTagName: "div",
    props: {
      ...mergeProps<"div">(props, {
        className: cn("col-start-2 row-span-2 row-start-1 self-start justify-self-end", className),
      }),
      "data-slot": "card-action",
    },
  });
  return cardActionElement;
}

function CardPanel({ className, children, ...props }: useRender.ComponentProps<"div">) {
  return (
    <div
      className={cn(
        "w-full rounded-[calc(var(--radius-3xl)-var(--spacing))] border border-border bg-popover p-5",
        className,
      )}
      data-slot="card-panel"
      {...props}
    >
      {children}
    </div>
  );
}

function CardFooter({
  className,
  direction = "row",
  ...props
}: useRender.ComponentProps<"div"> & { direction?: "row" | "column" }) {
  const cardFooterElement = useRender({
    defaultTagName: "div",
    props: {
      ...mergeProps<"div">(props, {
        className: cn(
          "flex items-center gap-2 p-5 [.border-t]:pt-5",
          direction === "row" && "flex-row justify-end",
          direction === "column" && "flex-col",
          className,
        ),
      }),
      "data-slot": "card-footer",
    },
  });
  return cardFooterElement;
}

export {
  Card,
  CardHeader,
  CardFooter,
  CardTitle,
  CardAction,
  CardDescription,
  CardPanel,
  CardPanel as CardContent,
  CardPanel as CardBody,
};

API Reference

Card

PropTypeDefaultDescription
classNamestring-Additional CSS classes to apply to the card container.

CardHeader

PropTypeDefaultDescription
classNamestring-Additional CSS classes to apply to the header container.

CardTitle

PropTypeDefaultDescription
classNamestring-Additional CSS classes to apply to the title element.

CardDescription

PropTypeDefaultDescription
classNamestring-Additional CSS classes to apply to the description element.

CardAction

PropTypeDefaultDescription
classNamestring-Additional CSS classes to apply to the action container.

CardBody

CardBody is an alias for CardPanel.

PropTypeDefaultDescription
classNamestring-Additional CSS classes to apply to the panel container.

CardFooter

PropTypeDefaultDescription
direction"row" | "column""row"Layout direction for the footer content.
classNamestring-Additional CSS classes to apply to the footer container.