Card
The Card component is a flexible and extensible container used to display content.
Import
- React
- Angular
- Vue.js
// with @dhl-official/react-library:
import { DhlCard } from "@dhl-official/react-library"
// with @dhl-official/ui-libraries/react-library:
import { DhlCard } from "@dhl-official/ui-libraries/react-library"
If the DUIL has been installed, you can use the web component directly:
<dhl-card></dhl-card>
// with @dhl-official/vue-library:
import { DhlCard } from "@dhl-official/vue-library"
// with @dhl-official/ui-libraries/vue-library:
import { DhlCard } from "@dhl-official/ui-libraries/vue-library"
Code
- React
- Angular
- Vue.js
<DhlCard>
<img
slot="image"
src={img320x200}
width="100%"
style={{ display: "block" }}
alt="A 320x200 sample yellow image"
/>
<DhlHeadline slot="header" designLevel="4" noMargin>
Header
</DhlHeadline>
<DhlText>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean
commodo ligula eget dolor. Aenean massa. Cum sociis natoque
penatibus et magnis dis parturient montes, nascetur.
</DhlText>
<div slot="footer">
<DhlButton>Button</DhlButton>
</div>
</DhlCard>
<dhl-card>
<img
slot="image"
src="assets/img320x200.png"
width="100%"
style="display: block"
alt="A 320x200 sample yellow image"
/>
<dhl-headline slot="header" design-level="4" no-margin>
Header
</dhl-headline>
<dhl-text>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean
commodo ligula eget dolor. Aenean massa. Cum sociis natoque
penatibus et magnis dis parturient montes, nascetur.
</dhl-text>
<div slot="footer">
<dhl-button>Button</dhl-button>
</div>
</dhl-card>
<dhl-card>
<img
slot="image"
src="assets/img320x200.png"
width="100%"
style="display: block"
alt="A 320x200 sample yellow image"
/>
<dhl-headline slot="header" designLevel="4" :noMargin="true">
Header
</dhl-headline>
<dhl-text>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean
commodo ligula eget dolor. Aenean massa. Cum sociis natoque
penatibus et magnis dis parturient montes, nascetur.
</dhl-text>
<div slot="footer">
<dhl-button>Button</dhl-button>
</div>
</dhl-card>
Interactive Demo
Variants
Basic Card
A Card component without a header or footer slot supplied.
- React
- Angular
- Vue.js
<DhlCard>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo
ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis
parturient montes, nascetur.
</DhlCard>
<dhl-card>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo
ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis
parturient montes, nascetur.
</dhl-card>
<dhl-card>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo
ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis
parturient montes, nascetur.
</dhl-card>
lorem ipsum dolor sit amet, consectetuer adipiscing elit. aenean commodo ligula eget dolor. aenean massa. cum sociis natoque penatibus et magnis dis parturient montes, nascetur.
Card with a header and footer
To apply correct stylings, ensure that the header and footer slots are supplied.
- React
- Angular
- Vue.js
<DhlCard>
<DhlHeadline slot="header" designLevel="4" noMargin>
Header
</DhlHeadline>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo
ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis
parturient montes, nascetur.
<div slot="footer">
<DhlButton>Button</DhlButton>
</div>
</DhlCard>
<dhl-card>
<dhl-headline slot="header" design-level="4" no-margin>
Header
</dhl-headline>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo
ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis
parturient montes, nascetur.
<div slot="footer">
<dhl-button>Button</dhl-button>
</div>
</dhl-card>
<dhl-card>
<dhl-headline slot="header" designLevel="4" :noMargin="true">
Header
</dhl-headline>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo
ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis
parturient montes, nascetur.
<div slot="footer">
<dhl-button>Button</dhl-button>
</div>
</dhl-card>
header
lorem ipsum dolor sit amet, consectetuer adipiscing elit. aenean commodo ligula eget dolor. aenean massa. cum sociis natoque penatibus et magnis dis parturient montes, nascetur.
Card with an image in body
- React
- Angular
- Vue.js
<DhlCard>
<DhlHeadline slot="header" designLevel="4" noMargin>
Header
</DhlHeadline>
<img
src={img320x200}
width="100%"
style={{ display: "block" }}
alt="A 320x200 sample yellow image"
/>
<DhlText>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean
commodo ligula eget dolor. Aenean massa. Cum sociis natoque
penatibus et magnis dis parturient montes, nascetur.
</DhlText>
<div slot="footer">
<DhlButton>Button</DhlButton>
</div>
</DhlCard>
<dhl-card>
<dhl-headline slot="header" design-level="4" no-margin>
Header
</dhl-headline>
<img
src="assets/img320x200.png"
width="100%"
style="display: block"
alt="A 320x200 sample yellow image"
/>
<dhl-text>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean
commodo ligula eget dolor. Aenean massa. Cum sociis natoque
penatibus et magnis dis parturient montes, nascetur.
</dhl-text>
<div slot="footer">
<dhl-button>Button</dhl-button>
</div>
</dhl-card>
<dhl-card>
<dhl-headline slot="header" designLevel="4" :noMargin="true">
Header
</dhl-headline>
<img
src="assets/img320x200.png"
width="100%"
style="display: block"
alt="A 320x200 sample yellow image"
/>
<dhl-text>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean
commodo ligula eget dolor. Aenean massa. Cum sociis natoque
penatibus et magnis dis parturient montes, nascetur.
</dhl-text>
<div slot="footer">
<dhl-button>Button</dhl-button>
</div>
</dhl-card>
header
lorem ipsum dolor sit amet, consectetuer adipiscing elit. aenean commodo ligula eget dolor. aenean massa. cum sociis natoque penatibus et magnis dis parturient montes, nascetur.
Card with an image overlay
- React
- Angular
- Vue.js
<DhlCard imgOverlay={true}>
<img
slot="image"
src={img320x200}
width="100%"
style={{ display: "block" }}
alt="A 320x200 sample yellow image"
/>
<DhlHeadline slot="header" designLevel="4" noMargin>
Header
</DhlHeadline>
<DhlText>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean
commodo ligula eget dolor. Aenean massa. Cum sociis natoque
penatibus et magnis dis parturient montes, nascetur.
</DhlText>
<div slot="footer">
<DhlButton>Button</DhlButton>
</div>
</DhlCard>
<dhl-card img-overlay="true">
<img
slot="image"
src="assets/img320x200.png"
width="100%"
style="display: block"
alt="A 320x200 sample yellow image"
/>
<dhl-headline slot="header" desgin-level="4" no-margin>
Header
</dhl-headline>
<dhl-text>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean
commodo ligula eget dolor. Aenean massa. Cum sociis natoque
penatibus et magnis dis parturient montes, nascetur.
</dhl-text>
<div slot="footer">
<dhl-button>Button</dhl-button>
</div>
</dhl-card>
<dhl-card imgOverlay="true">
<img
slot="image"
src="assets/img320x200.png"
width="100%"
style="display: block"
alt="A 320x200 sample yellow image"
/>
<dhl-headline slot="header" designLevel="4" :noMargin="true">
Header
</dhl-headline>
<dhl-text>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean
commodo ligula eget dolor. Aenean massa. Cum sociis natoque
penatibus et magnis dis parturient montes, nascetur.
</dhl-text>
<div slot="footer">
<dhl-butotn>Button</dhl-butotn>
</div>
</dhl-card>
header
lorem ipsum dolor sit amet, consectetuer adipiscing elit. aenean commodo ligula eget dolor. aenean massa. cum sociis natoque penatibus et magnis dis parturient montes, nascetur.
Accessibility
If you use aria-label on Card, please also provide a useful role via dataRole.
Migrating from DUIL 1.0
- Compound components e.g. Card.Header are now defined through slots (see docs)
- Add
dataTestid
Readme
Properties
| Property | Attribute | Description | Type | Default |
|---|---|---|---|---|
dataAriaDescribedby | data-aria-describedby | An optional prop defining the list of reference IDs (separated by spaces), recommended when you want to an error message on your field. | string | undefined |
dataAriaLabel | data-aria-label | An optional prop defining the text read by the screen reader to represent the component; use this if you need different text to be read from label. | string | undefined |
dataClassName | data-class-name | An optional class name prop for the component. | string | undefined |
dataId | data-id | An optional prop. Gives a valid HTML ID attribute value for the component. | string | `dhl-card-${getRandomString()}` |
dataRole | data-role | An optional prop defining the role attribute of the component. | string | undefined |
dataTestid | data-testid | An optional prop. The test id attached to the component as a data-testid attribute. | string | undefined |
highlightState | highlight-state | An optional prop to highlight card state. | Variants.error | Variants.success | undefined |
imgOverlay | img-overlay | An optional prop to be set when an image within the card should overlay the card. | boolean | false |
menuButtonColorVariant | menu-button-color-variant | An optional prop to set color variant for menu button. | Variants.dark | Variants.light | DHL_CARD.MENU_BUTTON_COLOR_VARIANT.DARK |
showMenuButton | show-menu-button | An optional prop to display menu button. Content for the menu should be passed under the <slot="menu" />. | boolean | false |
size | size | An optional size prop for the component. | "md" | "sm" | DHL_CARD.SIZE.MD |
tabindex | tabindex | An optional prop to control the focusability of the card. Set to 0 to make the card keyboard-focusable, -1 to make it programmatically focusable, or leave undefined (default) to make it non-focusable. Only set this when the card itself is interactive (e.g., clickable). | number | undefined |
tag | tag | An optional tag prop for the Card component - use this prop when grouping cards for accessibility & semantic html. | "div" | "li" | DHL_CARD.TAG.DIV |
Slots
| Slot | Description |
|---|---|
"footer" | used for elements intended to be positioned as the DhlCard footer |
"header" | used for elements intended to be positioned as the DhlCard header |
"image" | used to supply <img> elements for display within the DhlCard |
"menu" | used for elements intended to be positioned as the DhlCard menu |
"unnamed" | unnamed children slot for DhlCard content |
Dependencies
Used by
Depends on
Graph
Built by DHL User Interface Library Team!