Liking cljdoc? Tell your friends :D

x-card

Themeable surface container for grouping related content.

Attributes

AttributeValuesDefault
variantelevated | outlined | filled | ghostelevated
paddingnone | sm | md | lgmd
radiusnone | sm | md | lg | xllg
interactiveboolean (presence)absent
disabledboolean (presence)absent
labelstring

Properties

PropertyTypeReflects to attribute
interactivebooleanyes (interactive)
disabledbooleanyes (disabled)

Event

EventDetailBubblesComposed
press{}yesyes

Fired on click, Enter, or Space when interactive is set and disabled is absent.

Accessibility

Default state: no role or tabindex set.

Interactive mode:

  • role="button" added to host
  • tabindex="0" (focusable) when not disabled
  • tabindex="-1" (non-focusable) when disabled
  • aria-disabled="true" when disabled
  • Enter and Space trigger press; Space also calls preventDefault

The label attribute maps to aria-label on the host.

Slot

Default slot only. Accepts arbitrary content.

Styling

Override CSS custom properties on the host element:

x-card {
  --x-card-background: white;
  --x-card-color: black;
}

Custom properties

PropertyDefault (light)Purpose
--x-card-backgroundrgba(255,255,255,0.92)Base surface colour
--x-card-color#111827Text colour
--x-card-border-colorrgba(17,24,39,0.12)Outlined variant border
--x-card-filled-backgroundrgba(241,245,249,0.96)Filled variant surface
--x-card-ghost-backgroundtransparentGhost variant surface
--x-card-hover-backgroundrgba(15,23,42,0.04)Interactive hover state
--x-card-press-backgroundrgba(15,23,42,0.08)Interactive active/press state
--x-card-shadow0 10px 24px rgba(15,23,42,0.10)Elevated variant shadow
--x-card-focus-ringrgba(59,130,246,0.55)Focus ring colour
--x-card-disabled-opacity0.6Opacity when disabled
--x-card-padding-none0Padding token — none
--x-card-padding-sm0.5remPadding token — sm
--x-card-padding-md1remPadding token — md
--x-card-padding-lg1.5remPadding token — lg
--x-card-radius-none0Radius token — none
--x-card-radius-sm0.375remRadius token — sm
--x-card-radius-md0.75remRadius token — md
--x-card-radius-lg1remRadius token — lg
--x-card-radius-xl1.5remRadius token — xl
--x-card-transition-duration140msHover/press transition speed
--x-card-transition-timingeaseHover/press transition easing

Dark mode values are set automatically via @media (prefers-color-scheme: dark). Transition animations are suppressed via @media (prefers-reduced-motion: reduce).

Internal styling hooks (part="base")

The inner wrapper div carries part="base" and the following data-* attributes that can be targeted in external stylesheets:

AttributeValues
data-variantelevated | outlined | filled | ghost
data-paddingnone | sm | md | lg
data-radiusnone | sm | md | lg | xl
data-interactive"true" or absent
data-disabled"true" or absent

Note: data-* values reflect the normalised value, not the raw attribute. Invalid attribute values are silently corrected to the default.

Example

<!-- Static card -->
<x-card variant="outlined" padding="md">
  <h3>Title</h3>
  <p>Content here.</p>
</x-card>

<!-- Interactive card -->
<x-card variant="elevated" padding="md" interactive label="Open details">
  <h3>Click me</h3>
  <p>Fires a press event.</p>
</x-card>

<script>
  document.querySelector('x-card[interactive]')
    .addEventListener('press', () => console.log('pressed'));
</script>

Can you improve this documentation?Edit on GitHub

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close