Cards are useful to group high profile information together into one bite-sized unit. User info, activities, or other complex data items are great to summarize and provide related actions in a card.
Default card
Create a default card by adding the class .hc-card to any block-level element. The only required content is a main content section with class .hc-card-main, which includes at least a title as an <h5> inside of a wrapping element with class .hc-card-title.
This extra markup is required to handle the positioning for other types of content that may appear here, like a badge and subheader.
Add a subheader inside of the main content section right after the title, using class .hc-card-sub on any element.
You can include an optional footer for additional data and actions by adding a block-level element with class .hc-card-footer as a sibling of the main content section.
This footer can include a left-aligned data section with class .hc-card-data and up to 2 inline elements. The first one will be a normal font size; the second one if included will be smaller and should have the class .hc-card-data--secondary to ensure this.
The footer can also include a right-aligned actions section with class .hc-card-actions. Add 1 or 2 buttons here, with the primary button the furthest to the right.
Stacked cards
Stacked cards indicate a collection or more than one related item. They can show that the card represents a group or collection of cards, or that there are more things to be done after this focused card is addressed.
Create one by adding the modifier class .hc-card--stack to the main element. By default only one additional stacked card is present at the bottom, but you can add the additional class .hc-card--stack--full to add a second one.
Note that because these use pseudo-elements for the stacked effect, a 0.5rem margin is applied to the bottom of these cards to enforce an appropriate gap. Spacing of the cards should always be handled by the gap property so this should not matter.
Semantic cards
Semantic alternatives for info and danger are available to signify some alert or enhanced state.
Info cards are good to show priority or prominence without signifying some issue, whereas danger cards are good to alert the user that a deadline has passed or some other urgency.
User cards
Cards with user information can provide a discrete block for related actions or metadata about the user. Combine an avatar next to the name, or stacked avatar to show a user and a group.
Size handling
Cards have no minimum or maximum width by default, so it’s important to control their sizing with whatever wrapper element you use.
For out-of-the-box handling, create an element with class .hc-card-grid and then a child with class .hc-card-grid-cols. Any cards you place inside will be sized and wrapped automatically.
Here’s an example that has five cards inside of the default card grid. Note that each card is sized equally despite the odd number. If you shrink or expand the screen, the cards should resize automatically and show between 1 and 2 per row.
Click the expand button in the code sample above to see how the cards operate on your entire viewport. In a wider wrapping element you would see more than two (or even three) cards. Each card in a row will also adapt to fit the entire row’s height.
Technical details
We unfortunately need to have 2 wrapper elements because we’re making use of CSS container queries.
By default on small screens, the cards stack vertically and fill the entire width.
When the .hc-card-gridwrapper (not the screen) is larger than mobile, the inner wrapping element changes to use grid-template-columns with a value of repeat(auto-fill, minmax(16rem, 1fr)); This repeats the cards and sizes them to be the larger of 16rem or the remaining available space.
Finally, when the container is 51rem wide, the new minimum card size is 20rem instead of 16rem. We chose 51rem to prevent 3 cards from sitting in a row too early.