Skip to main content

What are you looking for?

Try searching for…

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

HTML

Press Enter to start editing
Unable to parse html
const Preview = () => {
  return (
    <Card style={{ maxWidth: '320px' }} data-color='neutral'>
      <Heading>Lykkeland Barneskole</Heading>
      <Paragraph>
        Lykkeland Barneskole er ein trygg og inkluderande nærskule der leik,
        læring og nysgjerrigheit går hand i hand.
      </Paragraph>
      <Paragraph data-size='sm'>Solslett kommune</Paragraph>
    </Card>
  );
};

render(<Preview />)

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 in the card.

CSS variables and data attributes

All CSS variables are tied 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
data-clickdelegatefor

Examples

With sections

If you need sections in the card, use ds-card__block if you want to divide the card with dividers or add images or video that extend to the edge.

Note that when you use ds-card__block, all content must be placed inside elements with ds-card__block - not placed directly in Card.

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

There are two different ways to do this.

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

2. Card with linked elements

If you have a card with multiple interactive elements, such as links or buttons, you can use data-clickdelegatefor to make the entire card clickable while retaining the semantics of the interactive elements.

Horizontal

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

React

Card

variant
Description

Change the background color of the card.

Type
"default" | "tinted"
Default
default
asChild
Description

Change the default rendered element for the one passed as a child, merging their props and behavior.

Type
boolean
Default
false
children
Description

Instances of `Card.Block`, `Divider` or other React nodes

Type
ReactNode
NameTypeDefaultDescription
variant"default" | "tinted"default

Change the background color of the card.

asChildbooleanfalse

Change the default rendered element for the one passed as a child, merging their props and behavior.

childrenReactNode-

Instances of `Card.Block`, `Divider` or other React nodes

CardBlock

asChild
Description

Change the default rendered element for the one passed as a child, merging their props and behavior.

Type
boolean
Default
false
NameTypeDefaultDescription
asChildbooleanfalse

Change the default rendered element for the one passed as a child, merging their props and behavior.

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).

When Card finds an <a> inside the heading element, data-clickdelegatefor will automatically be added to the card. This is useful when Card contains text or media and should navigate to another page.

Note that with keyboard navigation, the focus ring only surrounds the text in the link, not the entire card. This is because link cards can also contain multiple clickable elements (secondary actions), and it is less confusing for users of assistive technology, such as voice control or screen readers, if the link text matches the focus area.

Edit this page on github.com (opens in a new tab)