Card

Card is a styled container component with border, box-shadow, and border-radius that groups related content. It supports structured layouts with subcomponents or custom content.

Page navigation navigation

React
experimental

React examples

Default

A basic Card with an icon, heading, description, and metadata.

Card Heading

This is a description of the card providing supplemental information.

3 contributors

With image

Use Card.Image to render an edge-to-edge image in the card header instead of an icon.

Octocat

Card with Image

This card uses an edge-to-edge image instead of an icon.

With metadata

Use Card.Metadata to display supplemental metadata content below the description.

primer/react

GitHub's design system implemented as React components for building consistent user interfaces.

1.2k stars

With action

Use Card.Action to place a single interactive control in the top-right corner of the card. The control label should include card context.

primer/react

GitHub's design system implemented as React components for building consistent user interfaces.

1.2k stars

Padding

The padding prop controls the internal padding of the Card. Available values: normal (default), condensed, and none.

Normal padding

This card uses the default normal padding.

Condensed padding

This card uses condensed padding.

No padding

This card uses no padding.

Semantic section

Set as="section" when the card should be exposed as a standalone landmark. When used this way, Card.Heading is automatically wired to the section with aria-labelledby.

primer/react

This card is rendered as a section landmark and uses its heading for accessible labeling.

In a list

When rendering a collection of cards, place each Card inside an <li> so the list provides grouping. See the accessibility guidance for details on semantics and labelling interactive controls.

  • primer/react

  • primer/css

  • primer/octicons

Custom content

When no subcomponents (Card.Icon, Card.Heading, etc.) are used, Card renders as a plain styled container with your arbitrary children.

Custom Content Card

This card uses arbitrary custom content instead of the built-in subcomponents.

  • Item one
  • Item two
  • Item three

More code examples

See the Card Storybook stories

Props

Card

NameDefaultDescription
children Required
React.ReactNode

The contents of the card. Provide either Card.* subcomponents (for example Card.Heading, Card.Description, Card.Metadata) or any custom content. A card with no children will not render.

className
string

CSS class name(s) for custom styling.

padding
'normal'
'none' | 'condensed' | 'normal'

Controls the internal padding of the Card.

borderRadius
'large'
'medium' | 'large'

Controls the border radius of the Card.

as
'div'
'div' | 'section'

The HTML element to render. Use 'section' for standalone Cards (not inside a list of cards) so screen readers announce the Card as a labelled region. When Card.Heading is present, aria-labelledby is automatically wired. Use the default 'div' when the Card is inside an <li> of a list of cards.

Card.Icon

NameDefaultDescription
icon
React.ElementType

An Octicon or custom SVG icon to render.

aria-label
string

Accessible label for the icon. When omitted, the icon is treated as decorative.

Card.Image

NameDefaultDescription
src
string

The image source URL.

alt
""
string

Alt text for accessibility. Defaults to empty string (decorative).

Card.Heading

NameDefaultDescription
as
'h3'
'h2' | 'h3' | 'h4' | 'h5' | 'h6'

The heading level to render. When the parent Card uses as="section", the heading's id is automatically wired to the section's aria-labelledby.

Card.Description

NameDefaultDescription
children Required
React.ReactNode

The descriptive text for the card. Rendered inside a <p> element so should be flowing text content.

Card.Action

NameDefaultDescription
children Required
React.ReactNode

Interactive control for the top-right corner of the card.

Card.Metadata

NameDefaultDescription
children Required
React.ReactNode

Metadata content for the bottom of the card. Accepts any content: plain text, icons, or other Primer components.