Skip to content
Amplify from Studio 24
  • Get started
  • Layout helpers
  • Fundamentals
  • Core components
  • Advanced components
  • Design handover & standards
  • Colours
  • Typography
  • Buttons and links
  • Lists
  • Icons
  • Breakpoints
  • Vertical spacing
  • Hide and show items inclusively
  • Skip link
  • Images
  • Forms
  • Form error messages
  • Tables
  • Details and summary
  • Utility classes
  • Flow elements
  • Print styles

Tables

Example table

Column header 1 Column header 2 Column header 3
Row 1 header Row 1, cell 2 Row 1, cell 3
Row 2 header Row 2, cell 2 Row 2, cell 3

Considerations

The table markup must include column and/or row headers (th). Some screen readers that encounter a table without headers will treat it as a ‘layout table’ and communicate it quite differently.

Use the attributes scope="col" and scope="row" to differentiate between column and row headers respectively.

Where there are both column and row headers, do not leave the first header cell empty as this can produce unexpected behaviour.

Use a caption to label the table correctly. A heading element can be used within the caption if desired.

Responsive tables

The grid structure of data tables must remain intact, no matter the available space. If there are many columns, the result may be horizontal scrolling. Based on the advice in Adrian Roselli's article Under-Engineered Responsive Tables, the basic table markup then needs to be amended as follows:

  • Wrap the table in a div with the class table-wrap, and the attribute tabindex="0" so that keyboard users can scroll it.

  • Add the following attributes to the wrapping div: tabindex="0" and role="region"

  • Add a unique ID to the caption and add aria-labelledby to the wrapping div with the caption ID as the value. This will correctly label what is now an interactive div.

  • A JavaScript enhancement checks whether the wrapper has any overflow. If there is no overflow, the tabindex, role and aria-labelledby attributes are all removed; but they need to exist in the base markup in case JavaScript is not available.

Members of the Spice Girls
First name Last name Band name Date of birth Place of birth
Emma Bunton Baby 21 January 1976 Watford
Geri Halliwell Ginger 6 August 1972 London
Victoria Beckham Posh 17 April 1974 Harlow
Melanie Brown Scary 29 May 1975 Leeds
Melanie Chisholm Sporty 12 January 1974 Whiston
© Studio 24