---
title: Card
---

import LibraryInfo from '@theme/LibraryInfo'
import { Feedback, TokensTable, PropsTable } from '../../src/components'
import { Card as WebDocs } from 'docs/@telus-uds/components-web'
import AvailableOnBoth from '../../partials/_platform-considerations-both.mdx'
import { Card as BaseDocs } from 'docs/@telus-uds/components-base'

# Card

<LibraryInfo
  packageType="Multi-Platform Component"
  figmaLink="https://www.figma.com/embed?embed_host=share&url=https%3A%2F%2Fwww.figma.com%2Ffile%2F4zJn2Qn6uXOqPP1GVDipy6%2F%25F0%259F%258D%2580-Allium-Components%3Fnode-id%3D829%253A6868"
/>

```jsx live
<div style={{ maxWidth: '20rem', margin: '0 auto' }}>
  <Card>
    <Typography block variant={{ size: 'h2' }}>
      Connecting with the community
    </Typography>
    <Box top={4}>
      <Typography>
        Card width expands based on the container. Card height expands based on content.
      </Typography>
      <Box top={4}>
        <Button onPress={noop} variant={{ priority: 'high', width: 'full' }}>
          Sign up
        </Button>
      </Box>
    </Box>
  </Card>
</div>
```

## Introduction

Cards are content containers with varying visual styles.

[Follow the appropriate instructions](importing-components) to add this component in to your app.

## Guidance

- Use a card to contain content and visually distinguish itself as a single unit
- A card may contain other components and content such as headings, text, lists, buttons, links, and images
- A card's layout and dimensions depend on it's container
- A card will have 5 standard background options (default, alternative, subtle, and grid)

### Platform considerations

<AvailableOnBoth />

## Props

<PropsTable web={WebDocs} base={BaseDocs} />

## Tokens

<TokensTable base={BaseDocs} component="Card" />

## Style

:::info

Introducing the new `style` variants. These new variants enable brands to design more comprehensively
according to their visual language, support the ability to easily swap between brands, and provide
more intuitive and intentional use. Please note that the `background` variant is deprecated and will
be removed by August 1, 2025 in preference of the `style` variant.

:::

#### Default

```jsx live
<Card variant={{ style: 'default' }}>
  <Typography>This is the default style.</Typography>
</Card>
```

#### Grid

```jsx live
<Card variant={{ style: 'grid' }}>
  <Typography>This is the grid style.</Typography>
</Card>
```

#### Light

```jsx live
<Card variant={{ style: 'light' }}>
  <Typography>This is the light style.</Typography>
</Card>
```

#### Lighter

```jsx live
<Card variant={{ style: 'lighter' }}>
  <Typography>This is the lighter style.</Typography>
</Card>
```

#### Lightest

```jsx live
<Card variant={{ style: 'lightest' }}>
  <Typography>This is the lightest style.</Typography>
</Card>
```

#### Dark

```jsx live
<Card variant={{ style: 'dark' }}>
  <Typography variant={{ colour: 'white' }}>This is the dark style.</Typography>
</Card>
```

#### Darker

```jsx live
<Card variant={{ style: 'darker' }}>
  <Typography variant={{ colour: 'white' }}>This is the darker style.</Typography>
</Card>
```

#### Darkest

```jsx live
<Card variant={{ style: 'darkest' }}>
  <Typography variant={{ colour: 'white' }}>This is the darkest style.</Typography>
</Card>
```

#### Feature

```jsx live
<Card variant={{ style: 'feature' }}>
  <Typography>This is the feature style.</Typography>
</Card>
```

#### Feature2

```jsx live
<Card variant={{ style: 'feature2' }}>
  <Typography>This is the feature2 style.</Typography>
</Card>
```

#### Feature3

```jsx live
<Card variant={{ style: 'feature3' }}>
  <Typography>This is the feature3 style.</Typography>
</Card>
```

#### Feature4

```jsx live
<Card variant={{ style: 'feature4' }}>
  <Typography>This is the feature4 style.</Typography>
</Card>
```

#### Warning

```jsx live
<Card variant={{ style: 'warning' }}>
  <Typography>This is the warning style.</Typography>
</Card>
```

#### Error

