ba-card

Cards are used for aggregating groups of content together. They are easy to browse and can be used in a variety of instances across the products for a multitude of use cases

Figma GitHub Storybook

Cards, like other BAgel components, will stretch to fill all the horizontal space available and be as high as the content they contain. Consideration should be taken to adjust the card size to suit the content within the body of the card and it's position in a page or journey

As a general rule cards should be:

  • 1 column on small / mobile devices
  • 2 or 3 columns on medium / tablet devices
  • 2, 3, or 4 columns on large / desktop devices

Images choices should always be related to the card content, eg. photos of relevant destinations etc.

It is possible to use any of the image ratios provided by the ba-image component, however it is recommended to use 1:1, 4:3, and 16:9.

Adding a heading on to cards helps users navigate the page and understand the content of the card

Cards can have up to 2 actions:

ba-link
Must be used when linking to another page
ba-button
Must only be used when submitting data in a ba-form
When there are 2 ba-buttons on a card - the first action must be primary / sale and the other must be a secondary style
ba-details
Only 1 per card
Can be used in combination with other actions but make it the last action at the bottom of the card
Other cards in the group will expand when the ba-details is open
Must be the last action when used in combination with other actions
ba-loading-skeleton
Must be used to show a loading state.

Icons should be a replacement for the image, they should not be used together.

On the smallest size card and viewport:

  • Headings should not stretch longer than 2 lines
  • Body copy should be no longer than 5 to 6 lines

When grouping cards together, consider the Hermann Grid illusion. The Hermann Grid illusion is an optical illusion that occurs when viewing a grid of black squares on a white background. When you look at the grid, you see faint grey spots at the intersections of the grid lines. This is because the brain is trying to interpret the intersections as a single point, and the grey spots are the result of this interpretation.

When you group too many cards together, the brain can interpret the cards as a single entity, making it difficult to distinguish between individual cards.

Further reading:

Using the ARIA list and listitem roles a screen reader will let users know how many cards there are and provide tools to navigate between them

Example

<div role="list">
  <ba-card role="listitem">...</ba-card>
  <ba-card role="listitem">...</ba-card>
  <ba-card role="listitem">...</ba-card>
  ...
</div>

Further reading:

Using the group role and aria-labbeledby by helps screen reader users understand that form controls are part of the same section of a form. Make sure that aria-labbeledby uses the id of the text that describes the cards form elements.

<ba-form>
  <ba-card role="group" aria-labelledby="label-id">
    <ba-content>
      <p id="label-id">Label</p>
    </ba-content>
    <!-- Form controls -->
    <ba-button slot="action">Submit</ba-button>
  </ba-card>
</ba-form>

Further reading:

Code

Properties & Attributes

Property Attribute Description Type Default
dropShadow drop-shadow Toggles a drop shadow on the card boolean | undefined false
tagText tag-text Text to display on the tag, this will only display if an image is present string | undefined undefined

Slots

Slot Description Permitted elements
Unnamed slot Elements will render in the body of the component <ba‑content>, <ba‑copy‑to‑clipboard>, <ba‑flex>, <ba‑flight‑line>, <ba‑form>, <ba‑form‑group>, <ba‑form‑group‑dropdown>, <ba‑grid>, <ba‑input>, <ba‑input‑date>, <ba‑input‑datepicker>, <ba‑input‑email>, <ba‑input‑number>, <ba‑input‑password>, <ba‑input‑phone‑number>, <ba‑input‑stepper>, <ba‑input‑text>, <ba‑input‑textarea>, <ba‑input‑typeahead>, <ba‑input‑upload>, <ba‑loading‑skeleton>, <ba‑media‑object>, <ba‑radio‑group>, <ba‑select>, <fieldset>, <form>
"image" Component to show at the top of the card <ba‑image>
"action" Interactive elements to show at the bottom of the card <ba‑button>, <ba‑details>, <ba‑download>, <ba‑link>, <ba‑loading‑skeleton>

Permitted ARIA roles

  • listitem
  • group
  • aria-labelledby when used with group

Parent components

ba-card can be slotted into:

Usage

Basic usage

In most scenarios a card will consist of an image, some content, and an action

A card with image, content and action
<ba-card>
  <ba-image slot="image" src="" alt=""></ba-image>
  <ba-content>
    <!-- card content -->
  </ba-content>
  <ba-link slot="action" href="/url">Action</ba-link>
</ba-card>

Adding a tag over the image

A tag can be added by using the tag-text attribute. The tag will be positioned over the image in the top left corner.

A card with a tag, image, content and action
<ba-card tag-text="Tag text">
  <ba-image slot="image" src="" alt=""></ba-image>
  <ba-content>
    <!-- card content -->
  </ba-content>
  <ba-link slot="action" href="/url">Action</ba-link>
</ba-card>

Multiple actions

Multiple actions can be added by assigning multiple components to the action slot

A card with 2 actions
<ba-card>
  <!-- card content -->
  <ba-link slot="action" href="/url">Action 1</ba-link>
  <ba-link slot="action" href="/url">Action 2</ba-link>
</ba-card>

Placing form controls in the card

Instead of putting all of the form elements (<ba-form>, <ba-input>, <ba-button>, etc) in the anonymous slot of the card it is preferable to:

  • Wrap the ba-card in a <ba-form> element
  • Put inputs (<ba-input>, <ba-select>, etc) in the anonymous slot
  • Place the <ba-button> in the action slot

This will ensure that the card layout is consistent with other cards

A card that is used as a log in form
<ba-form>
  <ba-card role="group" aria-labelledby="log-in-legend">
    <ba-content>
      <p id="log-in-legend">Log in</p>
    </ba-content>
    <ba-input type="text">
      <span slot="label">Username</span>
    </ba-input>
    <ba-input type="password">
      <span slot="label">Password</span>
    </ba-input>
    <ba-button slot="action">Submit</ba-button>
  </ba-card>
</ba-form>

As a container

The card component can also be used to group custom layouts and content

A card using ba-grid to position an image to the left hand side on larger screens
<ba-card>
  <ba-grid columns-1024vw="1:2">
    <ba-image alt="" src=""></ba-image>
    <ba-content>
      <h4>Example heading</h4>
      <p>Example content</p>
    </ba-content>
  </ba-grid>
</ba-card>

With a drop shadow

The card component can also be rendered with a drop shadow to give the component some depth.

A card being rendered with a drop shadow
<ba-card drop-shadow>
  <ba-image
    alt="Description of image"
    src="ba-card-live-demo.jpg"
    slot="image"
    aspect-ratio="16-9"
  ></ba-image>
  <ba-content>
    <h4>Example heading</h4>
    <p>Example content</p>
  </ba-content>
  <ba-link href="/link" slot="action">Action</ba-link>
</ba-card>

High contrast mode users

  • Border is added to the card to separate it from the background
  • Tag text is visible in high contrast mode

Screen reader users

  • Tag text is read out when the card is focused

UX Criteria

  • Card includes a heading that summarises its content
  • Card has a maximum of 2 actions at the bottom of the card
  • Groups of cards do not suffer from the Hermann Grid illusion
  • Headings should not stretch longer than 2 lines
  • Body copy should be no longer than 5 to 6 lines
  • Tag text is concise

Accessibility Criteria

  • Card has a role of listitem when used in a list
  • Card has a role of group and an aria-labelledby attribute when used in a ba-form
  • Tag text doesn't break the image when font size is increased to 200%
GitHub Storybook Figma library Version 3 release guide Release history BAgel helper QA process