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.
React
const PreviewEn = () => { return ( <Card style={{ maxWidth: '320px' }} data-color='neutral'> <Heading>Lykkeland Primary School</Heading> <Paragraph> Lykkeland Primary School is a safe and inclusive local school where play, learning and curiosity go hand in hand. </Paragraph> <Paragraph data-size='sm'>Solslett Municipality</Paragraph> </Card> ); }; render(<PreviewEn />)
Usage
Code examples
Colours
Cards come in all theme colours and have two variants.
React
const Variants = () => { const colorVariants = ['accent', 'brand1', 'brand2', 'brand3', 'neutral']; const variants = ['default', 'tinted']; return ( <> {variants.map((variant) => colorVariants.map((color) => ( <Card key={`${variant}-${color}`} data-variant={variant as 'default' | 'tinted'} data-color={color as CardProps['data-color']} > <Card.Block> <Paragraph> {variant}: {color} </Paragraph> </Card.Block> </Card> )), )} </> ); }; render(<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.
React
const MediaEn = () => { return ( <Card data-color='neutral' style={{ maxWidth: '380px' }}> <Card.Block> <video controls preload='metadata' width='100%'> <source src='/videos/designsystemet/designsystemet-info.mp4' type='video/mp4' /> <track label='Norwegian' kind='subtitles' srcLang='nb' src='/videos/designsystemet/designsystemet-info-no.vtt' default /> <track label='English' kind='subtitles' srcLang='en' src='/videos/designsystemet/designsystemet-info-en.vtt' /> Your browser does not support the video tag. </video> </Card.Block> <Card.Block> <Heading>About Designsystemet</Heading> <Paragraph> The video above provides a brief introduction to what Designsystemet is and how it can be used in the development of digital services. </Paragraph> </Card.Block> </Card> ); }; render(<MediaEn />)
Link card
Card can be used as a navigation card to take users to another page.
There are two ways to do this.
1. Card with a link in the title
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.
React
const WithLinkEn = () => { return ( <Card data-color='neutral'> <Card.Block> <Heading> <Link href='https://designsystemet.no' target='_blank' rel='noopener noreferrer' > Myrkheim Museum </Link> </Heading> <Paragraph> The Myrkheim Museum lies in the valley between the old mountain peaks and displays exhibitions from the time when the first travelling companies crossed the land. Here you can explore ancient maps, tools from the great wanderings, and tales preserved by the wardens of the forests. </Paragraph> <Paragraph data-size='sm'> Myrkheim Council for Cultural Heritage </Paragraph> </Card.Block> </Card> ); }; render(<WithLinkEn />)
2. Card as a link
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>.
React
const AsLink = () => { return ( <Card data-color='neutral' asChild> <a href='https://designsystemet.no' rel='noopener noreferrer'> <Heading>Link Card with asChild</Heading> <Paragraph> Most provide as with carried business are much better more the perfected designer. </Paragraph> </a> </Card> ); }; render(<AsLink />)
Horizontal
You can switch between display: flex and display: grid to place Card.Block next to each other:
React
const AsGridEn = () => { return ( <Card data-color='neutral' style={{ display: 'grid', gridTemplateColumns: '1fr 1fr' }} > <Card.Block> <Heading>Wanderer’s Fever</Heading> </Card.Block> <Card.Block> <Paragraph> Symptoms can include restlessness, heightened alertness, and a tendency to look over one’s shoulder. The condition usually eases after a good meal and a safe place to rest. </Paragraph> </Card.Block> </Card> ); }; render(<AsGridEn />)
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.
| Name | Value |
|---|---|
| --dsc-card-background--active | var(--ds-color-surface-active) |
| --dsc-card-background--hover | var(--ds-color-surface-hover) |
| --dsc-card-background | var(--ds-color-surface-default) |
| --dsc-card-border-width | var(--ds-border-width-default) |
| --dsc-card-border-style | solid |
| --dsc-card-border-color | var(--ds-color-border-subtle) |
| --dsc-card-block-border-width | var(--dsc-card-border-width) |
| --dsc-card-block-border-style | var(--dsc-card-border-style) |
| --dsc-card-block-border-color | var(--dsc-card-border-color) |
| --dsc-card-color | var(--ds-color-text-default) |
| --dsc-card-content-margin-block | var(--ds-size-3) 0 |
| --dsc-card-padding | var(--ds-size-6) |
| --dsc-card-border-radius | var(--ds-border-radius-lg) |
| Name | Value |
|---|---|
| data-variant | default, tinted |