Card
On this page
Overview
A card formats content in a small, contained space. It can be used to display a preview of information or provide secondary content in relation to the content it's near. Several cards can be used together to group related information.
<rh-card>
element. Consult the <rh-card>
element documentation
for more information on how to use the card element.
Customizing cards
Cards act as both themeable containers and also respond to the color theme from their themeable containers.
To customize a card the design tokens must be altered. These design tokens are different depending on the context for the card (light or dark theme).
Examples include:
For more information, please see the docs on theming and
<rh-card>
css custom properties.
Color Palettes
Cards will automatically react to the color-palette
context provided by a
parent element, like <rh-surface>
.
Card title
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla vitae elit libero, a pharetra augue. Nullam id dolor id nibh ultricies vehicula ut id elit. Donec id elit non mi porta gravida at eget metus.
<rh-card>
<h2 slot="header">Card title</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla vitae elit
libero, a pharetra augue. Nullam id dolor id nibh ultricies vehicula ut id
elit. Donec id elit non mi porta gravida at eget metus.</p>
<rh-cta slot="footer" href="#">Call to action</rh-cta>
</rh-card>
Copy to Clipboard
Copied!
Toggle line wrap
Copy to Clipboard
Copied!
Toggle line wrap
import '@rhds/elements/rh-card/rh-card.js';
import '@rhds/elements/rh-cta/rh-cta.js';
Copy to Clipboard
Copied!
Toggle line wrap
Card title
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla vitae elit libero, a pharetra augue. Nullam id dolor id nibh ultricies vehicula ut id elit. Donec id elit non mi porta gravida at eget metus.
<rh-card>
<h2 slot="header">Card title</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla vitae elit
libero, a pharetra augue. Nullam id dolor id nibh ultricies vehicula ut id
elit. Donec id elit non mi porta gravida at eget metus.</p>
<rh-cta slot="footer" href="#">Call to action</rh-cta>
</rh-card>
Copy to Clipboard
Copied!
Toggle line wrap
Copy to Clipboard
Copied!
Toggle line wrap
import '@rhds/elements/rh-card/rh-card.js';
import '@rhds/elements/rh-cta/rh-cta.js';
Copy to Clipboard
Copied!
Toggle line wrap
Explicit card theming
Cards can play an active role in theming by declaring a specific color-palette
.
Card title
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla vitae elit libero, a pharetra augue. Nullam id dolor id nibh ultricies vehicula ut id elit. Donec id elit non mi porta gravida at eget metus.
<rh-card color-palette="lighter">
<h2 slot="header">Card title</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla vitae elit
libero, a pharetra augue. Nullam id dolor id nibh ultricies vehicula ut id
elit. Donec id elit non mi porta gravida at eget metus.</p>
<rh-cta slot="footer" href="#">Call to action</rh-cta>
</rh-card>
Copy to Clipboard
Copied!
Toggle line wrap
Copy to Clipboard
Copied!
Toggle line wrap
Copy to Clipboard
Copied!
Toggle line wrap
Custom theming
When using design tokens to apply custom themes, it is important to ensure that the colors used meet color contrast guidelines.
Card title
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla vitae elit libero, a pharetra augue. Nullam id dolor id nibh ultricies vehicula ut id elit. Donec id elit non mi porta gravida at eget metus.
<rh-card class="custom-theme-card">
<h2 slot="header">Card title</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla vitae elit
libero, a pharetra augue. Nullam id dolor id nibh ultricies vehicula ut id
elit. Donec id elit non mi porta gravida at eget metus.</p>
<rh-cta slot="footer" href="#">Call to action</rh-cta>
</rh-card>
Copy to Clipboard
Copied!
Toggle line wrap
.custom-theme-card {
--rh-color-border-subtle-on-dark: #5e40be;
--rh-color-border-subtle-on-light: #f56e6e;
--rh-color-surface-darkest: #3d2785;
--rh-color-surface-lightest: #feeded;
--rh-color-text-primary-on-dark: #ece6ff;
--rh-color-text-primary-on-light: #5f0000;
}
Copy to Clipboard
Copied!
Toggle line wrap
Copy to Clipboard
Copied!
Toggle line wrap
Other libraries
To learn more about our other libraries, visit this page.
Feedback
To give feedback about anything on this page, contact us.
Other libraries
To learn more about our other libraries, visit the getting started page.