Components

Table

Use the table component to make information easier to compare and scan for users.

Dates and amounts
DateAmount
First 6 weeks£109.80 per week
Next 33 weeks£109.80 per week
Total estimated pay£4,282.20
<table class="govuk-table">
<caption class="govuk-table__caption govuk-table__caption--m">
Dates and amounts
</caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th scope="col" class="govuk-table__header">Date</th>
<th scope="col" class="govuk-table__header">Amount</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<tr class="govuk-table__row">
<th scope="row" class="govuk-table__header">First 6 weeks</th>
<td class="govuk-table__cell">£109.80 per week</td>
</tr>
<tr class="govuk-table__row">
<th scope="row" class="govuk-table__header">Next 33 weeks</th>
<td class="govuk-table__cell">£109.80 per week</td>
</tr>
<tr class="govuk-table__row">
<th scope="row" class="govuk-table__header">Total estimated pay</th>
<td class="govuk-table__cell">£4,282.20</td>
</tr>
</tbody>
</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.

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.

Primary options
Name Type Description
rows array Required.

The rows within the table component.

See rows.

head array

Can be used to add a row of table header cells (<th>) at the top of the table component.

See head.

caption string

Caption text.

captionClasses string

Classes for caption text size. Classes should correspond to the available typography heading classes.

firstCellIsHeader boolean

If set to true, the first cell in each row will be a table header (<th>).

classes string

Classes to add to the table container.

attributes object

HTML attributes (for example data attributes) to add to the table container.

Options for head
Name Type Description
text string

If html is set, this is not required. Text for table head cells. If html is provided, the text option will be ignored.

html string

If text is set, this is not required. HTML for table head cells. If html is provided, the text option will be ignored.

format string

Specify format of a cell. Currently we only use "numeric".

classes string

Classes to add to the table head cell.

colspan integer

Specify how many columns a cell extends.

rowspan integer

Specify how many rows a cell extends.

attributes object

HTML attributes (for example data attributes) to add to the table cell.

Options for rows
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 option 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 option will be ignored.

format string

Specify format of a cell. Currently we only use "numeric".

classes string

Classes to add to the table row cell.

colspan integer

Specify how many columns a cell extends.

rowspan integer

Specify how many rows a cell extends.

attributes object

HTML attributes (for example data attributes) to add to the table cell.

{% from "moduk/components/table/macro.njk" import modukTable -%}

{{ modukTable({
caption: "Dates and amounts",
captionClasses: "govuk-table__caption--m",
firstCellIsHeader: true,
head: [
{
text: "Date"
},
{
text: "Amount"
}
],
rows: [
[
{
text: "First 6 weeks"
},
{
text: "£109.80 per week"
}
],
[
{
text: "Next 33 weeks"
},
{
text: "£109.80 per week"
}
],
[
{
text: "Total estimated pay"
},
{
text: "£4,282.20"
}
]
]
}) -}}

See GOV.UK table component guidance for:

  • when to use this component
  • when not to use it
  • how it works

Changes from the GOV.UK version

MOD.UK Design System components are closely based on GOV.UK Design System components.

For this component we’ve changed the font.

Have you tested this component?

Let us know how we could improve this component or share your user research findings.

Email the MOD.UK Design System team at design-system@digital.mod.uk

Need help?

Email the MOD.UK Design System team at design-system@digital.mod.uk if you have questions or feedback.