Card

Accessibility

Card accessibility props

NameTypeDescription
labelClosestringLabel for the close button that’s announced by screen readers, ensuring users understand the button’s purpose.
dataA11ySectionstringOptional identifier for the Card that can be used to improve screen reader navigation and identification of content sections.
titleAsenumControls the semantic heading level (h1-h6) of the Card title, helping maintain proper document structure and heading hierarchy.

CardSection accessibility props

NameTypeDescription
titleAsenumControls the semantic heading level of the CardSection title, allowing proper document hierarchy within Cards.

Keyboard navigation

Card component

  • Interactive elements within cards can be accessed using the Tab key
  • When a Card contains the close button, it can be activated using Enter or Space

CardSection component

  • Expandable sections can be toggled with Enter or Space when focused
  • Focus is managed automatically when expanding/collapsing sections
  • When multiple expandable sections exist in a Card, users can navigate between them using Tab

Screen reader experience

Card component

  • Card title level as specified by the titleAs prop (when provided anything other than div)
  • The Card title as specified by the title prop (when provided)
  • The close button with the custom label specified in labelClose prop

CardSection component

  • The CardSection title as specified by the title prop
  • The content within the section when expanded
  • The expanded/collapsed state for expandable sections

Important restrictions

  • CardSection with actions and expandability: When using a clickable or expandable CardSection (expandable={true} or with onClick handler), avoid using the actions prop. If you must use it, ensure it only contains non-interactive elements. This prevents focus management issues and keyboard navigation confusion. Interactive elements in this context can create conflicts with the expanding functionality, leading to poor accessibility and usability.
<CardSection
expandable
title="Flight details"
actions={<Button>Edit</Button>} // Avoid interactive elements here
>
{/* content */}
</CardSection>
<CardSection
expandable
title="Flight details"
actions={<Badge type="info">Economy</Badge>} // Non-interactive element is acceptable
>
{/* content */}
</CardSection>
<CardSection
expandable
title="Flight details"
actions={<Button asComponent="div">Open</Button>} // Non-interactive element is acceptable
>
{/* content */}
</CardSection>

Best practices

Card best practices

  • Use semantic heading levels with the titleAs prop to maintain proper document structure
  • Provide a descriptive labelClose that clearly explains the action (e.g., “Close flight details”)
  • When creating complex page layouts and using SkipNavigation component on the page, you can use the dataA11ySection prop connect the Card with this component

CardSection best practices

  • Avoid placing interactive elements in the actions prop of expandable CardSection components
  • Maintain logical heading hierarchy between Card titles and CardSection titles

Examples with accessibility features

Basic Card with accessibility props

<Card
title="Flight details"
titleAs="h3"
dataA11ySection="flight-summary"
labelClose="Close flight details"
onClose={() => {}}
>
<CardSection>
<Stack direction="column" spacing="100">
<Text>Prague to Barcelona</Text>
<Text type="secondary">June 21, 2023</Text>
</Stack>
</CardSection>
</Card>

Card with expandable sections

<Card title="Trip itinerary" titleAs="h2" dataA11ySection="trip-details">
<CardSection expandable initialExpanded title="Flight information" titleAs="h3">
<Text>Prague to Barcelona</Text>
<Text type="secondary">June 21, 2023</Text>
</CardSection>
<CardSection expandable title="Hotel details" titleAs="h3">
<Text>Hotel Barcelona</Text>
<Text type="secondary">Check-in: June 21, 2023</Text>
</CardSection>
</Card>