Usage
When to use
Use a card container to help build more consistently styled cards.
Types
Static cards
Static cards may contain interactive elements but must not be actionable or interactive on their own. They should not have any shadows applied to them, so that they can be differentiated from an interactive card.
Interactive cards
Interactive cards are actionable, e.g., they can be hovered over, clicked, or focused on.
If you're using an interactive element (like an <a>
or <button>
) as the main content wrapper inside Card::Container
, avoid placing other interactive elements inside it. This kind of nesting creates accessibility issues—particularly for screen reader users—because nested interactive elements can't be reliably accessed or operated.
When the card is interactive, only static elements should be contained within it.
Levels
Base
Use for static cards.
Mid
Use for the rested (default) and active (pressed) states of interactive cards.
High
Use for the raised (hover) state of interactive cards.
Border
Card containers come with or without borders.
Background
There are two backgrounds available: neutral-primary
and neutral-secondary
.
Recommended spacing
We recommend the following spacing options for cards:
- 16px all around
- 24px all around
- 16px top/bottom; 24px left/right
- 24px top/bottom; 16px left/right
How to use this component
<Hds::Card::Container @level="mid" @hasBorder={{true}}>
[Your content here]
</Hds::Card::Container>
To style the Cards, you can add an external element that wraps the Card, with a custom class that controls the width of the wrapper itself and an internal element that wraps the content and applies padding around it (resulting in visual internal padding for the Card) and aligns the text to the center.
Alternatively, you could use the Card Containers in a CSS flex
or grid
container.
HTML tag
To specify which HTML tag to use to render the component, use the @tag
argument. The default tag is a div
but you can optionally render the Card as an li
to be used within a list.
Note: If you choose to use the Card
as a list item, you must wrap it either in a ul
or ol
tag for the markup to be valid. Also note that you are responsible for the related styling for the list and list items.
- Card item 1
- Card item 2
- Card item 3
<ul class="doc-card-list-demo">
<Hds::Card::Container @tag="li" @hasBorder={{true}} class="doc-card-list-demo__item">
Card item 1
</Hds::Card::Container>
<Hds::Card::Container @tag="li" @hasBorder={{true}} class="doc-card-list-demo__item">
Card item 2
</Hds::Card::Container>
<Hds::Card::Container @tag="li" @hasBorder={{true}} class="doc-card-list-demo__item">
Card item 3
</Hds::Card::Container>
</ul>
Interactive states
The @level
, @levelHover
, and @levelActive
arguments can be used to declare the specific elevation of the Card for each interactive state. Following the guidelines, this example transitions between mid → high → mid elevation for the corresponding interactive states; default → hover → active.
<div class="doc-card-interactive-demo">
<Hds::Card::Container @level="mid" @levelHover="high" @levelActive="mid" @hasBorder={{true}}>
<a href="#">
[Your static content here]
</a>
</Hds::Card::Container>
</div>
Using SCSS, the .doc-card-interactive-demo
class would look something like this:
.doc-card-interactive-demo {
.hds-card__container {
a {
display: block;
padding: 16px;
border-radius: inherit;
&:focus {
outline: none;
box-shadow: var(--token-focus-ring-action-box-shadow);
}
}
}
}
This example implements a basic interactive card which uses a link to wrap the entirety of the static content area. For further assistance on implementing interactive cards, contact the Design System Team.
Component API
Card::Container
level
enum
- base (default)
- mid
- high
levelHover
enum
- base
- mid
- high
:hover
state.
levelActive
enum
- base
- mid
- high
:active
state.
background
enum
- neutral-primary (default)
- neutral-secondary
hasBorder
boolean
- false (default)
overflow
enum
- visible (default)
- hidden
tag
enum
- div (default)
- li
Card
content.
…attributes
...attributes
.
Conformance rating
By default, the Card container component has @overflow="hidden"
applied to it. This means you may need to handle cases where text is truncated, to make it accessible for keyboard-only users.
If the Card tag
argument is set to li
, it must be contained within either a ul
or ol
parent element in order for the HTML markup to be valid.
Additionally, if the component is altered to be an interactive element, and also contains interactive elements like links or buttons, it can cause a conformance failure for having nested interactive elements.
To implement accessible interactive cards, a helpful resource is the "Inclusive Components" blog on Cards.
Support
If any accessibility issues have been found within this component, let us know by submitting an issue.
4.18.1
Add tag
argument to choose between using a div
tag (the default) or an li
tag
4.10.0
Fixed the HdsCard
type reexport to reflect correct component name HdsCardContainer
. If you are importing HdsCard
types, update it to HdsCardContainer
.