Skip to content

Card ​

catnip-card is a surface wrapper. By default it is a non-interactive container for consumer-owned content. Set interactive to make the whole surface one native control: an anchor when href is set, or a button type="button" when it is not.

CatnipCard owns only the surface, interaction states, disabled treatment, and native control semantics. It does not supply a title, image, icon, status, action, width, or height. The consumer owns all slotted content, its hierarchy, its layout, and the wording announced by assistive technology.

Live example ​

Container card ​

Use the default non-interactive card when it groups content or contains several separate controls:

html
<catnip-card>
  <article>
    <h2>Identity methods</h2>
    <p>Configure the methods available to your users.</p>
    <catnip-button>Configure</catnip-button>
  </article>
</catnip-card>

The card itself is not focusable and has no implicit landmark or article role. Put meaningful HTML such as article, headings, lists, or regions in the slot when the content needs that structure.

Interactive card ​

Use one interactive card for one primary action. A URL produces a real link, so browser features such as copying the address, opening a context menu, opening in another tab, and native visited-link history remain available:

html
<catnip-card interactive href="/identity-methods" card-aria-label="Open identity methods">
  <h2>Identity methods</h2>
  <p>Configure electronic identity methods.</p>
</catnip-card>

Without href, the component renders a native button type="button" for an in-page action. Listen for the ordinary click event:

html
<catnip-card interactive card-aria-label="Select Norwegian BankID">
  <strong>Norwegian BankID</strong>
</catnip-card>

<script>
  document.querySelector("catnip-card").addEventListener("click", selectMethod);
</script>

One card, one action ​

Do not put any other interactive element inside an interactive card. This includes button, a, input, select, textarea, summary, media controls, or another custom element that users can focus or activate.

The HTML Standard’s anchor content model requires that “there must be no interactive content descendant.” WCAG’s Focus Order guidance warns against controls that appear to receive focus more than once or create a confusing order. Nested actions also make the card’s purpose and activation target ambiguous for screen-reader, keyboard, touch, switch, and voice-control users.

The entire card must perform the same single action. If the content needs a primary link plus Edit, Delete, More, a checkbox, a tooltip button, or any other independent action, omit interactive and place those controls inside the card as siblings.

  • The default target is the current browsing context. Use target="_blank" only when the product genuinely requires a new tab or window, and tell users in the visible content or accessible name. noopener noreferrer is added automatically unless already present.
  • Do not add a visited prop or announce a made-up visited state. A navigation card is a native anchor, so the browser and assistive technology own real history. Browser privacy rules restrict what :visited may style or reveal.
  • Use cardAriaCurrent="page" (HTML: card-aria-current="page") for the card representing the current destination. The component forwards it as aria-current; current means current, not visited.

Styling slotted content from card state ​

The state selectors are implemented on the internal .catnip-card--interactive surface. Because that class is inside Shadow DOM, consumers should target the public catnip-card host. CSS custom properties inherit through the component and into slotted content, including nested Web Components:

css
.product-icon {
  color: var(--product-icon-color, currentColor);
}

catnip-card:hover {
  --product-icon-color: var(--catnip-color-content-primary-strong, #5f36bc);
  --catnip-icon-color: var(--catnip-color-content-primary-strong, #5f36bc);
}

catnip-card:active {
  --product-icon-color: var(--catnip-color-content-primary-strongest, #2a0062);
}

catnip-card:focus-within {
  --product-icon-color: var(--catnip-color-content-primary-strong, #5f36bc);
}

The nested icon can consume the inherited property internally:

css
:host {
  color: var(--catnip-icon-color, currentColor);
}

Avoid expecting the library to reach arbitrary descendants with ::slotted(): it can match only a node assigned directly to the slot, not an icon nested inside a slotted div:

html
<catnip-card>
  <div>
    <catnip-icon class="product-icon"></catnip-icon>
  </div>
</catnip-card>

The consumer owns these state-to-content relationships. The surface is also exposed as part="card" for narrowly scoped styling, but prefer inherited custom properties for reusable content behavior.

Guidelines ​

Choose interactive from semantics, not appearance ​

  • Omit interactive (or set it to false) when the surface groups content, has no action, or contains more than one independent control.
  • Set interactive only when the entire surface performs one action.
  • Add href when that action navigates. The component then uses a native anchor.
  • Omit href only for an in-page action such as selecting an option or opening a consumer-owned dialog. The component then uses a native button.

Do not use an action card to imitate navigation, and do not use a link card for an action that does not change location. Native semantics let browsers, keyboard users, screen readers, switch devices, and voice input predict the control.

Keep interactive cards to one action ​

An interactive card is one focus stop and one activation target. Never slot buttons, links, form fields, disclosure summaries, editable content, audio/video controls, or focusable custom elements into it.

Examples that require a non-interactive card:

  • A product card with Open, Edit, and Delete.
  • A selectable row with a checkbox and a More menu.
  • A card with a tooltip trigger or copy-to-clipboard button.
  • A media card with playback controls.
  • A form or any group of fields.

Nested controls can create invalid HTML, conflicting activation, duplicate or illogical focus stops, and an overly long or misleading accessible name. If a design requires several actions, keep the surface static and use visible native/Catnip controls inside it.

  • Internal and external URLs both use href; relative, absolute, hash, mailto:, and tel: URLs retain native anchor behavior.
  • Default to the current tab. When _blank is necessary, warn users in visible copy or the accessible name. The component resolves safe rel tokens automatically.
  • Use download only when activation downloads a resource rather than showing it.
  • Use hreflang to describe the linked resource language when useful.
  • Use cardAriaCurrent only for the one current item in a related set.
  • Never infer or manually set “visited.” A true visited state depends on private browser history.

Disabled cards ​

Avoid disabled links when possible: removing an unavailable destination or explaining why it is unavailable is often clearer. If disabled is required, the link cannot navigate and is removed from sequential focus. Ensure nearby visible text explains availability when users need that information.

A disabled container supplies the disabled surface and aria-disabled state, but cannot safely rewrite the semantics of arbitrary slotted controls. If it contains buttons, links, or fields, the consumer must disable or remove each control consistently. Do not use the state merely to make usable content look unavailable.

Content and layout ownership ​

The component supplies 16px tokenized surface padding but no width, height, minimum size, internal grid, content typography, or content components. Consumers should:

  • use headings at the correct page level rather than choosing a heading for visual size;
  • use article, lists, or landmarks only when their document meaning is correct;
  • keep reading order aligned with visual order;
  • provide alternative text for informative images and empty alt for decorative images;
  • ensure text, icons, and custom state colors meet contrast requirements;
  • size card groups responsively and use list semantics when a collection is meaningfully a list.

For hover, press, and focus styling of slotted content, see Styling slotted content from card state.

Catnip Design System by Signicat