When to use it#
- Use a card for one thing that a resident or a case worker looks at as a unit: a service, a news item, a case.
- Put a heading at the top and, if the card leads somewhere, one link in the heading. Actions go in the footer as buttons.
- A list of cards is a list: render each card as a list item, so a screen reader (software that reads the screen aloud) says how many there are.
- Not for a region of the page, such as a sidebar or a band of content: use a Section. A card on a section is fine, a section inside a card isn’t.
Example#
Waste collection at Storgatan 12
Food waste and residual waste are collected every other week.
import { Card, Heading } from '@kvirn-ui/react'
import { useCardTexts } from './texts.ts'
export function DefaultCard() {
const { texts } = useCardTexts()
return (
<Card.Root className="kv-prose">
<Heading as="h3">{texts.service.heading}</Heading>
<p>{texts.service.text}</p>
</Card.Root>
)
}Use cases#
A service with actions
Use it when a card is a service the user can act on. The text goes in the body, with the heading first, and the actions go in the footer: one primary button, the rest secondary.
Waste collection at Storgatan 12
Food waste and residual waste are collected every other week.
import { Button, Card, Heading } from '@kvirn-ui/react'
import { useCardTexts } from './texts.ts'
export function CardWithActions() {
const { texts } = useCardTexts()
return (
<Card.Root>
<Card.Body className="kv-prose">
<Heading as="h4">{texts.service.heading}</Heading>
<p>{texts.service.text}</p>
</Card.Body>
<Card.Footer className="kv-button-group">
<Button className="kv-button--primary">{texts.service.orderExtra}</Button>
<Button>{texts.service.pause}</Button>
</Card.Footer>
</Card.Root>
)
}Props in this example:
A list of news items
Several cards of the same kind are a list. Make each card a list item with as, so a screen reader announces how many items there are. Give each card one link, in its heading, with text that makes sense on its own.
New opening hours at the recycling centre
From 1 November the recycling centre is open until 19:00 on weekdays.
Winter road maintenance: how we clear snow
We clear main roads and bus routes first, then residential streets.
Apply for association grants by 1 December
Sports and culture associations can apply for grants for next year.
import { Card, Heading, Link } from '@kvirn-ui/react'
import { useCardTexts } from './texts.ts'
export function NewsList() {
const { texts } = useCardTexts()
const items = [texts.news.recycling, texts.news.snow, texts.news.grants]
return (
<ul role="list" className="kv-stack">
{items.map((item) => (
<Card.Root key={item.title} as="li">
<Card.Body className="kv-prose">
<Heading as="h4">
<Link href="#">{item.title}</Link>
</Heading>
<p>{item.excerpt}</p>
</Card.Body>
</Card.Root>
))}
</ul>
)
}Props in this example:
ason Card.Root
Warning: Don't forget
Put role="list" on a hand-written <ul>. The default theme draws no marker on a card, and Safari with VoiceOver can then read the list as a plain group (1.3.1 Info and Relationships). A Stack as a <ul> adds it for you.
A story that stands on its own
Render the card as an <article> when it is a self-contained item, such as a news story, and name it with aria-labelledby pointing at its heading. An <article> is not a landmark, so many of them don’t crowd a screen reader’s list of landmarks.
New opening hours at the recycling centre
From 1 November the recycling centre is open until 19:00 on weekdays. On Saturdays it closes at 15:00.
import { Card, Heading } from '@kvirn-ui/react'
import { useId } from 'react'
import { useCardTexts } from './texts.ts'
export function ArticleCard() {
const { texts } = useCardTexts()
const headingId = useId()
return (
<Card.Root as="article" aria-labelledby={headingId}>
<Card.Body className="kv-prose">
<Heading as="h4" id={headingId}>
{texts.article.title}
</Heading>
<p>{texts.article.text}</p>
</Card.Body>
</Card.Root>
)
}Props in this example:
ason Card.Root
A case with a divider between its parts
A card for staff or a dense page can mark its parts with a line and use less padding. Put the heading in the header, the content in the body and the action in the footer.
Housing adaptation grant
Waiting for a decision.
Latest event: the occupational therapist’s certificate arrived.
import { Button, Card, Heading } from '@kvirn-ui/react'
import { useCardTexts } from './texts.ts'
export function CardWithDividers() {
const { texts } = useCardTexts()
return (
<Card.Root className="kv-card--dividers kv-card--padding-sm">
<Card.Header>
<Heading as="h4">{texts.dividers.heading}</Heading>
</Card.Header>
<Card.Body className="kv-prose">
<p>{texts.dividers.text}</p>
<p>{texts.dividers.next}</p>
</Card.Body>
<Card.Footer>
<Button>{texts.dividers.addDocument}</Button>
</Card.Footer>
</Card.Root>
)
}Props in this example:
classNameon Card.Root
Accessibility#
What it does for you#
- APG pattern: none. A card is not a widget, so there is no APG pattern.
- Deviations: none
- Native elements used:
<div>for every part by default.Card.Roottakesas(allowed elements below), and the element's own semantics apply.
Card is a plain container for content on a surface. It adds no role, no ARIA, no text, no tabindex and no behaviour. Everything a user perceives inside a card comes from the consumer's children, which keep their own semantics and focus order.
| Part | Element / role | ARIA | Notes |
|---|---|---|---|
| Card.Root | <div> → generic | none. The consumer adds it with the element | class="kv-card". as="article", "section" with aria-labelledby, "figure" or "li" give it a role. Also exported as CardRoot |
| Card.Header | <div> → generic | none | class="kv-card-header". Never <header>: at the top level it would be a banner landmark. Also exported as CardHeader |
| Card.Body | <div> → generic | none | class="kv-card-body". Also exported as CardBody |
| Card.Footer | <div> → generic | none | class="kv-card-footer". Never <footer>: at the top level it would be a contentinfo landmark. Also exported as CardFooter |
| Card.Root | as | the chosen element's own | One element, chosen with a string. A tag outside the list is a type error. In plain JavaScript it warns once in development and renders a <div>. Header, Body and Footer have no as: they are always a <div>. className joins, style and refs pass |
| every part | attributes | passed through | aria-*, id, data-* and every other attribute reach the element unchanged. The part's class is its own: a className prop joins it, never replaces it |
| every part | never | no role, aria-*, tabindex, inert, aria-hidden | No click handler, no heading, no live region, no text |
useCard() gives the same rootProps, headerProps, bodyProps and footerProps (only className) for your own elements.
It announces nothing.
What you need to do#
- Heading level. Put a heading at the top of
Card.Body(or the Root), at the level the page outline needs:h2for a card on My pages,h3for cards under anh2list heading. Card can't know it (2.4.6 Headings and Labels, 1.3.1 Info and Relationships). - Alt text. Use
alt=""for a decorative image, which most card images are when the heading names the topic. Give an informative image real alt text. Don't put text in images. The image comes first in the page's order, as it does on screen (1.1.1 Non-text Content, 1.3.2 Meaningful Sequence). - Links. One link per card, in the heading, with text that makes sense on its own (2.4.4 Link Purpose (In Context)). No "Read more", and no second link on the image.
- Buttons. Write them as verbs, and use one primary button per view. Going to another page is a Link, not a Button.
- Landmarks. Use
as="section"witharia-labelledby={headingId}only for a region a user would want to jump to. Asectionwithout a name isn't a landmark. Never make every card in a list a landmark.<article>is for a self-contained item such as a news story. - Lists. A list of cards is a
<ul>with each card rendered as<li>(as="li"), so screen readers say how many items there are. The default theme draws no marker on a card, and Safari can then treat a<ul>without visible markers as a plain group. Putrole="list"on a hand-written<ul>to keep it a list there (see Known issues). Stack and Grid add it themselves. - Card or Section. A card is one identifiable thing. A region of the page (a sidebar, a band, a group of controls) is a Section, and a form section is a heading or a
<fieldset>. A Card on a Section is fine. Don't put a Section inside a Card. - Language. Text in another language goes in a nested
KvirnProvider, withuseLocale().localePropson your own element (3.1.2 Language of Parts). - Parts are direct children of the Root. The default theme's padding relies on it. Don't render an empty part.
Warning: Don't forget
Choose the heading level the page’s outline needs, because Card can’t know it (2.4.6 Headings and Labels). Give a decorative image alt="", and put one link per card in the heading, with text that makes sense on its own (1.1.1 Non-text Content, 2.4.4 Link Purpose (In Context)).
Visual and modes#
Headless: Card ships no CSS. With @kvirn-ui/theme/theme.css:
- Focus indicator: none of its own, because a card is never focused. Children keep their own rings, and the card doesn't clip them.
- Target size: not applicable. Footer buttons keep their own sizes (2.5.8 Target Size (Minimum), AA).
- Contrast: the default theme checks that text, links, muted text and button edges meet their minimum contrast on the card's surface and on the surfaces a card sits on (1.4.3 Contrast (Minimum), AA; 1.4.11 Non-text Contrast, AA). The card's own edge is decorative and low in contrast on purpose: the heading and the spacing group the content, not the edge.
- Forced colours: the card keeps a visible border in the system's text colour, so its boundary and dividers stay.
- Reduced motion: nothing moves. There is no hover effect, transition or pointer style.
- Reflow and text spacing: no fixed sizes, no clipping, long words break, and the card can shrink in a grid. The reflow sweep runs every story at 320 CSS px, with Finnish text, and fails on horizontal overflow, and the text-spacing sweep applies the 1.4.12 spacing to every story and fails on a box that clips more content than it holds (1.4.10 Reflow, 1.4.12 Text Spacing). Media directly in a part or the Root never get wider than it.
Focus management#
- Initial focus: not moved. Card never moves focus.
- Trap: no.
- Restore to: not applicable.
- Never hidden by: Card draws nothing over its content. The default theme never crops a card, so a child's focus ring is not clipped (2.4.11 Focus Not Obscured (Minimum), AA). Media that touch a rounded corner get the corner's radius themselves instead.
Allowed elements#
A tag outside the list changes the page's outline or semantics (1.3.1, 4.1.2). as is a string, so it works from a Server Component.
| Part | `as` | Why |
|---|---|---|
| Card.Root | div (default), li, article, figure, section | A list item, a self-contained item, media with a caption, or a named region. No aside (a card is an object, not tangential content) |
| Header, Body, Footer | none | Always a <div>: a <header> or <footer> would become a landmark |
WCAG success criteria#
- 1.3.1 Info and Relationships (A): the card has no role of its own, so your element and children decide the meaning. Header and Footer are never landmarks.
- 1.3.2 Meaningful Sequence (A) and 2.4.3 Focus Order (A): the order in the page is the reading order and the focus order. The Tab rows prove the card is skipped.
- 1.4.3 Contrast (Minimum) (AA) and 1.4.11 Non-text Contrast (AA): the default theme's colour pairs on every card surface are checked automatically.
- 1.4.10 Reflow (AA) and 1.4.12 Text Spacing (AA): the card doesn't crop or fix its size. The reflow and text-spacing sweeps check it: the reflow sweep runs every story at 320 CSS px and fails on horizontal overflow; the text-spacing sweep applies the 1.4.12 spacing to every story and fails on a box that clips more content than it holds.
- 2.4.11 Focus Not Obscured (Minimum) (AA): the card doesn't clip a child's focus ring. 2.4.13 Focus Appearance (AAA) is not counted toward AA.
- 4.1.2 Name, Role, Value (A): the card has no role or name of its own to get wrong.
Keyboard#
Card has no keys of its own. What you put in it keeps its own keys.
API reference#
import { Card, useCard } from '@kvirn-ui/react'Card.Root
Renders <div> with no role, or the element as picks. It takes every attribute of that element and passes ref to it. Also exported as CardRoot. The default theme is described on Theming.
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | – | Your own classes. They join the part’s class and never replace it, so the theme keeps styling the card. |
as | 'div' | 'li' | 'article' | 'figure' | 'section' | 'div' | Changes the element: li in a list of cards, article for a self-contained item, figure with a caption, or section with aria-labelledby. Card adds no role. Another tag warns once in development. |
| Class or attribute | Values | Meaning |
|---|---|---|
kv-card | always | The part class. The default theme styles it. |
kv-card--radius-lg | -md | -none | class you add | The radius. lg is the default, md suits a card inside a card. |
kv-card--padding-none | -sm | -md | -lg | class you add | The padding of every part. md is the default. |
kv-card--dividers | class you add | A subtle line between the parts. |
Card.Header
Renders <div> with no role. It takes every attribute of a <div> and passes ref to it. The default theme is described on Theming. Never a <header>, which would be a page landmark. Also exported as CardHeader.
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | – | Your own classes. They join the part’s class and never replace it, so the theme keeps styling the card. |
| Class or attribute | Values | Meaning |
|---|---|---|
kv-card-header | always | The part class. The default theme styles it. |
kv-card-header--padding-none | -sm | -md | -lg | class you add | This part’s padding, instead of the Root’s. none is for full-bleed media. |
Card.Body
Renders <div> with no role. It takes every attribute of a <div> and passes ref to it. The default theme is described on Theming. Also exported as CardBody.
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | – | Your own classes. They join the part’s class and never replace it, so the theme keeps styling the card. |
| Class or attribute | Values | Meaning |
|---|---|---|
kv-card-body | always | The part class. The default theme styles it. |
kv-card-body--padding-none | -sm | -md | -lg | class you add | This part’s padding, instead of the Root’s. |
Card.Footer
Renders <div> with no role. It takes every attribute of a <div> and passes ref to it. The default theme is described on Theming. Never a <footer>, which would be a page landmark. Also exported as CardFooter.
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | – | Your own classes. They join the part’s class and never replace it, so the theme keeps styling the card. |
| Class or attribute | Values | Meaning |
|---|---|---|
kv-card-footer | always | The part class. The default theme styles it. |
kv-card-footer--padding-none | -sm | -md | -lg | class you add | This part’s padding, instead of the Root’s. |
useCard
Takes no options. Use it for your own elements, such as a <section> with aria-labelledby. You pick the element and the heading level.
Result
| Prop | Type | Default | Description |
|---|---|---|---|
rootProps | { className: 'kv-card' } | – | Spread on the Root’s element. |
headerProps | { className: 'kv-card-header' } | – | Spread on the Header’s element. |
bodyProps | { className: 'kv-card-body' } | – | Spread on the Body’s element. |
footerProps | { className: 'kv-card-footer' } | – | Spread on the Footer’s element. |
const card = useCard()
<section {...card.rootProps} aria-labelledby={headingId}>
<div {...card.bodyProps}>…</div>
</section>Known issues#
- WebKit is not automated. Keyboard rows run in Vitest browser mode on Chromium. WebKit is not covered by the automated tests, so check Safari with your own users and assistive technology.
- A list of cards can lose its list role in Safari. Safari with VoiceOver drops the list role when
list-style: noneremoves the markers, which the default theme does. Writerole="list"on a hand-written<ul>, or use Stack or Grid as the list: they add it themselves. If your linter callsrole="list"redundant, relax that rule forulonly. Check it with VoiceOver in Safari. - Prose and nested cards. Prose turned on inside a card (
kv-prose) stops at a nested card, for two levels of nesting. The default theme doesn't support deeper nesting.
Testing#
The automated tests prove the keyboard behaviour, the names and states, that axe finds no violations in every story and theme, and, for the components they cover, that the stories hold up in forced colours, reduced motion, text spacing and a 320 pixel width. An Automated row passes on these tests alone. A Core or Release row passes only when an automated agent check and a person on the real assistive technology have both checked it. "agent-verified" means automated tests in the repository (with a virtual screen reader for the screen reader rows), not the real assistive technology.
| AT + browser + OS | Agent check | Human check | Result | Notes |
|---|---|---|---|---|
| Automated (re-runnable tests) | ||||
| axe, WCAG 2.2 A and AA, every story, 4 themes | pass | n/a | pass | card.stories.tsx, every story, 4 themes |
| Markup and ARIA (roles, names, ids, states) | pass | n/a | pass | card.test.tsx (axe and role, name and state): adds no role, ARIA or tabindex |
| Keyboard contract rows (Vitest browser) | pass | n/a | pass | 3 rows, each names a test in card.test.tsx |
| Focus order and management | pass | n/a | pass | card.test.tsx: the card is skipped by Tab: focus goes through its children in DOM order |
| Display modes (forced colours, 320px reflow, text spacing, reduced motion) | pass | n/a | pass | the four sweep projects (storybook-forced-colors, -reduced-motion, -reflow, -text-spacing), run in CI |
| Core (required for beta) | ||||
| NVDA + Chrome + Windows | pending | pending | pending | |
| VoiceOver + Safari + iOS | pending | pending | pending | |
| Release (before 1.0 and each minor) | ||||
| JAWS + Chrome + Windows | pending | pending | pending | |
| TalkBack + Chrome + Android | pending | pending | pending | |
| VoiceOver + Safari + macOS | pending | pending | pending |
What to check#
With a screen reader and the keyboard, try:
- Tab through a card with a heading link and two buttons: focus lands on the link, then each button, never the card.
- A list of cards in VoiceOver on Safari is announced as a list with its count.
- The heading is read before the actions.