```jsx live
<Card variant={{ style: 'error' }}>
  <Typography>This is the error style.</Typography>
</Card>
```

#### Success

```jsx live
<Card variant={{ style: 'success' }}>
  <Typography>This is the success style.</Typography>
</Card>
```

## Background (deprecated)

:::caution

The `background` variant is deprecated and will be removed by August 1, 2025 in preference of the `style` variant.

:::

#### Default background

```jsx live
<Card variant={{ background: 'default' }}>
  <Typography>This is the default background.</Typography>
</Card>
```

#### Alternative background

```jsx live
<Card variant={{ background: 'alternative' }}>
  <Typography>An alternative colour background.</Typography>
</Card>
```

#### Subtle background

```jsx live
<Card variant={{ background: 'subtle' }}>
  <Typography>The subtle background is more visually muted.</Typography>
</Card>
```

#### Grid background

```jsx live
<Card variant={{ background: 'grid' }}>
  <Typography>The grid background provides another visual variant.</Typography>
</Card>
```

#### Feature background

```jsx live
<Card variant={{ background: 'feature' }}>
  <Typography>The feature background provides another visual variant.</Typography>
</Card>
```

#### Plain background

```jsx live
<Card variant={{ background: 'plain' }}>
  <Typography>The plain background provides another visual variant.</Typography>
</Card>
```

## Custom image background

Card supports a custom responsive image background. The `backgroundImage` prop takes an object with the following properties:

