Table
Usage
Table caption
All tables must include a caption element that describes the table. Use it in the same way you might use a heading element. A well-written caption adds context to a table and makes it easier to understand.
Table headers
Use table header elements to describe what the data in rows or columns represents. Use the scope
attribute to say whether a header applies to a row or a column. This helps screen reader users.
Mobile behaviour
In general, mobile devices have room for three columns of data. If there is a lot of data in a table it might not display well on small screens. There are two alternative displays you can use, depending on your use case.
Scrolling table
In a scrolling table, the if there are too many columns to display in the content area the first column becomes sticky while the rest of the table is allowed to scroll beneath it. The data in the first column should be indicative of what the data in the column is about. In this example the first column has the name of the item being described in the row of data.
Pros:
- easy to compare data between rows
- the data is still displayed as a table
Cons:
- requires interaction (scroll or swipe) from the user
- not all data is visible at once
Collapse to boxes
In a table that collapses to boxes, the rows of the table become individual blocks of data.
Pros:
- provides an easily-digestable summary of the data
Cons:
- difficult to compare data between rows
- does not look like a table and this non-standard display may be unfamiliar to users
Live example
Public and bank holidays (mygov.scot)
Feedback, help and support
If you need help or support you can e-mail us at designsystem@gov.scot
There is a problem
Thanks for your feedback