Skip to main content

Card

stable

Overview

Cards are versatile content structures that group related concepts and tasks together as well as provide an entry point to more complex and detailed information.

Usage

When to use

  • Use a card to group content that belongs together and reads as one unit: a summary, a record, a choice. A card marks a boundary. Anything inside it is about the same thing.

When not to use

  • Don't use a card to add visual weight to content that already has structure. A section heading and spacing usually do the job with less noise.
  • Don't nest cards. If content inside a card needs its own container, the outer card is doing too much. Split it or use a divider.
  • Don't make the whole card a click target. Card is a static container. Put actions in the footer as buttons or links.

Text overflow

All text within the card’s predefined slots automatically wraps to a new line and forces its containers to grow to fit it.

<img src="/assets/v2/img/components/card/card-behavior-text-overflow.png" alt="The sample text of the card's title, default slot, and footer slot wrap to multiple lines within the card container." />

Media scaling

Media placed within the media slot scales according to its intrinsic aspect ratio. However, custom aspect ratios can be set via component token and media will scale to fill the container.

<img src="/assets/v2/img/components/card/card-behavior-media-scaling.png" alt="Two cards compare the scale of a sample media image. The bottom card is approximately twice as wide as the top card with its image scaling proportionally to fill the media slot of the card." />

Height

Cards grow in height to accommodate the content of the card.

<img src="/assets/v2/img/components/card/card-behavior-height.png" alt="Two cards compare how a card's height accommodates multiple content elements. The container of the left card hugs content that includes a title and sample body text. The container of the right card hugs content that includes a media image, title, body text, and footer text." />

Alternatives

List item

when the content is one row in a set and will be scanned, not read.

Divider

or spacing when you need separation without a boundary.

Anatomy

The card component is made up of nine elements.

  1. Container

    The card surface and its border. Sets the radius, elevation, and padding for everything inside.

  2. Media slot

    Optional image or illustration area at the top of the card.

  3. Header slot

    Holds the title and subtitle.

  4. Default slot

    The card's body. Takes any content.

  5. Footer slot

    Actions or metadata that apply to the whole card.

  6. Title

    The card's name. One line where possible.

  7. Subtitle

    Supporting text under the title. Optional.

  8. Header divider

    Rule between the header and body.

  9. Footer divider

    Rule between the body and footer.

Variants

Body content

Media slot

The media slot allows any type of rich media to be placed at the top of the card. Media can include imagery, video embeds, map embeds, or data visualizations. Custom media layouts can be created and placed within the media slot.

Body content

Header slot

The header slot is a container that is positioned at the top of the main content area and spans the full width of the card. A default layout includes a title and subtitle within the header slot, but it may be customized as needed.

Body content

Default slot

The default slot is a basic container that sits between the header and footer and allows for complete customization of the card’s body content. Text styling is applied to the slot itself to allow for quick insertion of basic text content, but can accommodate a variety of custom layouts and configurations based on the content requirements.

Body content Footer

Footer slot

The footer slot is positioned at the bottom of the content and allows for custom footer layouts. Default styling is applied to the slot to allow for consistent treatment of basic text.

Body content Footer Body content Footer

Dividers

Dividers can be independently added below the header and above the footer. This can help create clearer definition between complex body content and the rest of the card. The dividers can have insets applied to align them to card content as needed.

Body content Footer Body content Footer Body content Footer

Padding

By default, cards have medium padding applied to slots to ensure content can be added without butting up against the edges of the container. A more modest padding can be applied using the small preset, while the padding surrounding the default slot can be completely removed with the none preset. Component tokens are available for fine-grain control of padding when needed.

Custom layouts

The card component is designed to accommodate custom content and layouts within each of its slots. To make the most of this structure, we recommend adding a series of relevant card “micro-layouts” (headers, body content, footers, etc.) to your product library. You can then swap combinations of these layouts into the slots to create a custom card. If that particular card will be used in multiple places throughout your UI, you can then componentize that specific card with the content in place so it can be consistently reused.

Padding

General padding can be set for the card using the padding property. These options apply broad-level padding settings to the entire card. However, custom paddings may be applied to each individual side of each slot to accommodate specific layout considerations. These can be set on the following layers:

  • card-media-wrapper
  • card-header-wrapper
  • card-default-wrapper
  • card-footer-wrapper

When making overrides to the padding, use variables based on Forge’s dimension tokens.

Media slot

One known Figma quirk is that images set using the aspect ratio component within the media slot will not persist between card variants. It’s recommended that you establish the variant you want to use (including padding and dividers) and then set your image.

While the card has its own border radius that can be set, the media slot can also have its own border radius applied. This can help accommodate circumstances where the image is inset and needs rounded corners. In Figma, select the card-media layer and adjust the border radius as needed. Note that, when implemented into code, this isn't applying a border radius to the slot itself. Rather, the radius is applied to whatever content is being placed into the slot (ex., an <img> element).

Configuration

Theming

Tune via style hook

HookDescriptionDefault
1 Container background (1)
HookDescriptionDefault
--jh-card-color-backgroundThe card background-color.--jh-color-container-primary-enabled
1 Container border (1)
HookDescriptionDefault
--jh-card-color-borderThe card border color.--jh-border-decorative-color
1 Container radius (1)
HookDescriptionDefault
--jh-card-border-radiusThe card border-radius.--jh-border-radius-200
2 Media aspect ratio (1)
HookDescriptionDefault
--jh-card-media-aspect-ratioThe media slot aspect-ratio.auto
2 Media padding (1)
HookDescriptionDefault
--jh-card-media-space-paddingThe media slot padding.0
3 Header padding (1)
HookDescriptionDefault
--jh-card-header-space-paddingThe header slot padding. Defaults to --jh-dimension-400 --jh-dimension-600 0. When padding="small", defaults to --jh-dimension-400 --jh-dimension-400 0. When padding="small" and show-header-divider, defaults to --jh-dimension-400. When padding="medium" or padding="none' and show-header-divider,--jh-dimension-400
3 Header text color (1)
HookDescriptionDefault
--jh-card-header-color-textThe header text color.--jh-color-content-primary-enabled
4 Default slot padding (1)
HookDescriptionDefault
--jh-card-default-space-paddingThe default slot padding. Defaults to --jh-dimension-400 --jh-dimension-600. When padding="small", defaults to --jh-dimension-400. When padding="none",--jh-dimension-400
4 Default slot text color (1)
HookDescriptionDefault
--jh-card-default-color-textThe default slot text color.--jh-color-content-primary-enabled
5 Footer padding (1)
HookDescriptionDefault
--jh-card-footer-space-paddingThe footer slot padding. Defaults to 0 --jh-dimension-600 --jh-dimension-400. When padding="small", defaults to 0 --jh-dimension-400 --jh-dimension-400. When padding="small" and show-footer-divider, defaults to --jh-dimension-400. When padding="medium" or padding="none" and show-footer-divider,--jh-dimension-400
5 Footer text color (1)
HookDescriptionDefault
--jh-card-footer-color-textThe footer slot text color.--jh-color-content-secondary-enabled
6 Title text color (1)
HookDescriptionDefault
--jh-card-header-title-color-textThe header title text color.--jh-color-content-primary-enabled
7 Subtitle text color (1)
HookDescriptionDefault
--jh-card-header-subtitle-color-textThe header subtitle text color.--jh-color-content-secondary-enabled

Fixed

  • Header divider — not customizable
  • Footer divider — not customizable

Examples

Default layout

A default layout includes a title and subtitle within the header slot, but it may be customized as needed. The default slot is a basic container that sits between the header and footer. The footer slot is positioned at the bottom of the content.