JGuang

Card

Card · Ant Design

Preview
npm install antd@6.6.5 @ant-design/icons@6.3.4 dayjs@1.11.23

Card

A container for displaying information.

When To Use

A card can be used to display content related to a single subject. The content can consist of multiple elements of varying types and sizes.

Examples

  • Basic card · basic
  • No border · border-less
  • Simple card · simple
  • Customized content · flexible-content
  • Card in column · in-column
  • Loading card · loading
  • Grid card · grid-card
  • Inner card · inner
  • With tabs · tabs
  • Support more content configuration · meta
  • Custom semantic dom styling · style-class

API

Common props ref:Common props

<Card title="Card title">Card content</Card>
PropertyDescriptionTypeDefaultVersionGlobal Config
actionsThe action list, shows at the bottom of the CardArray<ReactNode>-×
activeTabKeyCurrent TabPane's keystring-×
borderedToggles rendering of the border around the card, please use variant insteadbooleantrue×
bodyStyleStyle of card body, please use styles.body insteadCSSProperties--×
variantVariants of Cardoutlined | borderlessoutlined5.24.05.24.0
classNamesCustomize class for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, string> | (info: { props })=> Record<SemanticDOM, string>-5.14.0
coverCard coverReactNode-×
defaultActiveTabKeyInitial active TabPane's key, if activeTabKey is not setstringThe key of first tab×
extraContent to render in the top-right corner of the cardReactNode-×
hoverableLift up when hovering cardbooleanfalse×
headStyleStyle of card head, please use styles.header insteadCSSProperties--×
loadingShows a loading indicator while the contents of the card are being fetchedbooleanfalse×
sizeSize of cardmedium | smallmedium×
tabBarExtraContentExtra content in tab barReactNode-×
tabListList of TabPane's headTabItemType[]-×
tabPropsTabs--×
titleCard titleReactNode-×
typeCard style type, can be set to inner or not setstring-×
stylesCustomize inline style for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, CSSProperties> | (info: { props })=> Record<SemanticDOM, CSSProperties>-5.14.0
onTabChangeCallback when tab is switched(key) => void-×

Card.Grid

PropertyDescriptionTypeDefaultVersion
hoverableLift up when hovering card gridbooleantrue

Card.Meta

PropertyDescriptionTypeDefaultVersionGlobal Config
avatarAvatar or iconReactNode-×
descriptionDescription contentReactNode-×
titleTitle contentReactNode-×

Semantic DOM

Card

Semantic nodeNative descriptionVersion
rootCard root element with positioning, background, border, border-radius, box-shadow, padding and other container styles6.0.0
headerCard header area with flex layout, min-height, padding, text color, font-weight, font-size, background, bottom border and top border-radius5.14.0
titleCard title with inline-block display, flex-grow, text ellipsis and other title display styles5.14.0
extraCard extra operation area in top-right corner with text color and layout styles for additional content5.14.0
coverTitle cover with styles for cover image display and layout5.14.0
bodyCard content area with padding, font-size and other content display styles5.14.0
actionsCard bottom action group with flex layout, list-style reset, background, top border and bottom border-radius for action buttons container5.14.0

Semantic description source: vendor/components/card/demo/_semantic.tsx

Card.Meta

Semantic nodeNative descriptionVersion
rootset root of Card.Meta6.0.0
sectionset section of Card.Meta6.0.0
avatarset avatar of Card.Meta6.0.0
titleset title of Card.Meta6.0.0
descriptionset description of Card.Meta6.0.0

Semantic description source: vendor/components/card/demo/_semantic_meta.tsx

Design Token

Types, inheritance and declarations retain the pinned native source. Defaults are computed by the native theme and may be overridden by ConfigProvider; this table does not invent static defaults.

TokenTypeNative description
headerBgstringBackground color of card header
headerFontSizenumber | stringFont size of card header
headerFontSizeSMnumber | stringFont size of small card header
headerHeightnumber | stringHeight of card header
headerHeightSMnumber | stringHeight of small card header
bodyPaddingSMnumberPadding of small card body
headerPaddingSMnumberPadding of small card head
bodyPaddingnumberPadding of card body
headerPaddingnumberPadding of card head
actionsBgstringBackground color of card actions
actionsLiMarginstringMargin of each item in card actions
tabsMarginBottomnumberMargin bottom of tabs component
extraColorstringText color of extra area

