Content presentation – Table
Use a table to make it easier for users to scan and compare data or information.
We have 6 kinds of table:
The page also explains how to:
When to use a table
Use a table to:
- present data or information that can be organised in a structured way
- make it easy for users to scan and compare information and understand relationships between data
Aim to present a minimum of data. If you have a lot of data, try to organise it into multiple tables or multiple pages.
When not to use a table
Use tables with caution. They may not be the best way to present information, especially for the public and on mobile screens. In staff services, complex data tables can lead to cognitive overload, a poor user experience and performance issues.
There may be better ways to meet users' needs, for example:
- a plain English summary with headings and lists
- an expander
- tabs
Check this in your user research.
Do not use a table to lay out content on a page. Use the grid system instead.
Basic table
2 column table
Nunjucks macro options
Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.
Some options are required for the macro to work. These are marked as "Required" in the option description. Deprecated options are marked as "Deprecated".
If you're using Nunjucks macros in production with "html" options, or ones ending with "html", you must sanitise the HTML to protect against cross-site scripting exploits.
| Name | Type | Description |
|---|---|---|
| id | string | The ID of the table. |
| border | boolean |
If set to false, remove separating borders from all rows.
|
|
last |
boolean |
If set to false, remove separating border from the last row.
|
| rows | array | Required. Array of table rows and cells. See macro options for rows. |
| head | array | Array of table head cells. See macro options for head. |
| caption | object | Table caption. See macro options for caption. |
|
caption |
string |
Deprecated in 10.6.0 (see GitHub).
Replaced by the caption.classes option.
|
|
caption |
string |
Deprecated in 10.6.0 (see GitHub).
Replaced by the caption.size option.
|
|
first |
boolean |
If set to true, first cell in table row will be a th instead of a td.
|
| compact | boolean |
If set to true, vertical padding will be reduced for table cells.
|
| responsive | boolean |
If set to true, responsive table classes will be applied.
|
| scroll | boolean |
If set to true, wrap a scrolling container around the table component. Scrolling tables require the caption.text and caption.id options.
|
| striped | boolean |
If set to true, striped background colours will be applied to table rows.
|
| variant | string |
Optional variant of table. You can use only "reverse" or empty values with this option.
|
| card | object | Can be used to wrap a card around the table component. If any of these options are present, a card will wrap around the table. See macro options for card. |
| panel | boolean |
Deprecated in 10.3.0 (see GitHub).
Replaced by the card option.
|
|
panel |
string |
Deprecated in 10.3.0 (see GitHub).
Replaced by the card.classes option.
|
| heading | string |
Deprecated in 10.3.0 (see GitHub).
Replaced by the card.heading.text option.
|
|
heading |
integer |
Deprecated in 10.3.0 (see GitHub).
Replaced by the card.heading.level option.
|
| classes | string | Classes to add to the table container. |
|
table |
string |
Deprecated in 10.3.0 (see GitHub).
Replaced by the classes option.
|
| attributes | object | HTML attributes (for example data attributes) to add to the table container. |
|
ascending |
string |
Text for columns in ascending sort order, used to populate the %{direction} placeholder in sortAnnouncementText. Defaults to "ascending".
|
|
descending |
string |
Text for columns in descending sort order, used to populate the %{direction} placeholder in sortAnnouncementText. Defaults to "descending".
|
|
sort |
string |
Announcement made to screen reader users when a table column has been sorted. The component will replace the %{header} placeholder with the column header, and the %{direction} placeholder with the ascendingText or descendingText option value.
|
| Name | Type | Description |
|---|---|---|
| text | string |
Required.
If html is set, this is not required. Text for cells in table rows. If html is provided, the text argument will be ignored.
|
| html | string |
Required.
If text is set, this is not required. HTML for cells in table rows. If html is provided, the text argument will be ignored.
|
|
visually |
string | A visually hidden suffix added to the table cell. |
| header | string |
Deprecated in 10.6.0 (see GitHub).
Set automatically by table head cells in the head option.
|
| href | string | If set, the table cell will become a link. |
| format | string |
Specify format of a cell – "numeric" or "string". Defaults to "string"
|
|
sort |
string | Sort value text for cells in table rows. |
| colspan | integer | Specify how many columns a cell spans. |
| rowspan | integer | Specify how many rows a cell spans. |
| align | string |
Specify the table cell alignment – "left", "centre", or "right". Defaults to "left"
|
| width | string |
Specify the table cell width. You can pass any design system grid width here – for example, "one-third", "two-thirds" or "one-half".
|
| classes | string | Classes to add to the table cell. |
| attributes | object | HTML attributes (for example data attributes) to add to the table cell. |
| Name | Type | Description |
|---|---|---|
| text | string |
If html is set, this is not required. Text for table head cells. If html is provided, the text argument will be ignored.
|
| html | string |
If text is set, this is not required. HTML for table head cells. If html is provided, the text argument will be ignored.
|
|
visually |
string | A visually hidden suffix added to the table head cell. |
| href | string |
If set, the table header will become a link for server-side table sorting. Use sort to set the column sort direction.
|
| format | string |
Specify format of a cell – "numeric" or "string". Defaults to "string"
|
| colspan | integer | Specify how many columns a cell spans. |
| rowspan | integer | Specify how many rows a cell spans. |
| align | string |
Specify the table head cell alignment – "left", "centre", or "right". Defaults to "left"
|
| width | string |
Specify the table head cell width. You can pass any design system grid width here – for example, "one-third", "two-thirds" or "one-half".
|
| classes | string | Classes to add to the table head cell. |
| attributes | object | HTML attributes (for example data attributes) to add to the table head cell. |
| sort | string |
The sort direction applied to the column using aria-sort – "ascending", "descending", "none" or true. To enable sorting without a default direction, set sort to "none" or true.
|
|
sort |
string |
The next sort direction applied to the column using aria-sort when clicked – "ascending" or "descending". Defaults to "ascending". If you set sort to "ascending", sortNext defaults to "descending".
|
| Name | Type | Description |
|---|---|---|
| id | string |
The ID of the table caption and the aria-labelledby attribute in the scrolling container. Defaults to the table id option suffixed with "-caption". If neither are provided, the ID is generated from the caption text option.
|
| text | string |
Required.
If html is set, this is not required. Text for the table caption. If html is provided, the text option will be ignored.
|
| html | string |
Required.
If text is set, this is not required. HTML for the table caption. If html is provided, the text option will be ignored.
|
|
visually |
string |
Message made available to assistive technologies to describe that the table is sortable. Defaults to "Column headers are sortable".
|
| size | string |
Size of the table caption – "s", "m", "l" or "xl".
|
| classes | string |
Classes to add to the table caption, for example "nhsuk-table__caption--l".
|
| attributes | object | HTML attributes (for example data attributes) to add to the table caption. |
3 or more column table
If you have numeric data, right align the column header and cells to make it easier to compare numbers:
- in Nunjucks, add the
format: "numeric"option to the column header - for HTML, add the
nhsuk-table__header--numericclass to the column header andnhsuk-table__cell--numericclass to the cells
If you have non-numeric data that you want to right align:
- in Nunjucks, add the
align: "right"option to the column header - for HTML, add the
nhsuk-u-text-align-rightoverride class to both the column header and cells
Nunjucks macro options
Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.
Some options are required for the macro to work. These are marked as "Required" in the option description. Deprecated options are marked as "Deprecated".
If you're using Nunjucks macros in production with "html" options, or ones ending with "html", you must sanitise the HTML to protect against cross-site scripting exploits.
| Name | Type | Description |
|---|---|---|
| id | string | The ID of the table. |
| border | boolean |
If set to false, remove separating borders from all rows.
|
|
last |
boolean |
If set to false, remove separating border from the last row.
|
| rows | array | Required. Array of table rows and cells. See macro options for rows. |
| head | array | Array of table head cells. See macro options for head. |
| caption | object | Table caption. See macro options for caption. |
|
caption |
string |
Deprecated in 10.6.0 (see GitHub).
Replaced by the caption.classes option.
|
|
caption |
string |
Deprecated in 10.6.0 (see GitHub).
Replaced by the caption.size option.
|
|
first |
boolean |
If set to true, first cell in table row will be a th instead of a td.
|
| compact | boolean |
If set to true, vertical padding will be reduced for table cells.
|
| responsive | boolean |
If set to true, responsive table classes will be applied.
|
| scroll | boolean |
If set to true, wrap a scrolling container around the table component. Scrolling tables require the caption.text and caption.id options.
|
| striped | boolean |
If set to true, striped background colours will be applied to table rows.
|
| variant | string |
Optional variant of table. You can use only "reverse" or empty values with this option.
|
| card | object | Can be used to wrap a card around the table component. If any of these options are present, a card will wrap around the table. See macro options for card. |
| panel | boolean |
Deprecated in 10.3.0 (see GitHub).
Replaced by the card option.
|
|
panel |
string |
Deprecated in 10.3.0 (see GitHub).
Replaced by the card.classes option.
|
| heading | string |
Deprecated in 10.3.0 (see GitHub).
Replaced by the card.heading.text option.
|
|
heading |
integer |
Deprecated in 10.3.0 (see GitHub).
Replaced by the card.heading.level option.
|
| classes | string | Classes to add to the table container. |
|
table |
string |
Deprecated in 10.3.0 (see GitHub).
Replaced by the classes option.
|
| attributes | object | HTML attributes (for example data attributes) to add to the table container. |
|
ascending |
string |
Text for columns in ascending sort order, used to populate the %{direction} placeholder in sortAnnouncementText. Defaults to "ascending".
|
|
descending |
string |
Text for columns in descending sort order, used to populate the %{direction} placeholder in sortAnnouncementText. Defaults to "descending".
|
|
sort |
string |
Announcement made to screen reader users when a table column has been sorted. The component will replace the %{header} placeholder with the column header, and the %{direction} placeholder with the ascendingText or descendingText option value.
|
| Name | Type | Description |
|---|---|---|
| text | string |
Required.
If html is set, this is not required. Text for cells in table rows. If html is provided, the text argument will be ignored.
|
| html | string |
Required.
If text is set, this is not required. HTML for cells in table rows. If html is provided, the text argument will be ignored.
|
|
visually |
string | A visually hidden suffix added to the table cell. |
| header | string |
Deprecated in 10.6.0 (see GitHub).
Set automatically by table head cells in the head option.
|
| href | string | If set, the table cell will become a link. |
| format | string |
Specify format of a cell – "numeric" or "string". Defaults to "string"
|
|
sort |
string | Sort value text for cells in table rows. |
| colspan | integer | Specify how many columns a cell spans. |
| rowspan | integer | Specify how many rows a cell spans. |
| align | string |
Specify the table cell alignment – "left", "centre", or "right". Defaults to "left"
|
| width | string |
Specify the table cell width. You can pass any design system grid width here – for example, "one-third", "two-thirds" or "one-half".
|
| classes | string | Classes to add to the table cell. |
| attributes | object | HTML attributes (for example data attributes) to add to the table cell. |
| Name | Type | Description |
|---|---|---|
| text | string |
If html is set, this is not required. Text for table head cells. If html is provided, the text argument will be ignored.
|
| html | string |
If text is set, this is not required. HTML for table head cells. If html is provided, the text argument will be ignored.
|
|
visually |
string | A visually hidden suffix added to the table head cell. |
| href | string |
If set, the table header will become a link for server-side table sorting. Use sort to set the column sort direction.
|
| format | string |
Specify format of a cell – "numeric" or "string". Defaults to "string"
|
| colspan | integer | Specify how many columns a cell spans. |
| rowspan | integer | Specify how many rows a cell spans. |
| align | string |
Specify the table head cell alignment – "left", "centre", or "right". Defaults to "left"
|
| width | string |
Specify the table head cell width. You can pass any design system grid width here – for example, "one-third", "two-thirds" or "one-half".
|
| classes | string | Classes to add to the table head cell. |
| attributes | object | HTML attributes (for example data attributes) to add to the table head cell. |
| sort | string |
The sort direction applied to the column using aria-sort – "ascending", "descending", "none" or true. To enable sorting without a default direction, set sort to "none" or true.
|
|
sort |
string |
The next sort direction applied to the column using aria-sort when clicked – "ascending" or "descending". Defaults to "ascending". If you set sort to "ascending", sortNext defaults to "descending".
|
| Name | Type | Description |
|---|---|---|
| id | string |
The ID of the table caption and the aria-labelledby attribute in the scrolling container. Defaults to the table id option suffixed with "-caption". If neither are provided, the ID is generated from the caption text option.
|
| text | string |
Required.
If html is set, this is not required. Text for the table caption. If html is provided, the text option will be ignored.
|
| html | string |
Required.
If text is set, this is not required. HTML for the table caption. If html is provided, the text option will be ignored.
|
|
visually |
string |
Message made available to assistive technologies to describe that the table is sortable. Defaults to "Column headers are sortable".
|
| size | string |
Size of the table caption – "s", "m", "l" or "xl".
|
| classes | string |
Classes to add to the table caption, for example "nhsuk-table__caption--l".
|
| attributes | object | HTML attributes (for example data attributes) to add to the table caption. |
When not to use a basic table
Do not use a basic table if your table content becomes squashed and hard to read on small screens. Use a responsive table instead.
Compact table
Use a compact table when you have a lot of data to display. It reduces the vertical padding between rows, making it easier to scan the data.
If you're using Nunjucks, add the compact: true option. For HTML add the nhsuk-table--compact class to the table.
Try first to reduce the amount of data you display, for example by splitting it into multiple tables or combining columns. For example, showing a name and NHS number together in 1 column.
Nunjucks macro options
Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.
Some options are required for the macro to work. These are marked as "Required" in the option description. Deprecated options are marked as "Deprecated".
If you're using Nunjucks macros in production with "html" options, or ones ending with "html", you must sanitise the HTML to protect against cross-site scripting exploits.
| Name | Type | Description |
|---|---|---|
| id | string | The ID of the table. |
| border | boolean |
If set to false, remove separating borders from all rows.
|
|
last |
boolean |
If set to false, remove separating border from the last row.
|
| rows | array | Required. Array of table rows and cells. See macro options for rows. |
| head | array | Array of table head cells. See macro options for head. |
| caption | object | Table caption. See macro options for caption. |
|
caption |
string |
Deprecated in 10.6.0 (see GitHub).
Replaced by the caption.classes option.
|
|
caption |
string |
Deprecated in 10.6.0 (see GitHub).
Replaced by the caption.size option.
|
|
first |
boolean |
If set to true, first cell in table row will be a th instead of a td.
|
| compact | boolean |
If set to true, vertical padding will be reduced for table cells.
|
| responsive | boolean |
If set to true, responsive table classes will be applied.
|
| scroll | boolean |
If set to true, wrap a scrolling container around the table component. Scrolling tables require the caption.text and caption.id options.
|
| striped | boolean |
If set to true, striped background colours will be applied to table rows.
|
| variant | string |
Optional variant of table. You can use only "reverse" or empty values with this option.
|
| card | object | Can be used to wrap a card around the table component. If any of these options are present, a card will wrap around the table. See macro options for card. |
| panel | boolean |
Deprecated in 10.3.0 (see GitHub).
Replaced by the card option.
|
|
panel |
string |
Deprecated in 10.3.0 (see GitHub).
Replaced by the card.classes option.
|
| heading | string |
Deprecated in 10.3.0 (see GitHub).
Replaced by the card.heading.text option.
|
|
heading |
integer |
Deprecated in 10.3.0 (see GitHub).
Replaced by the card.heading.level option.
|
| classes | string | Classes to add to the table container. |
|
table |
string |
Deprecated in 10.3.0 (see GitHub).
Replaced by the classes option.
|
| attributes | object | HTML attributes (for example data attributes) to add to the table container. |
|
ascending |
string |
Text for columns in ascending sort order, used to populate the %{direction} placeholder in sortAnnouncementText. Defaults to "ascending".
|
|
descending |
string |
Text for columns in descending sort order, used to populate the %{direction} placeholder in sortAnnouncementText. Defaults to "descending".
|
|
sort |
string |
Announcement made to screen reader users when a table column has been sorted. The component will replace the %{header} placeholder with the column header, and the %{direction} placeholder with the ascendingText or descendingText option value.
|
| Name | Type | Description |
|---|---|---|
| text | string |
Required.
If html is set, this is not required. Text for cells in table rows. If html is provided, the text argument will be ignored.
|
| html | string |
Required.
If text is set, this is not required. HTML for cells in table rows. If html is provided, the text argument will be ignored.
|
|
visually |
string | A visually hidden suffix added to the table cell. |
| header | string |
Deprecated in 10.6.0 (see GitHub).
Set automatically by table head cells in the head option.
|
| href | string | If set, the table cell will become a link. |
| format | string |
Specify format of a cell – "numeric" or "string". Defaults to "string"
|
|
sort |
string | Sort value text for cells in table rows. |
| colspan | integer | Specify how many columns a cell spans. |
| rowspan | integer | Specify how many rows a cell spans. |
| align | string |
Specify the table cell alignment – "left", "centre", or "right". Defaults to "left"
|
| width | string |
Specify the table cell width. You can pass any design system grid width here – for example, "one-third", "two-thirds" or "one-half".
|
| classes | string | Classes to add to the table cell. |
| attributes | object | HTML attributes (for example data attributes) to add to the table cell. |
| Name | Type | Description |
|---|---|---|
| text | string |
If html is set, this is not required. Text for table head cells. If html is provided, the text argument will be ignored.
|
| html | string |
If text is set, this is not required. HTML for table head cells. If html is provided, the text argument will be ignored.
|
|
visually |
string | A visually hidden suffix added to the table head cell. |
| href | string |
If set, the table header will become a link for server-side table sorting. Use sort to set the column sort direction.
|
| format | string |
Specify format of a cell – "numeric" or "string". Defaults to "string"
|
| colspan | integer | Specify how many columns a cell spans. |
| rowspan | integer | Specify how many rows a cell spans. |
| align | string |
Specify the table head cell alignment – "left", "centre", or "right". Defaults to "left"
|
| width | string |
Specify the table head cell width. You can pass any design system grid width here – for example, "one-third", "two-thirds" or "one-half".
|
| classes | string | Classes to add to the table head cell. |
| attributes | object | HTML attributes (for example data attributes) to add to the table head cell. |
| sort | string |
The sort direction applied to the column using aria-sort – "ascending", "descending", "none" or true. To enable sorting without a default direction, set sort to "none" or true.
|
|
sort |
string |
The next sort direction applied to the column using aria-sort when clicked – "ascending" or "descending". Defaults to "ascending". If you set sort to "ascending", sortNext defaults to "descending".
|
| Name | Type | Description |
|---|---|---|
| id | string |
The ID of the table caption and the aria-labelledby attribute in the scrolling container. Defaults to the table id option suffixed with "-caption". If neither are provided, the ID is generated from the caption text option.
|
| text | string |
Required.
If html is set, this is not required. Text for the table caption. If html is provided, the text option will be ignored.
|
| html | string |
Required.
If text is set, this is not required. HTML for the table caption. If html is provided, the text option will be ignored.
|
|
visually |
string |
Message made available to assistive technologies to describe that the table is sortable. Defaults to "Column headers are sortable".
|
| size | string |
Size of the table caption – "s", "m", "l" or "xl".
|
| classes | string |
Classes to add to the table caption, for example "nhsuk-table__caption--l".
|
| attributes | object | HTML attributes (for example data attributes) to add to the table caption. |
Striped table
Add striping (sometimes called zebra stripes) to tables with many rows and columns of data to help users distinguish between rows.
If you're using Nunjucks, add the striped: true option. For HTML add the nhsuk-table--striped class to the table.
Nunjucks macro options
Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.
Some options are required for the macro to work. These are marked as "Required" in the option description. Deprecated options are marked as "Deprecated".
If you're using Nunjucks macros in production with "html" options, or ones ending with "html", you must sanitise the HTML to protect against cross-site scripting exploits.
| Name | Type | Description |
|---|---|---|
| id | string | The ID of the table. |
| border | boolean |
If set to false, remove separating borders from all rows.
|
|
last |
boolean |
If set to false, remove separating border from the last row.
|
| rows | array | Required. Array of table rows and cells. See macro options for rows. |
| head | array | Array of table head cells. See macro options for head. |
| caption | object | Table caption. See macro options for caption. |
|
caption |
string |
Deprecated in 10.6.0 (see GitHub).
Replaced by the caption.classes option.
|
|
caption |
string |
Deprecated in 10.6.0 (see GitHub).
Replaced by the caption.size option.
|
|
first |
boolean |
If set to true, first cell in table row will be a th instead of a td.
|
| compact | boolean |
If set to true, vertical padding will be reduced for table cells.
|
| responsive | boolean |
If set to true, responsive table classes will be applied.
|
| scroll | boolean |
If set to true, wrap a scrolling container around the table component. Scrolling tables require the caption.text and caption.id options.
|
| striped | boolean |
If set to true, striped background colours will be applied to table rows.
|
| variant | string |
Optional variant of table. You can use only "reverse" or empty values with this option.
|
| card | object | Can be used to wrap a card around the table component. If any of these options are present, a card will wrap around the table. See macro options for card. |
| panel | boolean |
Deprecated in 10.3.0 (see GitHub).
Replaced by the card option.
|
|
panel |
string |
Deprecated in 10.3.0 (see GitHub).
Replaced by the card.classes option.
|
| heading | string |
Deprecated in 10.3.0 (see GitHub).
Replaced by the card.heading.text option.
|
|
heading |
integer |
Deprecated in 10.3.0 (see GitHub).
Replaced by the card.heading.level option.
|
| classes | string | Classes to add to the table container. |
|
table |
string |
Deprecated in 10.3.0 (see GitHub).
Replaced by the classes option.
|
| attributes | object | HTML attributes (for example data attributes) to add to the table container. |
|
ascending |
string |
Text for columns in ascending sort order, used to populate the %{direction} placeholder in sortAnnouncementText. Defaults to "ascending".
|
|
descending |
string |
Text for columns in descending sort order, used to populate the %{direction} placeholder in sortAnnouncementText. Defaults to "descending".
|
|
sort |
string |
Announcement made to screen reader users when a table column has been sorted. The component will replace the %{header} placeholder with the column header, and the %{direction} placeholder with the ascendingText or descendingText option value.
|
| Name | Type | Description |
|---|---|---|
| text | string |
Required.
If html is set, this is not required. Text for cells in table rows. If html is provided, the text argument will be ignored.
|
| html | string |
Required.
If text is set, this is not required. HTML for cells in table rows. If html is provided, the text argument will be ignored.
|
|
visually |
string | A visually hidden suffix added to the table cell. |
| header | string |
Deprecated in 10.6.0 (see GitHub).
Set automatically by table head cells in the head option.
|
| href | string | If set, the table cell will become a link. |
| format | string |
Specify format of a cell – "numeric" or "string". Defaults to "string"
|
|
sort |
string | Sort value text for cells in table rows. |
| colspan | integer | Specify how many columns a cell spans. |
| rowspan | integer | Specify how many rows a cell spans. |
| align | string |
Specify the table cell alignment – "left", "centre", or "right". Defaults to "left"
|
| width | string |
Specify the table cell width. You can pass any design system grid width here – for example, "one-third", "two-thirds" or "one-half".
|
| classes | string | Classes to add to the table cell. |
| attributes | object | HTML attributes (for example data attributes) to add to the table cell. |
| Name | Type | Description |
|---|---|---|
| text | string |
If html is set, this is not required. Text for table head cells. If html is provided, the text argument will be ignored.
|
| html | string |
If text is set, this is not required. HTML for table head cells. If html is provided, the text argument will be ignored.
|
|
visually |
string | A visually hidden suffix added to the table head cell. |
| href | string |
If set, the table header will become a link for server-side table sorting. Use sort to set the column sort direction.
|
| format | string |
Specify format of a cell – "numeric" or "string". Defaults to "string"
|
| colspan | integer | Specify how many columns a cell spans. |
| rowspan | integer | Specify how many rows a cell spans. |
| align | string |
Specify the table head cell alignment – "left", "centre", or "right". Defaults to "left"
|
| width | string |
Specify the table head cell width. You can pass any design system grid width here – for example, "one-third", "two-thirds" or "one-half".
|
| classes | string | Classes to add to the table head cell. |
| attributes | object | HTML attributes (for example data attributes) to add to the table head cell. |
| sort | string |
The sort direction applied to the column using aria-sort – "ascending", "descending", "none" or true. To enable sorting without a default direction, set sort to "none" or true.
|
|
sort |
string |
The next sort direction applied to the column using aria-sort when clicked – "ascending" or "descending". Defaults to "ascending". If you set sort to "ascending", sortNext defaults to "descending".
|
| Name | Type | Description |
|---|---|---|
| id | string |
The ID of the table caption and the aria-labelledby attribute in the scrolling container. Defaults to the table id option suffixed with "-caption". If neither are provided, the ID is generated from the caption text option.
|
| text | string |
Required.
If html is set, this is not required. Text for the table caption. If html is provided, the text option will be ignored.
|
| html | string |
Required.
If text is set, this is not required. HTML for the table caption. If html is provided, the text option will be ignored.
|
|
visually |
string |
Message made available to assistive technologies to describe that the table is sortable. Defaults to "Column headers are sortable".
|
| size | string |
Size of the table caption – "s", "m", "l" or "xl".
|
| classes | string |
Classes to add to the table caption, for example "nhsuk-table__caption--l".
|
| attributes | object | HTML attributes (for example data attributes) to add to the table caption. |
Responsive table
This table has a responsive layout. On large screens it displays horizontally but on small screens it stacks vertically.
Use a responsive table when your table becomes squashed and hard to read on small screens, 768px and smaller.
If you're using Nunjucks, add the responsive: true option. For HTML add the nhsuk-table--responsive class to the table and set the correct role attribute for each element of the table.
Nunjucks macro options
Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.
Some options are required for the macro to work. These are marked as "Required" in the option description. Deprecated options are marked as "Deprecated".
If you're using Nunjucks macros in production with "html" options, or ones ending with "html", you must sanitise the HTML to protect against cross-site scripting exploits.
| Name | Type | Description |
|---|---|---|
| id | string | The ID of the table. |
| border | boolean |
If set to false, remove separating borders from all rows.
|
|
last |
boolean |
If set to false, remove separating border from the last row.
|
| rows | array | Required. Array of table rows and cells. See macro options for rows. |
| head | array | Array of table head cells. See macro options for head. |
| caption | object | Table caption. See macro options for caption. |
|
caption |
string |
Deprecated in 10.6.0 (see GitHub).
Replaced by the caption.classes option.
|
|
caption |
string |
Deprecated in 10.6.0 (see GitHub).
Replaced by the caption.size option.
|
|
first |
boolean |
If set to true, first cell in table row will be a th instead of a td.
|
| compact | boolean |
If set to true, vertical padding will be reduced for table cells.
|
| responsive | boolean |
If set to true, responsive table classes will be applied.
|
| scroll | boolean |
If set to true, wrap a scrolling container around the table component. Scrolling tables require the caption.text and caption.id options.
|
| striped | boolean |
If set to true, striped background colours will be applied to table rows.
|
| variant | string |
Optional variant of table. You can use only "reverse" or empty values with this option.
|
| card | object | Can be used to wrap a card around the table component. If any of these options are present, a card will wrap around the table. See macro options for card. |
| panel | boolean |
Deprecated in 10.3.0 (see GitHub).
Replaced by the card option.
|
|
panel |
string |
Deprecated in 10.3.0 (see GitHub).
Replaced by the card.classes option.
|
| heading | string |
Deprecated in 10.3.0 (see GitHub).
Replaced by the card.heading.text option.
|
|
heading |
integer |
Deprecated in 10.3.0 (see GitHub).
Replaced by the card.heading.level option.
|
| classes | string | Classes to add to the table container. |
|
table |
string |
Deprecated in 10.3.0 (see GitHub).
Replaced by the classes option.
|
| attributes | object | HTML attributes (for example data attributes) to add to the table container. |
|
ascending |
string |
Text for columns in ascending sort order, used to populate the %{direction} placeholder in sortAnnouncementText. Defaults to "ascending".
|
|
descending |
string |
Text for columns in descending sort order, used to populate the %{direction} placeholder in sortAnnouncementText. Defaults to "descending".
|
|
sort |
string |
Announcement made to screen reader users when a table column has been sorted. The component will replace the %{header} placeholder with the column header, and the %{direction} placeholder with the ascendingText or descendingText option value.
|
| Name | Type | Description |
|---|---|---|
| text | string |
Required.
If html is set, this is not required. Text for cells in table rows. If html is provided, the text argument will be ignored.
|
| html | string |
Required.
If text is set, this is not required. HTML for cells in table rows. If html is provided, the text argument will be ignored.
|
|
visually |
string | A visually hidden suffix added to the table cell. |
| header | string |
Deprecated in 10.6.0 (see GitHub).
Set automatically by table head cells in the head option.
|
| href | string | If set, the table cell will become a link. |
| format | string |
Specify format of a cell – "numeric" or "string". Defaults to "string"
|
|
sort |
string | Sort value text for cells in table rows. |
| colspan | integer | Specify how many columns a cell spans. |
| rowspan | integer | Specify how many rows a cell spans. |
| align | string |
Specify the table cell alignment – "left", "centre", or "right". Defaults to "left"
|
| width | string |
Specify the table cell width. You can pass any design system grid width here – for example, "one-third", "two-thirds" or "one-half".
|
| classes | string | Classes to add to the table cell. |
| attributes | object | HTML attributes (for example data attributes) to add to the table cell. |
| Name | Type | Description |
|---|---|---|
| text | string |
If html is set, this is not required. Text for table head cells. If html is provided, the text argument will be ignored.
|
| html | string |
If text is set, this is not required. HTML for table head cells. If html is provided, the text argument will be ignored.
|
|
visually |
string | A visually hidden suffix added to the table head cell. |
| href | string |
If set, the table header will become a link for server-side table sorting. Use sort to set the column sort direction.
|
| format | string |
Specify format of a cell – "numeric" or "string". Defaults to "string"
|
| colspan | integer | Specify how many columns a cell spans. |
| rowspan | integer | Specify how many rows a cell spans. |
| align | string |
Specify the table head cell alignment – "left", "centre", or "right". Defaults to "left"
|
| width | string |
Specify the table head cell width. You can pass any design system grid width here – for example, "one-third", "two-thirds" or "one-half".
|
| classes | string | Classes to add to the table head cell. |
| attributes | object | HTML attributes (for example data attributes) to add to the table head cell. |
| sort | string |
The sort direction applied to the column using aria-sort – "ascending", "descending", "none" or true. To enable sorting without a default direction, set sort to "none" or true.
|
|
sort |
string |
The next sort direction applied to the column using aria-sort when clicked – "ascending" or "descending". Defaults to "ascending". If you set sort to "ascending", sortNext defaults to "descending".
|
| Name | Type | Description |
|---|---|---|
| id | string |
The ID of the table caption and the aria-labelledby attribute in the scrolling container. Defaults to the table id option suffixed with "-caption". If neither are provided, the ID is generated from the caption text option.
|
| text | string |
Required.
If html is set, this is not required. Text for the table caption. If html is provided, the text option will be ignored.
|
| html | string |
Required.
If text is set, this is not required. HTML for the table caption. If html is provided, the text option will be ignored.
|
|
visually |
string |
Message made available to assistive technologies to describe that the table is sortable. Defaults to "Column headers are sortable".
|
| size | string |
Size of the table caption – "s", "m", "l" or "xl".
|
| classes | string |
Classes to add to the table caption, for example "nhsuk-table__caption--l".
|
| attributes | object | HTML attributes (for example data attributes) to add to the table caption. |
When not to use a responsive table
Do not use a responsive table if your content is easier to read and understand on a small screen in a non-stacked layout. Use a basic table instead. If you have too many columns to fit, use a scrolling table.
Scrolling table
Add the scrolling container when your table has many columns and you cannot split it up or use a responsive table.
If you're using Nunjucks, add the scroll: true option. For HTML add the scrolling container from the example below.
Nunjucks macro options
Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.
Some options are required for the macro to work. These are marked as "Required" in the option description. Deprecated options are marked as "Deprecated".
If you're using Nunjucks macros in production with "html" options, or ones ending with "html", you must sanitise the HTML to protect against cross-site scripting exploits.
| Name | Type | Description |
|---|---|---|
| id | string | The ID of the table. |
| border | boolean |
If set to false, remove separating borders from all rows.
|
|
last |
boolean |
If set to false, remove separating border from the last row.
|
| rows | array | Required. Array of table rows and cells. See macro options for rows. |
| head | array | Array of table head cells. See macro options for head. |
| caption | object | Table caption. See macro options for caption. |
|
caption |
string |
Deprecated in 10.6.0 (see GitHub).
Replaced by the caption.classes option.
|
|
caption |
string |
Deprecated in 10.6.0 (see GitHub).
Replaced by the caption.size option.
|
|
first |
boolean |
If set to true, first cell in table row will be a th instead of a td.
|
| compact | boolean |
If set to true, vertical padding will be reduced for table cells.
|
| responsive | boolean |
If set to true, responsive table classes will be applied.
|
| scroll | boolean |
If set to true, wrap a scrolling container around the table component. Scrolling tables require the caption.text and caption.id options.
|
| striped | boolean |
If set to true, striped background colours will be applied to table rows.
|
| variant | string |
Optional variant of table. You can use only "reverse" or empty values with this option.
|
| card | object | Can be used to wrap a card around the table component. If any of these options are present, a card will wrap around the table. See macro options for card. |
| panel | boolean |
Deprecated in 10.3.0 (see GitHub).
Replaced by the card option.
|
|
panel |
string |
Deprecated in 10.3.0 (see GitHub).
Replaced by the card.classes option.
|
| heading | string |
Deprecated in 10.3.0 (see GitHub).
Replaced by the card.heading.text option.
|
|
heading |
integer |
Deprecated in 10.3.0 (see GitHub).
Replaced by the card.heading.level option.
|
| classes | string | Classes to add to the table container. |
|
table |
string |
Deprecated in 10.3.0 (see GitHub).
Replaced by the classes option.
|
| attributes | object | HTML attributes (for example data attributes) to add to the table container. |
|
ascending |
string |
Text for columns in ascending sort order, used to populate the %{direction} placeholder in sortAnnouncementText. Defaults to "ascending".
|
|
descending |
string |
Text for columns in descending sort order, used to populate the %{direction} placeholder in sortAnnouncementText. Defaults to "descending".
|
|
sort |
string |
Announcement made to screen reader users when a table column has been sorted. The component will replace the %{header} placeholder with the column header, and the %{direction} placeholder with the ascendingText or descendingText option value.
|
| Name | Type | Description |
|---|---|---|
| text | string |
Required.
If html is set, this is not required. Text for cells in table rows. If html is provided, the text argument will be ignored.
|
| html | string |
Required.
If text is set, this is not required. HTML for cells in table rows. If html is provided, the text argument will be ignored.
|
|
visually |
string | A visually hidden suffix added to the table cell. |
| header | string |
Deprecated in 10.6.0 (see GitHub).
Set automatically by table head cells in the head option.
|
| href | string | If set, the table cell will become a link. |
| format | string |
Specify format of a cell – "numeric" or "string". Defaults to "string"
|
|
sort |
string | Sort value text for cells in table rows. |
| colspan | integer | Specify how many columns a cell spans. |
| rowspan | integer | Specify how many rows a cell spans. |
| align | string |
Specify the table cell alignment – "left", "centre", or "right". Defaults to "left"
|
| width | string |
Specify the table cell width. You can pass any design system grid width here – for example, "one-third", "two-thirds" or "one-half".
|
| classes | string | Classes to add to the table cell. |
| attributes | object | HTML attributes (for example data attributes) to add to the table cell. |
| Name | Type | Description |
|---|---|---|
| text | string |
If html is set, this is not required. Text for table head cells. If html is provided, the text argument will be ignored.
|
| html | string |
If text is set, this is not required. HTML for table head cells. If html is provided, the text argument will be ignored.
|
|
visually |
string | A visually hidden suffix added to the table head cell. |
| href | string |
If set, the table header will become a link for server-side table sorting. Use sort to set the column sort direction.
|
| format | string |
Specify format of a cell – "numeric" or "string". Defaults to "string"
|
| colspan | integer | Specify how many columns a cell spans. |
| rowspan | integer | Specify how many rows a cell spans. |
| align | string |
Specify the table head cell alignment – "left", "centre", or "right". Defaults to "left"
|
| width | string |
Specify the table head cell width. You can pass any design system grid width here – for example, "one-third", "two-thirds" or "one-half".
|
| classes | string | Classes to add to the table head cell. |
| attributes | object | HTML attributes (for example data attributes) to add to the table head cell. |
| sort | string |
The sort direction applied to the column using aria-sort – "ascending", "descending", "none" or true. To enable sorting without a default direction, set sort to "none" or true.
|
|
sort |
string |
The next sort direction applied to the column using aria-sort when clicked – "ascending" or "descending". Defaults to "ascending". If you set sort to "ascending", sortNext defaults to "descending".
|
| Name | Type | Description |
|---|---|---|
| id | string |
The ID of the table caption and the aria-labelledby attribute in the scrolling container. Defaults to the table id option suffixed with "-caption". If neither are provided, the ID is generated from the caption text option.
|
| text | string |
Required.
If html is set, this is not required. Text for the table caption. If html is provided, the text option will be ignored.
|
| html | string |
Required.
If text is set, this is not required. HTML for the table caption. If html is provided, the text option will be ignored.
|
|
visually |
string |
Message made available to assistive technologies to describe that the table is sortable. Defaults to "Column headers are sortable".
|
| size | string |
Size of the table caption – "s", "m", "l" or "xl".
|
| classes | string |
Classes to add to the table caption, for example "nhsuk-table__caption--l".
|
| attributes | object | HTML attributes (for example data attributes) to add to the table caption. |
The example uses an nhsuk-scroll container to automatically toggle left or right shadows when scrolling.
<div class="nhsuk-scroll" data-module="nhsuk-scroll">
<div class="nhsuk-scroll__content" role="region" aria-labelledby="table-caption-id">
Sortable table
A sortable table lets users sort columns in ascending or descending order, alphabetically or numerically.
Ascending order (up arrow) arranges:
- numerical data from the lowest to the highest value
- text in alphabetical order A to Z
Descending order (down arrow) reverses this.
This table only sorts by 1 column at a time. Sortable columns show a double arrow until they're sorted. When users click in the column header of an unsorted column, it sorts and shows a single arrow. Clicking again toggles between ascending and descending.
Nunjucks macro options
Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.
Some options are required for the macro to work. These are marked as "Required" in the option description. Deprecated options are marked as "Deprecated".
If you're using Nunjucks macros in production with "html" options, or ones ending with "html", you must sanitise the HTML to protect against cross-site scripting exploits.
| Name | Type | Description |
|---|---|---|
| id | string | The ID of the table. |
| border | boolean |
If set to false, remove separating borders from all rows.
|
|
last |
boolean |
If set to false, remove separating border from the last row.
|
| rows | array | Required. Array of table rows and cells. See macro options for rows. |
| head | array | Array of table head cells. See macro options for head. |
| caption | object | Table caption. See macro options for caption. |
|
caption |
string |
Deprecated in 10.6.0 (see GitHub).
Replaced by the caption.classes option.
|
|
caption |
string |
Deprecated in 10.6.0 (see GitHub).
Replaced by the caption.size option.
|
|
first |
boolean |
If set to true, first cell in table row will be a th instead of a td.
|
| compact | boolean |
If set to true, vertical padding will be reduced for table cells.
|
| responsive | boolean |
If set to true, responsive table classes will be applied.
|
| scroll | boolean |
If set to true, wrap a scrolling container around the table component. Scrolling tables require the caption.text and caption.id options.
|
| striped | boolean |
If set to true, striped background colours will be applied to table rows.
|
| variant | string |
Optional variant of table. You can use only "reverse" or empty values with this option.
|
| card | object | Can be used to wrap a card around the table component. If any of these options are present, a card will wrap around the table. See macro options for card. |
| panel | boolean |
Deprecated in 10.3.0 (see GitHub).
Replaced by the card option.
|
|
panel |
string |
Deprecated in 10.3.0 (see GitHub).
Replaced by the card.classes option.
|
| heading | string |
Deprecated in 10.3.0 (see GitHub).
Replaced by the card.heading.text option.
|
|
heading |
integer |
Deprecated in 10.3.0 (see GitHub).
Replaced by the card.heading.level option.
|
| classes | string | Classes to add to the table container. |
|
table |
string |
Deprecated in 10.3.0 (see GitHub).
Replaced by the classes option.
|
| attributes | object | HTML attributes (for example data attributes) to add to the table container. |
|
ascending |
string |
Text for columns in ascending sort order, used to populate the %{direction} placeholder in sortAnnouncementText. Defaults to "ascending".
|
|
descending |
string |
Text for columns in descending sort order, used to populate the %{direction} placeholder in sortAnnouncementText. Defaults to "descending".
|
|
sort |
string |
Announcement made to screen reader users when a table column has been sorted. The component will replace the %{header} placeholder with the column header, and the %{direction} placeholder with the ascendingText or descendingText option value.
|
| Name | Type | Description |
|---|---|---|
| text | string |
Required.
If html is set, this is not required. Text for cells in table rows. If html is provided, the text argument will be ignored.
|
| html | string |
Required.
If text is set, this is not required. HTML for cells in table rows. If html is provided, the text argument will be ignored.
|
|
visually |
string | A visually hidden suffix added to the table cell. |
| header | string |
Deprecated in 10.6.0 (see GitHub).
Set automatically by table head cells in the head option.
|
| href | string | If set, the table cell will become a link. |
| format | string |
Specify format of a cell – "numeric" or "string". Defaults to "string"
|
|
sort |
string | Sort value text for cells in table rows. |
| colspan | integer | Specify how many columns a cell spans. |
| rowspan | integer | Specify how many rows a cell spans. |
| align | string |
Specify the table cell alignment – "left", "centre", or "right". Defaults to "left"
|
| width | string |
Specify the table cell width. You can pass any design system grid width here – for example, "one-third", "two-thirds" or "one-half".
|
| classes | string | Classes to add to the table cell. |
| attributes | object | HTML attributes (for example data attributes) to add to the table cell. |
| Name | Type | Description |
|---|---|---|
| text | string |
If html is set, this is not required. Text for table head cells. If html is provided, the text argument will be ignored.
|
| html | string |
If text is set, this is not required. HTML for table head cells. If html is provided, the text argument will be ignored.
|
|
visually |
string | A visually hidden suffix added to the table head cell. |
| href | string |
If set, the table header will become a link for server-side table sorting. Use sort to set the column sort direction.
|
| format | string |
Specify format of a cell – "numeric" or "string". Defaults to "string"
|
| colspan | integer | Specify how many columns a cell spans. |
| rowspan | integer | Specify how many rows a cell spans. |
| align | string |
Specify the table head cell alignment – "left", "centre", or "right". Defaults to "left"
|
| width | string |
Specify the table head cell width. You can pass any design system grid width here – for example, "one-third", "two-thirds" or "one-half".
|
| classes | string | Classes to add to the table head cell. |
| attributes | object | HTML attributes (for example data attributes) to add to the table head cell. |
| sort | string |
The sort direction applied to the column using aria-sort – "ascending", "descending", "none" or true. To enable sorting without a default direction, set sort to "none" or true.
|
|
sort |
string |
The next sort direction applied to the column using aria-sort when clicked – "ascending" or "descending". Defaults to "ascending". If you set sort to "ascending", sortNext defaults to "descending".
|
| Name | Type | Description |
|---|---|---|
| id | string |
The ID of the table caption and the aria-labelledby attribute in the scrolling container. Defaults to the table id option suffixed with "-caption". If neither are provided, the ID is generated from the caption text option.
|
| text | string |
Required.
If html is set, this is not required. Text for the table caption. If html is provided, the text option will be ignored.
|
| html | string |
Required.
If text is set, this is not required. HTML for the table caption. If html is provided, the text option will be ignored.
|
|
visually |
string |
Message made available to assistive technologies to describe that the table is sortable. Defaults to "Column headers are sortable".
|
| size | string |
Size of the table caption – "s", "m", "l" or "xl".
|
| classes | string |
Classes to add to the table caption, for example "nhsuk-table__caption--l".
|
| attributes | object | HTML attributes (for example data attributes) to add to the table caption. |
When to use a sortable table
Use this table when users need to analyse and prioritise data.
How to use a sortable table
Carry out user research to understand what your users need to do with the data and if a sortable table is the best way to meet their needs.
There are 2 ways to sort a table. You can:
- sort data that fits on 1 page
- sort more than 1 page of data
Sort data on 1 page
The sortable table component uses JavaScript to sort the data in the user's browser. Use it where you have only 1 page of data. Make sure your data has a suitable sort order if JavaScript does not run.
Sorting columns
By default when you click on the column header for an unsorted column, it will sort that column in ascending order. To apply descending order when clicked:
- in Nunjucks, add the
sortNext: "descending"option to the column header - for HTML, add the
data-sort-next="descending"attribute to the column header
Typically users expect text to sort A to Z by default. With numbers, they often expect them to sort with the biggest number first.
Do not allow sorting on columns that cannot be meaningfully ordered, for example comments from users.
Do not add code to automatically save the sort order. Users may not expect this and it could add clinical risk.
A page refresh or navigation must return the page to its default sort order, unless you add functionality to allow users to save their sort order explicitly.
Sorting numbers
By default, columns will be sorted as text. To correctly order columns containing numbers:
- in Nunjucks, add the
format: "numeric"option to the column header - for HTML, add the
nhsuk-table__header--numericclass to the column header andnhsuk-table__cell--numericclass to the cells
Columns set to numeric will work correctly with most number symbols, including commas, decimals, percentages and currencies.
Use numeric for dates.
Overriding the default sort order
You can override the default sort value to make the presented data easier for users to understand.
For example:
- dates: 30 November 2026 sorted as
2026-11-30 - months: January sorted as
01 January - prefixes: The Whittington Hospital sorted as
Whittington Hospital
To override the default sort value:
- in Nunjucks, add the
sortValueoption to the table cell - for HTML, add the
data-sort-valueattribute to the table cell
Make sure to override the sort value for missing data. For example, setting sortValue: "£0" will sort the text "No data" consistently with other cells.
In this example the default sort order is by amount spent (descending).
Nunjucks macro options
Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.
Some options are required for the macro to work. These are marked as "Required" in the option description. Deprecated options are marked as "Deprecated".
If you're using Nunjucks macros in production with "html" options, or ones ending with "html", you must sanitise the HTML to protect against cross-site scripting exploits.
| Name | Type | Description |
|---|---|---|
| id | string | The ID of the table. |
| border | boolean |
If set to false, remove separating borders from all rows.
|
|
last |
boolean |
If set to false, remove separating border from the last row.
|
| rows | array | Required. Array of table rows and cells. See macro options for rows. |
| head | array | Array of table head cells. See macro options for head. |
| caption | object | Table caption. See macro options for caption. |
|
caption |
string |
Deprecated in 10.6.0 (see GitHub).
Replaced by the caption.classes option.
|
|
caption |
string |
Deprecated in 10.6.0 (see GitHub).
Replaced by the caption.size option.
|
|
first |
boolean |
If set to true, first cell in table row will be a th instead of a td.
|
| compact | boolean |
If set to true, vertical padding will be reduced for table cells.
|
| responsive | boolean |
If set to true, responsive table classes will be applied.
|
| scroll | boolean |
If set to true, wrap a scrolling container around the table component. Scrolling tables require the caption.text and caption.id options.
|
| striped | boolean |
If set to true, striped background colours will be applied to table rows.
|
| variant | string |
Optional variant of table. You can use only "reverse" or empty values with this option.
|
| card | object | Can be used to wrap a card around the table component. If any of these options are present, a card will wrap around the table. See macro options for card. |
| panel | boolean |
Deprecated in 10.3.0 (see GitHub).
Replaced by the card option.
|
|
panel |
string |
Deprecated in 10.3.0 (see GitHub).
Replaced by the card.classes option.
|
| heading | string |
Deprecated in 10.3.0 (see GitHub).
Replaced by the card.heading.text option.
|
|
heading |
integer |
Deprecated in 10.3.0 (see GitHub).
Replaced by the card.heading.level option.
|
| classes | string | Classes to add to the table container. |
|
table |
string |
Deprecated in 10.3.0 (see GitHub).
Replaced by the classes option.
|
| attributes | object | HTML attributes (for example data attributes) to add to the table container. |
|
ascending |
string |
Text for columns in ascending sort order, used to populate the %{direction} placeholder in sortAnnouncementText. Defaults to "ascending".
|
|
descending |
string |
Text for columns in descending sort order, used to populate the %{direction} placeholder in sortAnnouncementText. Defaults to "descending".
|
|
sort |
string |
Announcement made to screen reader users when a table column has been sorted. The component will replace the %{header} placeholder with the column header, and the %{direction} placeholder with the ascendingText or descendingText option value.
|
| Name | Type | Description |
|---|---|---|
| text | string |
Required.
If html is set, this is not required. Text for cells in table rows. If html is provided, the text argument will be ignored.
|
| html | string |
Required.
If text is set, this is not required. HTML for cells in table rows. If html is provided, the text argument will be ignored.
|
|
visually |
string | A visually hidden suffix added to the table cell. |
| header | string |
Deprecated in 10.6.0 (see GitHub).
Set automatically by table head cells in the head option.
|
| href | string | If set, the table cell will become a link. |
| format | string |
Specify format of a cell – "numeric" or "string". Defaults to "string"
|
|
sort |
string | Sort value text for cells in table rows. |
| colspan | integer | Specify how many columns a cell spans. |
| rowspan | integer | Specify how many rows a cell spans. |
| align | string |
Specify the table cell alignment – "left", "centre", or "right". Defaults to "left"
|
| width | string |
Specify the table cell width. You can pass any design system grid width here – for example, "one-third", "two-thirds" or "one-half".
|
| classes | string | Classes to add to the table cell. |
| attributes | object | HTML attributes (for example data attributes) to add to the table cell. |
| Name | Type | Description |
|---|---|---|
| text | string |
If html is set, this is not required. Text for table head cells. If html is provided, the text argument will be ignored.
|
| html | string |
If text is set, this is not required. HTML for table head cells. If html is provided, the text argument will be ignored.
|
|
visually |
string | A visually hidden suffix added to the table head cell. |
| href | string |
If set, the table header will become a link for server-side table sorting. Use sort to set the column sort direction.
|
| format | string |
Specify format of a cell – "numeric" or "string". Defaults to "string"
|
| colspan | integer | Specify how many columns a cell spans. |
| rowspan | integer | Specify how many rows a cell spans. |
| align | string |
Specify the table head cell alignment – "left", "centre", or "right". Defaults to "left"
|
| width | string |
Specify the table head cell width. You can pass any design system grid width here – for example, "one-third", "two-thirds" or "one-half".
|
| classes | string | Classes to add to the table head cell. |
| attributes | object | HTML attributes (for example data attributes) to add to the table head cell. |
| sort | string |
The sort direction applied to the column using aria-sort – "ascending", "descending", "none" or true. To enable sorting without a default direction, set sort to "none" or true.
|
|
sort |
string |
The next sort direction applied to the column using aria-sort when clicked – "ascending" or "descending". Defaults to "ascending". If you set sort to "ascending", sortNext defaults to "descending".
|
| Name | Type | Description |
|---|---|---|
| id | string |
The ID of the table caption and the aria-labelledby attribute in the scrolling container. Defaults to the table id option suffixed with "-caption". If neither are provided, the ID is generated from the caption text option.
|
| text | string |
Required.
If html is set, this is not required. Text for the table caption. If html is provided, the text option will be ignored.
|
| html | string |
Required.
If text is set, this is not required. HTML for the table caption. If html is provided, the text option will be ignored.
|
|
visually |
string |
Message made available to assistive technologies to describe that the table is sortable. Defaults to "Column headers are sortable".
|
| size | string |
Size of the table caption – "s", "m", "l" or "xl".
|
| classes | string |
Classes to add to the table caption, for example "nhsuk-table__caption--l".
|
| attributes | object | HTML attributes (for example data attributes) to add to the table caption. |
Sort more than 1 page of data
If your table is paginated, sorting should be applied server-side across all pages. Do not sort the current page only.
Use server-side sorting by adding a link to the column header to navigate to a page with the table sorting already applied. You will need to:
- build your own server-side function
- return users to the first page of new results after sorting
- test with users
This example shows a paginated table but it does not work in the browser. The functionality would need to be built server-side.
- HTML code for table sortable server side last login descending
- Nunjucks code for table sortable server side last login descending
Nunjucks macro options
Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.
Some options are required for the macro to work. These are marked as "Required" in the option description. Deprecated options are marked as "Deprecated".
If you're using Nunjucks macros in production with "html" options, or ones ending with "html", you must sanitise the HTML to protect against cross-site scripting exploits.
| Name | Type | Description |
|---|---|---|
| id | string | The ID of the table. |
| border | boolean |
If set to false, remove separating borders from all rows.
|
|
last |
boolean |
If set to false, remove separating border from the last row.
|
| rows | array | Required. Array of table rows and cells. See macro options for rows. |
| head | array | Array of table head cells. See macro options for head. |
| caption | object | Table caption. See macro options for caption. |
|
caption |
string |
Deprecated in 10.6.0 (see GitHub).
Replaced by the caption.classes option.
|
|
caption |
string |
Deprecated in 10.6.0 (see GitHub).
Replaced by the caption.size option.
|
|
first |
boolean |
If set to true, first cell in table row will be a th instead of a td.
|
| compact | boolean |
If set to true, vertical padding will be reduced for table cells.
|
| responsive | boolean |
If set to true, responsive table classes will be applied.
|
| scroll | boolean |
If set to true, wrap a scrolling container around the table component. Scrolling tables require the caption.text and caption.id options.
|
| striped | boolean |
If set to true, striped background colours will be applied to table rows.
|
| variant | string |
Optional variant of table. You can use only "reverse" or empty values with this option.
|
| card | object | Can be used to wrap a card around the table component. If any of these options are present, a card will wrap around the table. See macro options for card. |
| panel | boolean |
Deprecated in 10.3.0 (see GitHub).
Replaced by the card option.
|
|
panel |
string |
Deprecated in 10.3.0 (see GitHub).
Replaced by the card.classes option.
|
| heading | string |
Deprecated in 10.3.0 (see GitHub).
Replaced by the card.heading.text option.
|
|
heading |
integer |
Deprecated in 10.3.0 (see GitHub).
Replaced by the card.heading.level option.
|
| classes | string | Classes to add to the table container. |
|
table |
string |
Deprecated in 10.3.0 (see GitHub).
Replaced by the classes option.
|
| attributes | object | HTML attributes (for example data attributes) to add to the table container. |
|
ascending |
string |
Text for columns in ascending sort order, used to populate the %{direction} placeholder in sortAnnouncementText. Defaults to "ascending".
|
|
descending |
string |
Text for columns in descending sort order, used to populate the %{direction} placeholder in sortAnnouncementText. Defaults to "descending".
|
|
sort |
string |
Announcement made to screen reader users when a table column has been sorted. The component will replace the %{header} placeholder with the column header, and the %{direction} placeholder with the ascendingText or descendingText option value.
|
| Name | Type | Description |
|---|---|---|
| text | string |
Required.
If html is set, this is not required. Text for cells in table rows. If html is provided, the text argument will be ignored.
|
| html | string |
Required.
If text is set, this is not required. HTML for cells in table rows. If html is provided, the text argument will be ignored.
|
|
visually |
string | A visually hidden suffix added to the table cell. |
| header | string |
Deprecated in 10.6.0 (see GitHub).
Set automatically by table head cells in the head option.
|
| href | string | If set, the table cell will become a link. |
| format | string |
Specify format of a cell – "numeric" or "string". Defaults to "string"
|
|
sort |
string | Sort value text for cells in table rows. |
| colspan | integer | Specify how many columns a cell spans. |
| rowspan | integer | Specify how many rows a cell spans. |
| align | string |
Specify the table cell alignment – "left", "centre", or "right". Defaults to "left"
|
| width | string |
Specify the table cell width. You can pass any design system grid width here – for example, "one-third", "two-thirds" or "one-half".
|
| classes | string | Classes to add to the table cell. |
| attributes | object | HTML attributes (for example data attributes) to add to the table cell. |
| Name | Type | Description |
|---|---|---|
| text | string |
If html is set, this is not required. Text for table head cells. If html is provided, the text argument will be ignored.
|
| html | string |
If text is set, this is not required. HTML for table head cells. If html is provided, the text argument will be ignored.
|
|
visually |
string | A visually hidden suffix added to the table head cell. |
| href | string |
If set, the table header will become a link for server-side table sorting. Use sort to set the column sort direction.
|
| format | string |
Specify format of a cell – "numeric" or "string". Defaults to "string"
|
| colspan | integer | Specify how many columns a cell spans. |
| rowspan | integer | Specify how many rows a cell spans. |
| align | string |
Specify the table head cell alignment – "left", "centre", or "right". Defaults to "left"
|
| width | string |
Specify the table head cell width. You can pass any design system grid width here – for example, "one-third", "two-thirds" or "one-half".
|
| classes | string | Classes to add to the table head cell. |
| attributes | object | HTML attributes (for example data attributes) to add to the table head cell. |
| sort | string |
The sort direction applied to the column using aria-sort – "ascending", "descending", "none" or true. To enable sorting without a default direction, set sort to "none" or true.
|
|
sort |
string |
The next sort direction applied to the column using aria-sort when clicked – "ascending" or "descending". Defaults to "ascending". If you set sort to "ascending", sortNext defaults to "descending".
|
| Name | Type | Description |
|---|---|---|
| id | string |
The ID of the table caption and the aria-labelledby attribute in the scrolling container. Defaults to the table id option suffixed with "-caption". If neither are provided, the ID is generated from the caption text option.
|
| text | string |
Required.
If html is set, this is not required. Text for the table caption. If html is provided, the text option will be ignored.
|
| html | string |
Required.
If text is set, this is not required. HTML for the table caption. If html is provided, the text option will be ignored.
|
|
visually |
string |
Message made available to assistive technologies to describe that the table is sortable. Defaults to "Column headers are sortable".
|
| size | string |
Size of the table caption – "s", "m", "l" or "xl".
|
| classes | string |
Classes to add to the table caption, for example "nhsuk-table__caption--l".
|
| attributes | object | HTML attributes (for example data attributes) to add to the table caption. |
Consider search and filter
Filters reduce the amount of data so that users can focus on what they want. Search helps them find specific things they need.
For example, search or filter may work better than sorting for:
- names
- NHS numbers or other codes
- medical conditions
If your team is researching filtering, please feed back your findings via our community backlog issue on filtering a list (in GitHub).
Using word-breaks in a table
To avoid very long words, such as email addresses, breaking the layout of a table, you can use word-breaks. To do this:
- in Nunjucks, add the
class: "nhsuk-u-text-break-word"option to the table cell - for HTML, add the
nhsuk-u-text-break-wordoverride class to the table cell
Nunjucks macro options
Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.
Some options are required for the macro to work. These are marked as "Required" in the option description. Deprecated options are marked as "Deprecated".
If you're using Nunjucks macros in production with "html" options, or ones ending with "html", you must sanitise the HTML to protect against cross-site scripting exploits.
| Name | Type | Description |
|---|---|---|
| id | string | The ID of the table. |
| border | boolean |
If set to false, remove separating borders from all rows.
|
|
last |
boolean |
If set to false, remove separating border from the last row.
|
| rows | array | Required. Array of table rows and cells. See macro options for rows. |
| head | array | Array of table head cells. See macro options for head. |
| caption | object | Table caption. See macro options for caption. |
|
caption |
string |
Deprecated in 10.6.0 (see GitHub).
Replaced by the caption.classes option.
|
|
caption |
string |
Deprecated in 10.6.0 (see GitHub).
Replaced by the caption.size option.
|
|
first |
boolean |
If set to true, first cell in table row will be a th instead of a td.
|
| compact | boolean |
If set to true, vertical padding will be reduced for table cells.
|
| responsive | boolean |
If set to true, responsive table classes will be applied.
|
| scroll | boolean |
If set to true, wrap a scrolling container around the table component. Scrolling tables require the caption.text and caption.id options.
|
| striped | boolean |
If set to true, striped background colours will be applied to table rows.
|
| variant | string |
Optional variant of table. You can use only "reverse" or empty values with this option.
|
| card | object | Can be used to wrap a card around the table component. If any of these options are present, a card will wrap around the table. See macro options for card. |
| panel | boolean |
Deprecated in 10.3.0 (see GitHub).
Replaced by the card option.
|
|
panel |
string |
Deprecated in 10.3.0 (see GitHub).
Replaced by the card.classes option.
|
| heading | string |
Deprecated in 10.3.0 (see GitHub).
Replaced by the card.heading.text option.
|
|
heading |
integer |
Deprecated in 10.3.0 (see GitHub).
Replaced by the card.heading.level option.
|
| classes | string | Classes to add to the table container. |
|
table |
string |
Deprecated in 10.3.0 (see GitHub).
Replaced by the classes option.
|
| attributes | object | HTML attributes (for example data attributes) to add to the table container. |
|
ascending |
string |
Text for columns in ascending sort order, used to populate the %{direction} placeholder in sortAnnouncementText. Defaults to "ascending".
|
|
descending |
string |
Text for columns in descending sort order, used to populate the %{direction} placeholder in sortAnnouncementText. Defaults to "descending".
|
|
sort |
string |
Announcement made to screen reader users when a table column has been sorted. The component will replace the %{header} placeholder with the column header, and the %{direction} placeholder with the ascendingText or descendingText option value.
|
| Name | Type | Description |
|---|---|---|
| text | string |
Required.
If html is set, this is not required. Text for cells in table rows. If html is provided, the text argument will be ignored.
|
| html | string |
Required.
If text is set, this is not required. HTML for cells in table rows. If html is provided, the text argument will be ignored.
|
|
visually |
string | A visually hidden suffix added to the table cell. |
| header | string |
Deprecated in 10.6.0 (see GitHub).
Set automatically by table head cells in the head option.
|
| href | string | If set, the table cell will become a link. |
| format | string |
Specify format of a cell – "numeric" or "string". Defaults to "string"
|
|
sort |
string | Sort value text for cells in table rows. |
| colspan | integer | Specify how many columns a cell spans. |
| rowspan | integer | Specify how many rows a cell spans. |
| align | string |
Specify the table cell alignment – "left", "centre", or "right". Defaults to "left"
|
| width | string |
Specify the table cell width. You can pass any design system grid width here – for example, "one-third", "two-thirds" or "one-half".
|
| classes | string | Classes to add to the table cell. |
| attributes | object | HTML attributes (for example data attributes) to add to the table cell. |
| Name | Type | Description |
|---|---|---|
| text | string |
If html is set, this is not required. Text for table head cells. If html is provided, the text argument will be ignored.
|
| html | string |
If text is set, this is not required. HTML for table head cells. If html is provided, the text argument will be ignored.
|
|
visually |
string | A visually hidden suffix added to the table head cell. |
| href | string |
If set, the table header will become a link for server-side table sorting. Use sort to set the column sort direction.
|
| format | string |
Specify format of a cell – "numeric" or "string". Defaults to "string"
|
| colspan | integer | Specify how many columns a cell spans. |
| rowspan | integer | Specify how many rows a cell spans. |
| align | string |
Specify the table head cell alignment – "left", "centre", or "right". Defaults to "left"
|
| width | string |
Specify the table head cell width. You can pass any design system grid width here – for example, "one-third", "two-thirds" or "one-half".
|
| classes | string | Classes to add to the table head cell. |
| attributes | object | HTML attributes (for example data attributes) to add to the table head cell. |
| sort | string |
The sort direction applied to the column using aria-sort – "ascending", "descending", "none" or true. To enable sorting without a default direction, set sort to "none" or true.
|
|
sort |
string |
The next sort direction applied to the column using aria-sort when clicked – "ascending" or "descending". Defaults to "ascending". If you set sort to "ascending", sortNext defaults to "descending".
|
| Name | Type | Description |
|---|---|---|
| id | string |
The ID of the table caption and the aria-labelledby attribute in the scrolling container. Defaults to the table id option suffixed with "-caption". If neither are provided, the ID is generated from the caption text option.
|
| text | string |
Required.
If html is set, this is not required. Text for the table caption. If html is provided, the text option will be ignored.
|
| html | string |
Required.
If text is set, this is not required. HTML for the table caption. If html is provided, the text option will be ignored.
|
|
visually |
string |
Message made available to assistive technologies to describe that the table is sortable. Defaults to "Column headers are sortable".
|
| size | string |
Size of the table caption – "s", "m", "l" or "xl".
|
| classes | string |
Classes to add to the table caption, for example "nhsuk-table__caption--l".
|
| attributes | object | HTML attributes (for example data attributes) to add to the table caption. |
Find out more about word-breaks, with or without a hyphen, in breaking up long words in the typography section.
Displaying missing data
Do not leave empty cells in your table. The only exception can be the top left cell. If you have missing data, include some short text to explain why it's missing, such as:
- "No data"
- "Not applicable"
- "Not known"
To distinguish missing data from other table content, make the text dark grey by adding the class: "nhsuk-u-secondary-text-colour" Nunjucks option to the table cell. For HTML set it via the class attribute.
Nunjucks macro options
Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.
Some options are required for the macro to work. These are marked as "Required" in the option description. Deprecated options are marked as "Deprecated".
If you're using Nunjucks macros in production with "html" options, or ones ending with "html", you must sanitise the HTML to protect against cross-site scripting exploits.
| Name | Type | Description |
|---|---|---|
| id | string | The ID of the table. |
| border | boolean |
If set to false, remove separating borders from all rows.
|
|
last |
boolean |
If set to false, remove separating border from the last row.
|
| rows | array | Required. Array of table rows and cells. See macro options for rows. |
| head | array | Array of table head cells. See macro options for head. |
| caption | object | Table caption. See macro options for caption. |
|
caption |
string |
Deprecated in 10.6.0 (see GitHub).
Replaced by the caption.classes option.
|
|
caption |
string |
Deprecated in 10.6.0 (see GitHub).
Replaced by the caption.size option.
|
|
first |
boolean |
If set to true, first cell in table row will be a th instead of a td.
|
| compact | boolean |
If set to true, vertical padding will be reduced for table cells.
|
| responsive | boolean |
If set to true, responsive table classes will be applied.
|
| scroll | boolean |
If set to true, wrap a scrolling container around the table component. Scrolling tables require the caption.text and caption.id options.
|
| striped | boolean |
If set to true, striped background colours will be applied to table rows.
|
| variant | string |
Optional variant of table. You can use only "reverse" or empty values with this option.
|
| card | object | Can be used to wrap a card around the table component. If any of these options are present, a card will wrap around the table. See macro options for card. |
| panel | boolean |
Deprecated in 10.3.0 (see GitHub).
Replaced by the card option.
|
|
panel |
string |
Deprecated in 10.3.0 (see GitHub).
Replaced by the card.classes option.
|
| heading | string |
Deprecated in 10.3.0 (see GitHub).
Replaced by the card.heading.text option.
|
|
heading |
integer |
Deprecated in 10.3.0 (see GitHub).
Replaced by the card.heading.level option.
|
| classes | string | Classes to add to the table container. |
|
table |
string |
Deprecated in 10.3.0 (see GitHub).
Replaced by the classes option.
|
| attributes | object | HTML attributes (for example data attributes) to add to the table container. |
|
ascending |
string |
Text for columns in ascending sort order, used to populate the %{direction} placeholder in sortAnnouncementText. Defaults to "ascending".
|
|
descending |
string |
Text for columns in descending sort order, used to populate the %{direction} placeholder in sortAnnouncementText. Defaults to "descending".
|
|
sort |
string |
Announcement made to screen reader users when a table column has been sorted. The component will replace the %{header} placeholder with the column header, and the %{direction} placeholder with the ascendingText or descendingText option value.
|
| Name | Type | Description |
|---|---|---|
| text | string |
Required.
If html is set, this is not required. Text for cells in table rows. If html is provided, the text argument will be ignored.
|
| html | string |
Required.
If text is set, this is not required. HTML for cells in table rows. If html is provided, the text argument will be ignored.
|
|
visually |
string | A visually hidden suffix added to the table cell. |
| header | string |
Deprecated in 10.6.0 (see GitHub).
Set automatically by table head cells in the head option.
|
| href | string | If set, the table cell will become a link. |
| format | string |
Specify format of a cell – "numeric" or "string". Defaults to "string"
|
|
sort |
string | Sort value text for cells in table rows. |
| colspan | integer | Specify how many columns a cell spans. |
| rowspan | integer | Specify how many rows a cell spans. |
| align | string |
Specify the table cell alignment – "left", "centre", or "right". Defaults to "left"
|
| width | string |
Specify the table cell width. You can pass any design system grid width here – for example, "one-third", "two-thirds" or "one-half".
|
| classes | string | Classes to add to the table cell. |
| attributes | object | HTML attributes (for example data attributes) to add to the table cell. |
| Name | Type | Description |
|---|---|---|
| text | string |
If html is set, this is not required. Text for table head cells. If html is provided, the text argument will be ignored.
|
| html | string |
If text is set, this is not required. HTML for table head cells. If html is provided, the text argument will be ignored.
|
|
visually |
string | A visually hidden suffix added to the table head cell. |
| href | string |
If set, the table header will become a link for server-side table sorting. Use sort to set the column sort direction.
|
| format | string |
Specify format of a cell – "numeric" or "string". Defaults to "string"
|
| colspan | integer | Specify how many columns a cell spans. |
| rowspan | integer | Specify how many rows a cell spans. |
| align | string |
Specify the table head cell alignment – "left", "centre", or "right". Defaults to "left"
|
| width | string |
Specify the table head cell width. You can pass any design system grid width here – for example, "one-third", "two-thirds" or "one-half".
|
| classes | string | Classes to add to the table head cell. |
| attributes | object | HTML attributes (for example data attributes) to add to the table head cell. |
| sort | string |
The sort direction applied to the column using aria-sort – "ascending", "descending", "none" or true. To enable sorting without a default direction, set sort to "none" or true.
|
|
sort |
string |
The next sort direction applied to the column using aria-sort when clicked – "ascending" or "descending". Defaults to "ascending". If you set sort to "ascending", sortNext defaults to "descending".
|
| Name | Type | Description |
|---|---|---|
| id | string |
The ID of the table caption and the aria-labelledby attribute in the scrolling container. Defaults to the table id option suffixed with "-caption". If neither are provided, the ID is generated from the caption text option.
|
| text | string |
Required.
If html is set, this is not required. Text for the table caption. If html is provided, the text option will be ignored.
|
| html | string |
Required.
If text is set, this is not required. HTML for the table caption. If html is provided, the text option will be ignored.
|
|
visually |
string |
Message made available to assistive technologies to describe that the table is sortable. Defaults to "Column headers are sortable".
|
| size | string |
Size of the table caption – "s", "m", "l" or "xl".
|
| classes | string |
Classes to add to the table caption, for example "nhsuk-table__caption--l".
|
| attributes | object | HTML attributes (for example data attributes) to add to the table caption. |
Tables on dark backgrounds
To show tables with white text on dark backgrounds, add the variant: "reverse" option using Nunjucks. For HTML add the nhsuk-table--reverse class to the table.
Make sure all users can see the table content. The background colour must have a contrast ratio of at least 4.5:1 with white to meet WCAG 2.2 success criterion 1.4.3 Contrast (minimum), level AA (W3C).
Nunjucks macro options
Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.
Some options are required for the macro to work. These are marked as "Required" in the option description. Deprecated options are marked as "Deprecated".
If you're using Nunjucks macros in production with "html" options, or ones ending with "html", you must sanitise the HTML to protect against cross-site scripting exploits.
| Name | Type | Description |
|---|---|---|
| id | string | The ID of the table. |
| border | boolean |
If set to false, remove separating borders from all rows.
|
|
last |
boolean |
If set to false, remove separating border from the last row.
|
| rows | array | Required. Array of table rows and cells. See macro options for rows. |
| head | array | Array of table head cells. See macro options for head. |
| caption | object | Table caption. See macro options for caption. |
|
caption |
string |
Deprecated in 10.6.0 (see GitHub).
Replaced by the caption.classes option.
|
|
caption |
string |
Deprecated in 10.6.0 (see GitHub).
Replaced by the caption.size option.
|
|
first |
boolean |
If set to true, first cell in table row will be a th instead of a td.
|
| compact | boolean |
If set to true, vertical padding will be reduced for table cells.
|
| responsive | boolean |
If set to true, responsive table classes will be applied.
|
| scroll | boolean |
If set to true, wrap a scrolling container around the table component. Scrolling tables require the caption.text and caption.id options.
|
| striped | boolean |
If set to true, striped background colours will be applied to table rows.
|
| variant | string |
Optional variant of table. You can use only "reverse" or empty values with this option.
|
| card | object | Can be used to wrap a card around the table component. If any of these options are present, a card will wrap around the table. See macro options for card. |
| panel | boolean |
Deprecated in 10.3.0 (see GitHub).
Replaced by the card option.
|
|
panel |
string |
Deprecated in 10.3.0 (see GitHub).
Replaced by the card.classes option.
|
| heading | string |
Deprecated in 10.3.0 (see GitHub).
Replaced by the card.heading.text option.
|
|
heading |
integer |
Deprecated in 10.3.0 (see GitHub).
Replaced by the card.heading.level option.
|
| classes | string | Classes to add to the table container. |
|
table |
string |
Deprecated in 10.3.0 (see GitHub).
Replaced by the classes option.
|
| attributes | object | HTML attributes (for example data attributes) to add to the table container. |
|
ascending |
string |
Text for columns in ascending sort order, used to populate the %{direction} placeholder in sortAnnouncementText. Defaults to "ascending".
|
|
descending |
string |
Text for columns in descending sort order, used to populate the %{direction} placeholder in sortAnnouncementText. Defaults to "descending".
|
|
sort |
string |
Announcement made to screen reader users when a table column has been sorted. The component will replace the %{header} placeholder with the column header, and the %{direction} placeholder with the ascendingText or descendingText option value.
|
| Name | Type | Description |
|---|---|---|
| text | string |
Required.
If html is set, this is not required. Text for cells in table rows. If html is provided, the text argument will be ignored.
|
| html | string |
Required.
If text is set, this is not required. HTML for cells in table rows. If html is provided, the text argument will be ignored.
|
|
visually |
string | A visually hidden suffix added to the table cell. |
| header | string |
Deprecated in 10.6.0 (see GitHub).
Set automatically by table head cells in the head option.
|
| href | string | If set, the table cell will become a link. |
| format | string |
Specify format of a cell – "numeric" or "string". Defaults to "string"
|
|
sort |
string | Sort value text for cells in table rows. |
| colspan | integer | Specify how many columns a cell spans. |
| rowspan | integer | Specify how many rows a cell spans. |
| align | string |
Specify the table cell alignment – "left", "centre", or "right". Defaults to "left"
|
| width | string |
Specify the table cell width. You can pass any design system grid width here – for example, "one-third", "two-thirds" or "one-half".
|
| classes | string | Classes to add to the table cell. |
| attributes | object | HTML attributes (for example data attributes) to add to the table cell. |
| Name | Type | Description |
|---|---|---|
| text | string |
If html is set, this is not required. Text for table head cells. If html is provided, the text argument will be ignored.
|
| html | string |
If text is set, this is not required. HTML for table head cells. If html is provided, the text argument will be ignored.
|
|
visually |
string | A visually hidden suffix added to the table head cell. |
| href | string |
If set, the table header will become a link for server-side table sorting. Use sort to set the column sort direction.
|
| format | string |
Specify format of a cell – "numeric" or "string". Defaults to "string"
|
| colspan | integer | Specify how many columns a cell spans. |
| rowspan | integer | Specify how many rows a cell spans. |
| align | string |
Specify the table head cell alignment – "left", "centre", or "right". Defaults to "left"
|
| width | string |
Specify the table head cell width. You can pass any design system grid width here – for example, "one-third", "two-thirds" or "one-half".
|
| classes | string | Classes to add to the table head cell. |
| attributes | object | HTML attributes (for example data attributes) to add to the table head cell. |
| sort | string |
The sort direction applied to the column using aria-sort – "ascending", "descending", "none" or true. To enable sorting without a default direction, set sort to "none" or true.
|
|
sort |
string |
The next sort direction applied to the column using aria-sort when clicked – "ascending" or "descending". Defaults to "ascending". If you set sort to "ascending", sortNext defaults to "descending".
|
| Name | Type | Description |
|---|---|---|
| id | string |
The ID of the table caption and the aria-labelledby attribute in the scrolling container. Defaults to the table id option suffixed with "-caption". If neither are provided, the ID is generated from the caption text option.
|
| text | string |
Required.
If html is set, this is not required. Text for the table caption. If html is provided, the text option will be ignored.
|
| html | string |
Required.
If text is set, this is not required. HTML for the table caption. If html is provided, the text option will be ignored.
|
|
visually |
string |
Message made available to assistive technologies to describe that the table is sortable. Defaults to "Column headers are sortable".
|
| size | string |
Size of the table caption – "s", "m", "l" or "xl".
|
| classes | string |
Classes to add to the table caption, for example "nhsuk-table__caption--l".
|
| attributes | object | HTML attributes (for example data attributes) to add to the table caption. |
Accessibility
Follow WebAIM's guidance for tables and:
- give tables captions
- use the scope attribute to associate the data cells with the appropriate headers
- let the browser window determine the width of the table whenever possible, to reduce horizontal scrolling
Table captions
Use the <caption> element to describe a table in the same way you would use a heading. A caption helps users find, navigate and understand tables.
Style table captions to match the visual hierarchy of your page's content.
If you're using Nunjucks, add the size: "l" option to the caption. For HTML add the nhsuk-table__caption--l class to the caption.
You can use sizes s, m, l, xl.
Table headers
Use table headers to tell users what the rows and columns represent.
Sortable tables
The sortable table tells screen reader users that it can be sorted. When the user sorts the table, it announces what the new sort order is.
Research
Basic table
This table tested well with users of health information on the NHS website.
Responsive table
This table was tested at HM Revenue & Customs.
Sortable table
This table was developed by NHS England and tested in the Run breast screening in England and Manage vaccinations in schools services.
There is an overlap between sortable tables and:
- search
- filter
- pagination
We want to understand better how they can work together.
We have not yet developed a responsive or scrolling sortable table. If you need a responsive sorting table, you could try adding a select component.
Please feed back if you develop any of these or implement server-side sorting.
Table with panel
We have also designed a table with a panel. You can find an example in the frontend library. We have not included it in this list of components yet because it needs more testing.
Help us improve this guidance
Share insights or feedback and take part in the discussion. We use GitHub as a collaboration space. All the information on it is open to the public.
Feed back or share insights on GitHubRead more about how to feed back or share insights.
If you have any questions, get in touch with the service manual team.
Updated: August 2026