Skip to main content

rc-card

Design-system-neutral card shell with structural slots and parts.

rc-card owns card anatomy and layout affordances, but authors keep native anchors and buttons for semantics and keyboard access. Themes decide visual variants through tokens and selectors rather than a variant attribute.

Package
@rcarls/rc-card
Element
<rc-card>
Native dependency
Author-provided links and buttons
State model
Declarative selected/disabled/interactive hooks
Main events
None

Installation

npm install @rcarls/rc-card
import '@rcarls/rc-card/define';

Markup

<rc-card interactive action-target="article-link">
<img slot="media" src="/article-cover.jpg" alt="" />
<h2 slot="title">
<a id="article-link" href="/articles/resilient-interfaces">Resilient interfaces</a>
</h2>
<p>Patterns for preserving native behavior while adding richer interactions.</p>
<button slot="actions" type="button">Save</button>
</rc-card>

The theme-free card provides one rem of body padding and otherwise remains an undecorated content container. Apply a packaged theme or card tokens when the composition needs a different spacing scale, shape, elevation, or state layers.

Live demo

Structure

Slots cover media, header, title, subtitle, default body, actions, and footer. Matching parts and reflected has-* attributes let themes adapt spacing when regions are present or absent.

For shelf/grid layouts, set card rows through --rc-card-grid-template-rows. The demo spans each card across the parent grid's media, title, body, and action tracks, then uses subgrid on the hosts to align those regions across cards with different content.

Card titles remain author-owned semantic content. The packaged themes normalize slotted h2 and h3 margins and map those ranks to card-appropriate title typography. The Material mapping follows the Material 3 card specification and Android's semantic Material 3 type scale.

Action Target

action-target="id" forwards non-interactive surface clicks to a same-root anchor or button. It is pointer/tap convenience only; keyboard access and semantics remain on the real target element.

API

Properties

PropertyMarkupTypeDefaultDescription
selectedselectedbooleanfalseDeclarative selected state for theme styling.
disableddisabledbooleanfalseDeclarative disabled state. Disables action-target click forwarding.
interactiveinteractivebooleanfalseVisual affordance for cards with an author-provided action target.
actionTargetaction-targetstring''ID of a same-root anchor or button that receives forwarded surface clicks.

Methods

No public methods are documented in the custom elements manifest.

Events

No custom events are documented in the custom elements manifest.

Slots

NameDescription
mediaMedia region, typically an image or figure.
headerHeader content above title/body.
titlePrimary card title.
subtitleSecondary title or metadata.
(default)Body content.
actionsAction row.
footerFooter content.

CSS Custom Properties

PropertyDefaultDescription
--rc-card-grid-template-rowsauto auto auto 1fr auto autoGrid template rows for the host's structural regions.
--rc-card-border0Card border.
--rc-card-radius0Card border radius.
--rc-card-bgCanvasCard background.
--rc-card-colorCanvasTextCard text color.
--rc-card-shadownoneCard box shadow.
--rc-card-container-bgtransparentBackground of the non-interactive container overlay.
--rc-card-state-layer-bgcurrentColorState-layer overlay color.
--rc-card-state-layer-duration150msState-layer opacity transition duration.
--rc-card-state-layer-easingeaseState-layer opacity transition easing.
--rc-card-hover-state-layer-opacity0State-layer opacity on hover (interactive cards only).
--rc-card-pressed-state-layer-opacity0State-layer opacity on active press (interactive cards only).
--rc-card-padding-blockNot specifiedShared block-axis padding fallback for regions that don't set their own `*-padding-block` property. Defers to each region's own default (0 for header/title/subtitle/actions/footer, 1rem for body) when unset.
--rc-card-padding-inlineNot specifiedShared inline-axis padding fallback for regions that don't set their own `*-padding-inline` property. Defers to each region's own default (0 for header/title/subtitle/actions/footer, 1rem for body) when unset.
--rc-card-media-grid-rowautoGrid row for the media region.
--rc-card-header-grid-rowautoGrid row for the header region.
--rc-card-header-padding-blockvar(--rc-card-padding-block, 0) 0Header block-axis padding.
--rc-card-header-padding-inlinevar(--rc-card-padding-inline, 0)Header inline-axis padding.
--rc-card-title-grid-rowautoGrid row for the title region.
--rc-card-title-padding-blockvar(--rc-card-padding-block, 0) 0Title block-axis padding.
--rc-card-title-padding-inlinevar(--rc-card-padding-inline, 0)Title inline-axis padding.
--rc-card-title-colorinheritTitle text color.
--rc-card-title-fontinheritTitle font shorthand.
--rc-card-subtitle-grid-rowautoGrid row for the subtitle region.
--rc-card-subtitle-padding-block0Subtitle block-axis padding.
--rc-card-subtitle-padding-inlinevar(--rc-card-padding-inline, 0)Subtitle inline-axis padding.
--rc-card-subtitle-colorinheritSubtitle text color.
--rc-card-subtitle-fontinheritSubtitle font shorthand.
--rc-card-body-grid-rowautoGrid row for the body region.
--rc-card-body-padding-blockvar(--rc-card-padding-block, 1rem)Body block-axis padding.
--rc-card-body-padding-inlinevar(--rc-card-padding-inline, 1rem)Body inline-axis padding.
--rc-card-actions-grid-rowautoGrid row for the actions region.
--rc-card-actions-justifyflex-endJustify-content for the actions row.
--rc-card-actions-gap0Gap between action items.
--rc-card-actions-padding-block0 var(--rc-card-padding-block, 0)Actions block-axis padding.
--rc-card-actions-padding-inlinevar(--rc-card-padding-inline, 0)Actions inline-axis padding.
--rc-card-footer-grid-rowautoGrid row for the footer region.
--rc-card-footer-padding-block0 var(--rc-card-padding-block, 0)Footer block-axis padding.
--rc-card-footer-padding-inlinevar(--rc-card-padding-inline, 0)Footer inline-axis padding.

CSS Parts

PartDescription
containerNon-interactive visual container overlay.
mediaMedia region wrapper.
headerHeader region wrapper.
titleTitle region wrapper.
subtitleSubtitle region wrapper.
bodyBody region wrapper.
actionsActions region wrapper.
footerFooter region wrapper.
state-layerNon-interactive overlay for hover/pressed/ripple effects.