Declaration source: vendor/components/card/style/index.ts

import { unit } from '@ant-design/cssinjs';

import type { CSSObject } from '@ant-design/cssinjs';

import { clearFix, resetComponent, textEllipsis } from '../../style';

import type { FullToken, GenerateStyle, GetDefaultToken } from '../../theme/internal';

import { genStyleHooks, mergeToken } from '../../theme/internal';

export interface ComponentToken {
  /**
   * @desc 卡片头部背景色
   * @descEN Background color of card header
   */
  headerBg: string;
  /**
   * @desc 卡片头部文字大小
   * @descEN Font size of card header
   */
  headerFontSize: number | string;
  /**
   * @desc 小号卡片头部文字大小
   * @descEN Font size of small card header
   */
  headerFontSizeSM: number | string;
  /**
   * @desc 卡片头部高度
   * @descEN Height of card header
   */
  headerHeight: number | string;
  /**
   * @desc 小号卡片头部高度
   * @descEN Height of small card header
   */
  headerHeightSM: number | string;
  /**
   * @desc 小号卡片内边距
   * @descEN Padding of small card body
   */
  bodyPaddingSM: number;
  /**
   * @desc 小号卡片头部内边距
   * @descEN Padding of small card head
   */
  headerPaddingSM: number;
  /**
   * @desc 卡片内边距
   * @descEN Padding of card body
   */
  bodyPadding: number;
  /**
   * @desc 卡片头部内边距
   * @descEN Padding of card head
   */
  headerPadding: number;
  /**
   * @desc 操作区背景色
   * @descEN Background color of card actions
   */
  actionsBg: string;
  /**
   * @desc 操作区每一项的外间距
   * @descEN Margin of each item in card actions
   */
  actionsLiMargin: string;
  /**
   * @desc 内置标签页组件下间距
   * @descEN Margin bottom of tabs component
   */
  tabsMarginBottom: number;
  /**
   * @desc 额外区文字颜色
   * @descEN Text color of extra area
   */
  extraColor: string;
}

interface CardToken extends FullToken<'Card'> {
  /**
   * @desc 卡片阴影
   * @descEN Shadow of card
   */
  cardShadow: string;
  /**
   * @desc 卡片头部内边距
   * @descEN Padding of card header
   */
  cardHeadPadding: number;
  /**
   * @desc 卡片基础内边距
   * @descEN Padding of base card
   */
  cardPaddingBase: number;
  /**
   * @desc 卡片操作区图标大小
   * @descEN Size of card actions icon
   */
  cardActionsIconSize: number;
}

Shared native props

Tips: The following generic properties apply to most antd components; those not supported are described separately.

PropertyDescriptionTypeDefault
styleThe additional styleCSSProperties-
classNameThe additional css classstring-
rootClassNameClassName on the root elementstring-
autoFocusAuto focus when component mounted, only effective for focusable elements like forms, links, etc.booleanfalse

Install and reproduce an example

npm install antd@6.6.5 @ant-design/icons@6.3.4 dayjs@1.11.23

Use ConfigProvider and native App; configure dayjs locale separately. Each example lists its complete source files and additional pinned dependencies in View code. Example names select demos, not universal component props. See the resource setup guide for theme, locale and SSR.

Native type references

The source viewer includes unchanged native implementations and the following source declarations. Inherited types remain in their native packages. English source comments are preserved as code reference.

  • vendor/components/card/Card.tsx
  • vendor/components/card/CardGrid.tsx
  • vendor/components/card/CardMeta.tsx
  • vendor/components/card/index.tsx
  • vendor/components/card/style/index.ts

Source and license

https://github.com/ant-design/ant-design/tree/4a39f54842eade4e565ab336ef6097cd7e723cdd

Original bilingual prose and executable examples are retained. Website-only embeds and token tables are expanded locally. Ant Design is MIT; separately listed dependency notices also apply. Upload previews block outbound requests and do not provide a backend.