Skip to main content

Components

Card

Card highlight information or tasks that are related. The component comes in two variants and can contain text, images, text fields, buttons, and links.

Usage

Code examples

Colours

Cards come in all theme colours and have two variants.

With sections

Use multiple Card.Block elements if you want to divide the card with separators or add images or video that extend to the edge. Note that when you use Card.Block, all content must be placed inside a Card.Block and not directly in the Card.

Card can be used as a navigation card to take users to another page.

There are two ways to do this.

If the card should link to another page, you can place a link in the card’s title.
The entire card then becomes clickable, but screen reader users get a better experience than if the whole card were a link (adrianroselli.com).

In this example, Card renders an <a> inside the heading element.
This is useful when Card contains text or media and should navigate to another page.

The entire card can become a link by using asChild. This is useful when you want all text and content in the Card to be read by screen readers as one continuous link.

In this example, Card renders as <a>.

Horizontal

You can switch between display: flex and display: grid to place Card.Block next to each other:

HTML

Card has two class names you can use.

  • ds-card: The main class that wraps the entire card.
  • ds-card__block: The class used for each section within the card.

CSS variables and data attributes

Card has two CSS classes, but all CSS variables are attached to the main class ds-card.

CSS Variables
NameValue
--dsc-card-background--activevar(--ds-color-surface-active)
--dsc-card-background--hovervar(--ds-color-surface-hover)
--dsc-card-backgroundvar(--ds-color-surface-default)
--dsc-card-border-widthvar(--ds-border-width-default)
--dsc-card-border-stylesolid
--dsc-card-border-colorvar(--ds-color-border-subtle)
--dsc-card-block-border-widthvar(--dsc-card-border-width)
--dsc-card-block-border-stylevar(--dsc-card-border-style)
--dsc-card-block-border-colorvar(--dsc-card-border-color)
--dsc-card-colorvar(--ds-color-text-default)
--dsc-card-content-margin-blockvar(--ds-size-3) 0
--dsc-card-paddingvar(--ds-size-6)
--dsc-card-border-radiusvar(--ds-border-radius-lg)
Data Attributes
NameValue
data-variantdefault, tinted
Edit this page on github.com (opens in a new tab)