current theme: placeholder

component :: Card

The .card component, in its simplest form, is a container with 3 style options:

  • Default: transparent background, border outline.
  • Filled: solid background color.
  • Raised: drop shadow and hover effect.

Additional features include: header with title and subtitle, image with predefined aspect ratios, footer, custom badges, clickable body, disabled state, and loading state with skeleton UI. The Astro component makes it easy to use all those features.

A simple filled card

Natural Law, is a set of universal, non-man-made, binding and unchangeable conditions which govern the consequence of our actions.

A simple raised card

Natural Law, is a set of universal, non-man-made, binding and unchangeable conditions which govern the consequence of our actions.

File NameclassSource
component.card.css.cardGithub

HTML

Available modifiers

Available modifiersDescription
.cardDefault style. Transparent background with border.
.card + .card-filledFilled with a background color.
.card + .card-raisedDrop shadow, animated on hover.
.card + .is-disabledLowered opacity. Interactivity disabled.

Custom properties

The following custom properties are available in the default theme:

PropertyColor
--card-spacingGeneral padding inside the card.
--card-colorText color.
--card-secondary-text-colorSubtitle color.
--card-bg-colorBackground color of the “filled” variant.
--card-border-radiusBorder radius.
--card-border-colorBorder color.
--card-border-widthBorder width.
--card-shadowDefault drop shadow or the “raised” variant.
--card-shadow-hoverHover state drop shadow.
--card-badge-bgDefault badge background.
--card-badge-text-colorBadge text color.
--card-loading-bgLoading skeleton background color.

Astro component

PropTypeDefaultDescription
variantstringundefinedCard’s visual style: filled, raised.
isDisabledbooleanfalseDisabled style. Disabled interactions.
isLoadingbooleanfalseLoading state with skeleton UI.
hrefstringundefinedMakes card clickable.
titlestringundefinedHeader title text.
subtitlestringundefinedHeader subtitle text.
imageSrcstringundefinedAdd an image to card.
imageAltstring''Alt text for the image.
aspectRatiostringgoldenImage aspect ratio (available aspect ratios).
badgesarray[]Array of objects (see example below).
data-testidstring'card'Test ID for testing frameworks.
extraClassstringundefinedAdditional CSS, useful for helper classes.

Slots

The Card component supports the following slots for content projection:

  • Default slot: Main content area (e.g., text or paragraphs).
  • Actions slot: Action buttons or links in the footer.

It is recommended to use the button atom in the actions slot, e.g.:

<Fragment slot="actions">
  <a class="bt bt-text" href="/home">Cancel</a>
  <button class="bt bt-primary">Add to Cart</button>
</Fragment>

Badge Styling

The badges prop takes an array of objects. Each object consists of a label property which defines the badge’s text, and an optional color property that defines the badge’s background color. If no color is provided, it defaults to --card-badge-bg defined in the default theme.

A card with too many badges

Way Too Many Badges

This is where the content goes. Unless you only want a bunch of badges!

<Card
  title="A card with too many badges"
  badges={[
    { label: "Way", color: "#a6b65a" },
    { label: "Too", color: "#86615c" },
    { label: "Many", color: "#81a598" },
    { label: "Badges", color: "#e3863d" },
  ]}
>
  <p>This is where the content goes. Unless you only want a bunch of badges!</p>
</Card>

Examples