1. Component Guide
  2. Cards (experimental)
Component

Cards (experimental)

A grid of cards that have a link and a description

The component renders the cards as an unordered list element and visually presents it as a grid. It doesn’t use the GOV.UK Design System grid but sets its own so that it can separately target desktop, tablet and mobile columns.

You can display the grid in three or two columns on desktop. Browsers that don’t support CSS grid always display one column.

You must set a href for all the links.

This component is currently experimental. If you are using it, please feed back any research findings to the GOV.UK Explore team.

Search for usage of this component on GitHub.

How it looks (preview) (preview all)

Services and information

How to call this component

<%= render "govuk_publishing_components/components/cards", {
  heading: "Services and information",
  items: [
    {
      link: {
        text: "Benefits",
        path: "http://www.gov.uk"
      },
      description: "Includes eligibility, appeals, tax credits and Universal Credit"
    },
    {
      link: {
        text: "Births, deaths, marriages and&nbsp;care",
        path: "http://www.gov.uk"
      },
      description: "Parenting, civil partnerships, divorce and Lasting Power of Attorney"
    },
    {
      link: {
        text: "Business and self-employed",
        path: "http://www.gov.uk"
      },
      description: "Tools and guidance for businesses"
    },
    {
      link: {
        text: "Childcare and parenting",
        path: "http://www.gov.uk"
      },
      description: "Includes giving birth, fostering, adopting, benefits for children, childcare and schools"
    },
    {
      link: {
        text: "Citizenship and living in the&nbsp;UK",
        path: "http://www.gov.uk"
      },
      description: "Voting, community participation, life in the UK, international projects"
    },
    {
      link: {
        text: "Crime, justice and the&nbsp;law",
        path: "http://www.gov.uk"
      },
      description: "Legal processes, courts and the police"
    },
    {
      link: {
        text: "Disabled people",
        path: "http://www.gov.uk"
      },
      description: "Includes carers, your rights, benefits and the Equality Act"
    },
    {
      link: {
        text: "Driving and transport",
        path: "http://www.gov.uk"
      },
      description: "Includes vehicle tax, MOT and driving licences"
    },
    {
      link: {
        text: "Education and learning",
        path: "http://www.gov.uk"
      },
      description: "Includes student loans, admissions and apprenticeships"
    },
    {
      link: {
        text: "Employing people",
        path: "http://www.gov.uk"
      },
      description: "Includes pay, contracts, hiring and redundancies"
    },
    {
      link: {
        text: "Environment and countryside",
        path: "http://www.gov.uk"
      },
      description: "Includes flooding, recycling and wildlife"
    },
    {
      link: {
        text: "Housing and local services",
        path: "http://www.gov.uk"
      },
      description: "Owning or renting and council services"
    }
  ]
} %>

Accessibility acceptance criteria

The component must:

  • use the correct heading level hierarchy eg. if the component heading uses a <h2>, the subheadings must use a <h3>

It is also good practise to include a heading above the list to tell users what the list contains

Links in the component must:

  • accept focus
  • be focusable with a keyboard
  • be usable with a keyboard
  • indicate when they have focus
  • change in appearance when touched (in the touch-down state)
  • change in appearance when hovered
  • be usable with touch
  • be usable with voice commands
  • have visible text
  • have meaningful text

Other examples

Standard options

This component uses the component wrapper helper. It accepts the following options and applies them to the parent element of the component. See the component wrapper helper documentation for more detail.

  • id - accepts a string for the element ID attribute
  • data_attributes - accepts a hash of data attributes
  • aria - accepts a hash of aria attributes
  • classes - accepts a space separated string of classes, these should not be used for styling and must be prefixed with js-
  • role - accepts a space separated string of roles
  • lang - accepts a language attribute value

Two column layout (preview)

Override default three column layout on desktop by passing through two_column_layout parameter (defaults to false).

<%= render "govuk_publishing_components/components/cards", {
  two_column_layout: true,
  items: [
    {
      link: {
        text: "Benefits",
        path: "http://www.gov.uk"
      },
      description: "Includes eligibility, appeals, tax credits and Universal Credit"
    },
    {
      link: {
        text: "Births, deaths, marriages and&nbsp;care",
        path: "http://www.gov.uk"
      },
      description: "Parenting, civil partnerships, divorce and Lasting Power of Attorney"
    },
    {
      link: {
        text: "Business and self-employed",
        path: "http://www.gov.uk"
      },
      description: "Tools and guidance for businesses"
    },
    {
      link: {
        text: "Childcare and parenting",
        path: "http://www.gov.uk"
      },
      description: "Includes giving birth, fostering, adopting, benefits for children, childcare and schools"
    },
    {
      link: {
        text: "Citizenship and living in the&nbsp;UK",
        path: "http://www.gov.uk"
      },
      description: "Voting, community participation, life in the UK, international projects"
    },
    {
      link: {
        text: "Crime, justice and the&nbsp;law",
        path: "http://www.gov.uk"
      },
      description: "Legal processes, courts and the police"
    },
    {
      link: {
        text: "Disabled people",
        path: "http://www.gov.uk"
      },
      description: "Includes carers, your rights, benefits and the Equality Act"
    }
  ]
} %>

Custom heading levels (preview)

Override default heading level by passing through heading_level parameter (defaults to <h2>).

Override default subheading level by passing through sub_heading_level parameter (defaults to <h3>)

Services and information

  • Benefits

    Includes eligibility, appeals, tax credits and Universal Credit

<%= render "govuk_publishing_components/components/cards", {
  heading: "Services and information",
  heading_level: 3,
  sub_heading_level: 4,
  items: [
    {
      link: {
        text: "Benefits",
        path: "http://www.gov.uk"
      },
      description: "Includes eligibility, appeals, tax credits and Universal Credit"
    }
  ]
} %>

With data attributes (preview)

Data attributes can be passed to individual links within the component as shown.

Note that the component does not include built in tracking. If this is required consider using the track click script.

<%= render "govuk_publishing_components/components/cards", {
  items: [
    {
      link: {
        text: "Benefits",
        path: "http://www.gov.uk",
        data_attributes: {
          track_category: "homepageClicked",
          track_action: "track-action",
          track_label: "track-label",
          track_dimension: "track-dimension",
          track_dimension_index: 29,
          track_value: 9
        }
      },
      description: "Includes eligibility, appeals, tax credits and Universal Credit"
    },
    {
      link: {
        text: "Births, deaths, marriages and&nbsp;care",
        path: "http://www.gov.uk",
        data_attributes: {
          track_category: "homepageClicked",
          track_action: "track-action",
          track_label: "track-label",
          track_dimension: "track-dimension",
          track_dimension_index: 29,
          track_value: 9
        }
      },
      description: "Parenting, civil partnerships, divorce and Lasting Power of Attorney"
    }
  ]
} %>