- Use `src` to specify the image URL (can be used resonsively with different source per viewport size).
- Use `alt` to specify the image alt text.
- Use `resizeMode` to resize the image when the frame doesn't match the raw image dimensions.
  It can be set to one of the following values:

  - `cover`: scale the image uniformly (maintain the image's aspect ratio)
    so that both dimensions (width and height) of the image will be equal to or
    larger than the corresponding dimension of the view (minus padding).
  - `contain`: scale the image uniformly (maintain the image's aspect ratio)
    so that both dimensions (width and height) of the image will be equal to or less than
    the corresponding dimension of the view (minus padding).
  - `stretch`: scale width and height independently.
  - `repeat`: repeat the image to cover the frame of the view.
  - `center`: center the image in the view along both dimensions.
  - Use `position` to place the background image on the side of the card with `top`, `bottom`, `left`, `right` or `none`. The positioning is only available when `resizeMode` is set to `contain`.
  - Use `align` to determine where the background image should appear, with `start`, `center`, `end` or `stretch`. The alignment is only available when `resizeMode` is set to `contain`.

  It defaults to `cover` when no value is provided.

```jsx live
<Card
  backgroundImage={{
    alt: 'Gamer girl with headphones ',
    resizeMode: { xl: 'cover', lg: 'repeat', md: 'stretch', sm: 'center', xs: 'contain' },
    src: '/universal-design-system/img/gamer-girl-with-headphones.png'
  }}
>
  <Typography variant={{ colour: 'white' }}>This is the custom image background.</Typography>
</Card>
```

### Position background image

When using `resizeMode: 'contain'`, you can control the exact position and alignment of the image using the `position` and `align` properties:

```jsx live
<Card
  backgroundImage={{
    alt: 'Phone with three cameras',
    resizeMode: 'contain',
    position: 'right',
    align: 'start',
    src: '/universal-design-system/img/iPhone_15_Pro_Max.png'
  }}
>
  <Typography block variant={{ size: 'h2' }}>
    Pocket Wonders: Navigating the Realm of Modern Smartphones
  </Typography>
  <Typography>
    Explore the extraordinary universe tucked within your pocket with the latest smartphones.
  </Typography>
</Card>
```

### Position background image responsively

Both `position` and `align` support responsive values, allowing different positioning across viewport sizes:

```jsx live
<Card
  backgroundImage={{
    alt: 'Phone with three cameras with responsive positioning',
    resizeMode: 'contain',
    position: { xs: 'bottom', sm: 'left', md: 'top', lg: 'right', xl: 'top' },
    align: { xs: 'start', sm: 'center', md: 'end', lg: 'center', xl: 'center' },
    src: '/universal-design-system/img/iPhone_15_Pro_Max.png'
  }}
>
  <Typography block variant={{ size: 'h2', weight: 'bold' }}>
    🔄 Adaptive Responsive Design
  </Typography>
  <Typography variant={{ size: 'large' }}>
    Watch how the smartphone moves around! Dynamic positioning that intelligently adapts to
    different screen sizes and orientations.
  </Typography>
  <Typography variant={{ size: 'small', weight: 'bold' }}>
    Position background image responsively by viewport:
  </Typography>
  <Typography variant={{ size: 'small' }}>
    📱 XS: position: bottom; align: start
    <br />
    📱 SM: position: left; align: center
    <br />
    💻 MD: position: top; align: end
    <br />
    🖥️ LG: position: right; align: center
    <br />
    🖥️ XL: position: top; align: center
  </Typography>
  <Button variant={{ priority: 'secondary' }}>Resize to see changes</Button>
</Card>
```

## Padding variants

### Default padding

Card renders a predetermined, responsive padding by default.

```jsx live
<Card>
  <Typography block variant={{ size: 'h2' }}>
    Connecting with the community
  </Typography>
  <Box top={4}>
    <Typography>
      Card width expands based on the container. Card height expands based on content.
    </Typography>
  </Box>
</Card>
```

### Narrow padding

```jsx live
<Card variant={{ padding: 'narrow' }}>
  <Typography block variant={{ size: 'h2' }}>
    Connecting with the community
  </Typography>
  <Box top={4}>
    <Typography>
      Card width expands based on the container. Card height expands based on content.
    </Typography>
  </Box>
</Card>
```

### Intermediate padding

```jsx live
<Card variant={{ padding: 'intermediate' }}>
  <Typography block variant={{ size: 'h2' }}>
    Connecting with the community
  </Typography>
  <Box top={4}>
    <Typography>
      Card width expands based on the container. Card height expands based on content.
    </Typography>
  </Box>
</Card>
```

### Compact padding

```jsx live
<Card variant={{ padding: 'compact' }}>
  <Typography block variant={{ size: 'h2' }}>
    Connecting with the community
  </Typography>
  <Box top={4}>
    <Typography>
      Card width expands based on the container. Card height expands based on content.
    </Typography>
  </Box>
</Card>
```

### Custom padding

:::caution

Be careful! Custom padding tokens aren't responsive.

:::

Customize the card padding by defining the padding tokens:

- `paddingBottom`
- `paddingLeft`
- `paddingRight`
- `paddingTop`

```jsx live
<Card
  variant={{ padding: 'custom' }}
  tokens={{
    paddingBottom: 72,
    paddingLeft: 64,
    paddingRight: 64,
    paddingTop: 48
  }}
>
  <Typography block variant={{ size: 'h2' }}>
    Connecting with the community
  </Typography>
  <Box top={4}>
    <Typography>
      Card width expands based on the container. Card height expands based on content.
    </Typography>
  </Box>
</Card>
```

## Web-only variants

### Card with footer

Card footer renders the same predetermined, responsive padding by default.

```jsx live
<Card
  footer={
    <Typography>
      At TELUS, we’re building a better future for all Canadians by using our technology for good
      and giving back to our communities.
    </Typography>
  }
>
  <Typography block variant={{ size: 'h2' }}>
    Connecting with the community
  </Typography>
  <Box top={4}>
    <Typography>
      Card width expands based on the container. Card height expands based on content.
    </Typography>
  </Box>
</Card>
```

### Custom footer padding

Customize the card footer padding by defining the padding tokens via a dedicated `footerPadding` prop:

- `paddingBottom`
- `paddingLeft`
- `paddingRight`
- `paddingTop`

```jsx live
<Card
  footer={
    <Typography>
      At TELUS, we’re building a better future for all Canadians by using our technology for good
      and giving back to our communities.
    </Typography>
  }
  footerPadding={{
    paddingBottom: 96,
    paddingLeft: 64,
    paddingRight: 64,
    paddingTop: 24
  }}
>
  <Typography block variant={{ size: 'h2' }}>
    Connecting with the community
  </Typography>
  <Box top={4}>
    <Typography>
      Card width expands based on the container. Card height expands based on content.
    </Typography>
  </Box>
</Card>
```

### Card with full bleed image

Card supports responsive positioning:

- Use `fullBleedContent` to show a full bleed image
- Use `alt` tag to describe the appearance or function of the image
- Use `position` to place the image along the side of the card
  - Use `top` or `bottom` (image expands 100% of the container)
  - Use `left` or `right` (image expands proportionately based on size)
  - Use `imgCol` to set how wide the image expands (based on the responsive 12 column layout)
- Use `align` to determine where the image should appear along the left and right side of the card when the image won’t fill the available space with `start`, `center`, or `end`; does not affect image when `position` is `top` or `bottom`
- Use `src` (or multiple sources for `ResponsiveImage`, or a custom `fullBleedContent`)

```jsx live
<Card
  fullBleedContent={{
    alt: 'Three little piglets hanging out with the one on the far right holding a flower in their mouth.',
    position: { xl: 'left', lg: 'right', md: 'bottom', sm: 'top', xs: 'none' },
    align: { xl: 'end', lg: 'center' },
    src: '/universal-design-system/img/pigs-allium-lo.png'
  }}
>
  <Typography block variant={{ size: 'h2' }}>
    Connecting with the community
  </Typography>
  <Box top={4}>
    <Typography>
      Card width expands based on the container. Card height expands based on content.
    </Typography>
  </Box>
</Card>
```

### Card with adjustable full bleed image

```jsx live
<Card
  fullBleedContent={{
    alt: 'Three little piglets hanging out with the one on the far right holding a flower in their mouth.',
    position: { xl: 'left', lg: 'right', md: 'left', sm: 'right', xs: 'none' },
    imgCol: { xl: 6, lg: 4, md: 2, sm: 2, xs: 4 },
    align: 'center',
    src: '/universal-design-system/img/pigs-allium-lo.png'
  }}
>
  <Typography block variant={{ size: 'h2' }}>
    Connecting with the community
  </Typography>
  <Box top={4}>
    <Typography>
      Card width expands based on the container. Card height expands based on content.
    </Typography>
  </Box>
</Card>
```

### Card footer with image

A footer can also use a full bleed image.

```jsx live
<Card
  fullBleedContent={{
    alt: 'Full Bleed Image Example',
    position: 'bottom',
    src: '/universal-design-system/img/pigs-allium-lo.png'
  }}
  footer={
    <Typography>
      At TELUS, we’re building a better future for all Canadians by using our technology for good
      and giving back to our communities.
    </Typography>
  }
>
  <Typography block variant={{ size: 'h2' }}>
    Connecting with the community
  </Typography>
  <Box top={4}>
    <Typography>
      Card width expands based on the container. Card height expands based on content.
    </Typography>
  </Box>
</Card>
```

### Custom full bleed content

You can also render any content full bleed-style by passing some JSX to the `content` field of the `fullBleedContent` prop:

```jsx live
<Card
  fullBleedContent={{
    alt: 'friendly pigs',
    position: 'bottom',
    content: (
      <OptimizeImage
        contentfulAssetUrl="/universal-design-system/img/pigs-allium-lo.png"
        alt="alpacas"
      />
    )
  }}
>
  <Typography block variant={{ size: 'h2' }}>
    Connecting with the community
  </Typography>
  <Box top={4}>
    <Typography>
      Card width expands based on the container. Card height expands based on content.
    </Typography>
  </Box>
</Card>
```

### Custom full bleed align content

You can use the `contentAlign` prop to align the content within the full bleed image. This is useful when you want to control how the content aligns with respect to the image.

```jsx live
<Card
  fullBleedContent={{
    alt: 'Three little piglets hanging out with the one on the far right holding a flower in their mouth.',
    position: { xl: 'left', lg: 'right', md: 'bottom', sm: 'top', xs: 'none' },
    align: { xl: 'end', lg: 'center' },
    contentAlign: { xl: 'start', lg: 'center' },
    src: '/universal-design-system/img/pigs-allium-lo.png'
  }}
>
  <Box top={4}>
    <Typography>
      Card width expands based on the container. Card height expands based on content.
    </Typography>
  </Box>
</Card>
```

## Border radius variants

### Default border radius

```jsx live
<Card>
  <Typography>An alternative border radius variant with default border radius.</Typography>
</Card>
```

### No border radius

```jsx live
<Card variant={{ borderRadius: 'none' }}>
  <Typography>An alternative border radius variant with no border radius.</Typography>
</Card>
```

### Small border radius

```jsx live
<Card variant={{ borderRadius: 'small' }}>
  <Typography>An alternative border radius variant with default border radius.</Typography>
</Card>
```

### Large border radius

Limit use to marketing content where there is lots of space.

```jsx live
<Card variant={{ borderRadius: 'large' }}>
  <Typography>An alternative border radius variant with large border radius.</Typography>
</Card>
```

## Additional examples

### Group of cards

- Display multiple `Card` components using `StackView`
- Use `StackView`'s responsive behaviour to switch from horizontal to vertical based on viewport

```jsx live
<StackView direction={{ xs: 'column', md: 'row' }} space={{ xs: 2, lg: 3 }}>
  <Card>Short content</Card>
  <Card>A card with somewhat longer content</Card>
  <Card>A card with a much longer content that wraps over more lines, expanding the card</Card>
</StackView>
```

### Custom Content Flex tokens

Customize the card flexible's content by defining the content tokens, useful when trying to align the content of the card:

- `contentFlexGrow`
- `contentFlexShrink`
- `contentAlignItems`
- `contentJustifyContent`

```jsx live
<StackView direction={{ xs: 'column', md: 'row' }} space={{ xs: 2, lg: 3 }}>
  <Card
    tokens={{
      contentFlexGrow: 1,
      contentJustifyContent: 'space-between'
    }}
  >
    <Box bottom={4}>
      <Typography block variant={{ size: 'h4' }}>
        Card With Flex Content
      </Typography>
      <Typography>Example content only.</Typography>
    </Box>

    <Button>Sign up</Button>
  </Card>
  <Card>
    <Box bottom={4}>
      <Typography block variant={{ size: 'h4' }}>
        Card without Flex Content
      </Typography>
      <Typography>Example content only.</Typography>
    </Box>

    <Button>Sign up</Button>
  </Card>
  <Card>
    <Box bottom={4}>
      <Typography block variant={{ size: 'h4' }}>
        Largest Card
      </Typography>
      <Typography>
        A card with a much longer content that wraps over more lines, expanding the card.
      </Typography>
    </Box>

    <Button>Sign up</Button>
  </Card>
</StackView>
```

### Interactive card

`Card` can take `interactiveCard` prop to define interactive section. Think of it as an interactive section that lives in the `Card`, underneath rest of the body, and can respond to `focus`, `hover` and `pressed` states.
An optional `onPress` prop can also be passed in this case to assign a callback when `Card` is pressed.

#### `interactiveCard` prop

The signature of `interactiveCard` is as follows:

```js
  interactiveCard: {
    //interactable elements that defines the interactive card area (required for interactive section)
    body: <div></div>
    // `Card` tokens, but specific to interactive section (optional)
    tokens: {},
    // If the card has `isControl` variant set to `true`, the selectionType can have one of the following options:
    //    - `radiogroup`
    //    - `checkbox`
    selectionType: {},
    // `Card` variant, but specific to interactive section (optional)
    variant: {},
    // `Card` href, but specific to interactive section (optional)
    href: "",
    // Optional `Card` href attributes
    hrefAttrs: {}
  }
```

#### Example

```jsx live
<div style={{ maxWidth: '20rem', margin: '0 auto' }}>
  <Card
    interactiveCard={{
      body: (
        <>
          <Typography block variant={{ size: 'h2' }}>
            Connecting with the community
          </Typography>
          <Box top={4}>
            <Typography>
              Card width expands based on the container. Card height expands based on content.
            </Typography>
          </Box>
        </>
      )
    }}
    onPress={() => {
      console.log('Card pressed')
    }}
  >
    <Button
      onPress={() => {
        console.log('Button pressed')
      }}
      variant={{ priority: 'high', width: 'full' }}
    >
      Sign up
    </Button>
  </Card>
</div>
```

### Radio Selection Cards

Cards can be used as radio buttons by setting the `interactiveCard.selectionType` to `radiogroup` and `interactiveCard.variant.isControl` to `true`. This creates cards that behave like radio buttons, where only one card can be selected at a time.

### Example: Using interactiveCard.body with selectionType

The example below demonstrates how to use `interactiveCard.body` with `selectionType`. All content, including the main content (plan details) and any additional actions (View Details button), should be included within the `interactiveCard.body`.

```jsx live
function InteractiveCardWithRadioGroup() {
  const [selectedCardId, setSelectedCardId] = React.useState(null)

  const cards = [
    {
      id: 'card1',
      title: 'Card #1',
      elements: ['Element 1', 'Element 2', 'Element 3', 'Element 4', 'Element 5']
    },
    {
      id: 'card2',
      title: 'Card #2',
      elements: ['Element 1', 'Element 2', 'Element 3', 'Element 4', 'Element 5']
    },
    {
      id: 'card3',
      title: 'Card #3',
      elements: ['Element 1', 'Element 2', 'Element 3', 'Element 4', 'Element 5']
    }
  ]

  return (
    <Box>
      <Typography block variant={{ size: 'h2' }}>
        Interactive Card with Radio Group
      </Typography>
      <Box top={4} bottom={4}>
        <Typography>Select one of the options below:</Typography>
      </Box>

      <StackView direction={{ xs: 'column', md: 'row' }} space={{ xs: 2, lg: 3 }}>
        {cards.map((card) => {
          // Create a Card component with interactiveCard props only, no children
          const cardContent = (
            <Box>
              <Typography block>{card.title}</Typography>
              <Box top={2}>
                {card.elements.map((element, index) => (
                  <Typography key={`${card.id}-element-${index}-${element}`}>{element}</Typography>
                ))}
              </Box>
            </Box>
          )

          // Example showing how to use both interactiveCard.body and children together
          return (
            <Card
              key={card.id}
              id={card.id}
              onPress={() => setSelectedCardId(card.id)}
              tokens={{
                inputBackgroundColor: '#FFFFFF',
                iconBackgroundColor: '#2B8000',
                iconColor: '#FFFFFF',
                inputBorderRadius: 12,
                inputHeight: 24,
                inputWidth: 24,
                iconSize: 12,
                inputBorderWidth: 2,
                inputBorderColor: '#71757B',
                paddingTop: 16,
                paddingRight: 16,
                paddingBottom: 16,
                paddingLeft: 16
              }}
              interactiveCard={{
                selectionType: 'radiogroup',
                variant: {
                  selected: selectedCardId === card.id,
                  isControl: true
                },
                body: cardContent
              }}
            >
              {/* Additional content can be added as children */}
              <Box top={4}>
                <Button
                  variant={{ priority: 'secondary', width: 'full' }}
                  onPress={() => console.log(`View details for ${card.id}`)}
                >
                  View Details
                </Button>
              </Box>
            </Card>
          )
        })}
      </StackView>

      {selectedCardId && (
        <Box top={4}>
          <Button
            variant={{ priority: 'high' }}
            onPress={() => console.log(`Selected card: ${selectedCardId}`)}
          >
            Continue with selected plan
          </Button>
        </Box>
      )}
    </Box>
  )
}
```

## Radio Card Implementation Guide

### Required Properties for Radio Selection Cards

For radio selection cards to work properly, you must include these properties:

- Set `interactiveCard.selectionType` to `'radiogroup'`
- Set `interactiveCard.variant.isControl` to `true` (this is crucial for the radio button to appear)
- Provide an `interactiveCard.body` with the content
- Handle the selection state with `interactiveCard.variant.selected`
- Provide an `onPress` handler to update the selection state

### Radio Button Tokens

The following tokens control the appearance of the radio button:

```js
tokens={{
  inputBackgroundColor: '#FFFFFF',    // Background of the radio button
  iconBackgroundColor: '#2B8000',     // Background when selected
  iconColor: '#FFFFFF',               // Color of the check mark
  inputBorderRadius: 12,              // Border radius of the radio button
  inputHeight: 24,                    // Height of the radio button
  inputWidth: 24,                     // Width of the radio button
  iconSize: 12,                       // Size of the check mark
  inputBorderWidth: 2,                // Border width of the radio button
  inputBorderColor: '#71757B'         // Border color of the radio button
}}
```

## Feedback

<Feedback component="Card" />
