Skip to content

Build UI / Components / Card

Card ​

A card groups related content into one flex container, styled by --card-* tokens. It's a layout primitive, not a control — it has no action of its own. Any click, navigation, or keyboard interaction belongs entirely to the slotted content, like a real <kb-button> or <a>, never to the card.

preview
Code
html
<kb-card>
  <kb-text size="xs" weight="bold">Akita</kb-text>
  <kb-text size="xxxs" color="master">Docile, courageous, dignified</kb-text>
  <kb-button width="fill">Details</kb-button>
</kb-card>

Usage ​

html
<kb-card direction="row">
  <kb-text>Content</kb-text>
</kb-card>

When to use ​

  • Grouping related content — a heading, some text, an action — into one visually contained surface.
  • Laying out a row or column of content with consistent spacing and padding, driven by design tokens instead of ad hoc CSS.

When not to use ​

  • Expecting a clicked event from the card itself. The card despatches nothing — put a real <kb-button> or <a> in the slot and listen to that instead.
  • Expecting the card to be focusable or announced by a screen reader. The card is declared presentational (role="none"), adds no tabindex, and carries no accessible name — it's removed from the accessibility tree. Only the slotted content is reachable by keyboard or assistive technology.

Composition ​

  • Can contain: anything — the shadow root is a single <slot>, and the card's flex container lays it out. Nothing is intercepted: an interactive child keeps its own click, focus, and keyboard behavior untouched. One or more <kb-on> also work as children, for extra arcs beyond the single on attribute — they wire to the card directly and render nothing.
  • Can be a child of: anything. Commonly inside a <kb-render> list or a layout region.
preview
Code
html
<kb-card direction="row">
  <kb-cover src="https://picsum.photos/id/237/120/120" landscape></kb-cover>
  <kb-stack direction="column" spacing="quarck">
    <kb-text size="xxs" weight="bold">Labrador</kb-text>
    <kb-text size="xxxs" color="master">Kind, outgoing, agile</kb-text>
  </kb-stack>
</kb-card>

Direction ​

direction controls how slotted content is stacked, not how it looks.

DirectionArrangementUse for
column (default)Vertical stackThe common case — heading over body over actions.
rowHorizontal rowContent meant to sit side by side, like a thumbnail next to a label.

An unrecognized value is ignored — the property keeps the last valid direction it had (or the default, if none was ever set).

Attributes ​

AttributeTypeDefaultDescription
directionrow | columncolumnFlex direction of the slotted content. An unrecognized value is ignored — the property keeps the last valid direction it had.
widthauto | fill | hug | lengthautoHow the card fills its container.
heightauto | fill | hug | lengthautoCard height.
hiddenbooleanfalseRemoves the card from layout and the accessibility tree.
onarc string—Echo wiring, source/event:type/sink.

Events ​

None. The card despatches nothing of its own — only the slotted content does.

Styling ​

Every visual decision is a --card-* custom property defaulting to a global token. They inherit through the shadow boundary — set them on the element or any ancestor, never reach into the shadow DOM.

Custom propertyDefaultControls
--card-color-backgroundvar(--color-master-lighter)Background of the card.
--card-border-radiusvar(--border-radius-md)Corner radius.
--card-space-gapvar(--spacing_inset-xs)Gap between slotted children.
--card-space-insetvar(--spacing_inset-xs)Inner padding.
preview
Code
html
<div style="--card-border-radius: 8px; --card-space-inset: 8px;">
  <kb-card>
    <kb-text size="xxs">Flatter and tighter, scoped to one area</kb-text>
  </kb-card>
</div>

States and accessibility ​

  • hidden removes the card from layout and interaction. Prefer it over not rendering the element when the presence or absence should stay findable.
  • The host is declared presentational (role="none"), so the card adds no node of its own to the accessibility tree and carries no accessible name. It never receives focus, and a screen reader sees exactly the slotted content, as if the card weren't there.

Do's and don'ts ​

DoDon't
Nest a real <kb-button> or <a> for anything actionableExpect the card to emit clicked or otherwise act on its own
Rely on the slotted control's own focus and keyboard behaviorAdd tabindex or a role to the card to make it "feel" interactive
Override --card-* tokens to re-skinReach into the shadow DOM to change background or padding