Skip to main content

Cards

Cards are a blank surface component that serves short-form/summarized content to the user.

HSCard Component

Usage

HTML

<div class="hs-card">
<header class="hs-card__header">
<div class="hs-card__mast">
<h2 class="hs-card__title">CARD TITLE</h2>
<p class="hs-card__subtitle">Card Subtitle.</p>
</div>
</header>
<main class="hs-card__content">
Card content :)
</main>
</div>

SCSS/CSS

@use 'node_modules/@devprotocol/hashi';
@use 'node_modules/@devprotocol/hashi/hs-card';

@include hashi.init {
@include hs-card.render();
}

Outlined Card

The outlined card style is the default card style.

<div class="hs-card">
<header class="hs-card__header">
<div class="hs-card__mast">
<h2 class="hs-card__title">CARD TITLE</h2>
<p class="hs-card__subtitle">Card Subtitle.</p>
</div>
</header>
<main class="hs-card__content">
Card content :)
</main>
</div>

Filled Card

The filled card style is a style variant of the card component. To enable this style, attach the .is-filled class to the parent element's class list.

The class names inside brackets are only for emphasis, not to be used in the actual implementation.

<div class="hs-card [is-filled]">
<header class="hs-card__header">
<div class="hs-card__mast">
<h2 class="hs-card__title">CARD TITLE</h2>
<p class="hs-card__subtitle">Card Subtitle.</p>
</div>
</header>
<main class="hs-card__content">
Card content :)
</main>
</div>

Card Actions

Card actions is the most bottom section of a card. It contains buttons/hyperlinks that redirect the user to another page, submit an in-card form, or perform any action on click.

<div class="hs-card">
<header class="hs-card__header">
<div class="hs-card__mast">
<h2 class="hs-card__title">CARD TITLE</h2>
<p class="hs-card__subtitle">Card Subtitle.</p>
</div>
</header>
<main class="hs-card__content">
Card content :)
</main>
<footer class="hs-card__footer">
<button class="hs-button is-filled" role="button">
<span class="hs-button__label">Button</span>
</button>
<button class="hs-button" role="button">
<span class="hs-button__label">Button</span>
</button>
</footer>
</div>

Card Icons

Card icons provide a way of associating a certain symbol to a card. This is especially useful for token images. The card icon element can only take either an SVG or an image.

<div class="hs-card">
<header class="hs-card__header">
<div class="hs-card__mast">
<h2 class="hs-card__title">CARD TITLE</h2>
<p class="hs-card__subtitle">Card Subtitle.</p>
</div>
<div class="hs-card__icon">
<!-- Img or SVG -->
</div>
</header>
<main class="hs-card__content">
Card content :)
</main>
</div>

Card Media

Card media allows you to have an image that comes along with your card.

<div class="hs-card">
<section class="hs-card__media">
<img src="..." alt="Card Media"/>
</section>
<header class="hs-card__header">
<div class="hs-card__mast">
<h2 class="hs-card__title">CARD TITLE</h2>
<p class="hs-card__subtitle">Card Subtitle.</p>
</div>
</header>
<main class="hs-card__content">
Card content :)
</main>
</div>

API

CSS Classes

These are used to structure, extend, and modify the styles of a component on the markup.

Anatomical Classes

These classes make up the elements inside a component.

ClassEffect
.hs-cardMain card class.
.hs-card__headerThe header section of the card component.
.hs-card__mastThe identification section of the card.
.hs-card__titleThe title of the card.
.hs-card__subtitleThe subtitle of the card.
.hs-card__iconThe icon of the card.
.hs-card__mediaThe media of the card.
.hs-card__contentThe content section of the card.
.hs-card__actionsHere is where you put all the buttons for the card.

Variant Classes

For information on how to use these classes, click here.

ClassEffect
.is-raisedRenders the card in its raised style.

Custom Properties

These are for creating your own component theme classes that you can append to the parent element markup.

PropertyEffect
--hs-card-fillChanges the card's background color.
--hs-card-inkChanges the card's text color.
--hs-card-borderChanges the card's border color.
--hs-card-radiusChanges the card's border radius.
--hs-card-paddingChanges the card's padding.
--hs-card-section-gapChanges the card's section's gaps.
--hs-card-header-gapChanges the card's header gap.
--hs-card-footer-gapChanges the card's footer gap.
--hs-card-weightChanges the card's border color.
--hs-card-inkChanges the card's content color.
--hs-card-familyChanges the card content's family.
--hs-card-sizeChanges the card content's size.
--hs-card-weightChanges the card content's weight.
--hs-card-line-heightChanges the card content's line-height.
--hs-card-title-familyChanges the card title's family.
--hs-card-title-sizeChanges the card title's size.
--hs-card-title-weightChanges the card title's weight.
--hs-card-title-line-heightChanges the card title's line-height.
--hs-card-subtitle-familyChanges the card subtitle's family.
--hs-card-subtitle-sizeChanges the card subtitle's size.
--hs-card-subtitle-weightChanges the card subtitle's weight.
--hs-card-subtitle-line-heightChanges the card subtitle's line-height.
--hs-card-icon-sizeChanges the card's icon size.
--hs-card-media-heightChanges the card's media height.

Example

.my-card-theme {
--hs-card-fill: #232323;
--hs-card-ink: lime;
--hs-card-border: var(--hs-button-fill);

&:hover {
--hs-card-fill: #353535;
}

&:active {
--hs-card-fill: #535353;
}
}

Configuring styles

Here are all the themeable properties for this component. The directions to use these properties are located in the render API.

$fill: 'surface-200' !default;
$ink: 'surface-ink' !default;
$border: 'primary-400' !default;
$tone: 200 !default;

$radius: 'medium' !default;
$padding: 'md' !default;

$title-typography: 'subtitle' !default;
$subtitle-typography: 'body' !default;
$content-typography: 'body' !default;

$icon-size: 66px !default;
$media-height: 120px !default;

$section-gap: 'md' !default;
$header-gap: 'md' !default;
$footer-gap: 'sm' !default;

Extending styles

If you wish to extend the component styles, the extend() API might come in handy.