Components

Table

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

<table class="govuk-table">
  <caption class="govuk-table__caption">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. Array of table rows and cells. See rows.
head array Array of table head cells. 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, first cell in table row will be a TH instead of a TD.
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 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 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 ignore
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.
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 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 ignore
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.
{% from "govuk/components/table/macro.njk" import govukTable %}

{{ govukTable({
  caption: "Dates and amounts",
  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"
      }
    ]
  ]
}) }}

When to use this component

Use the table component to let users compare information in rows and columns.

When not to use this component

Never use the table component to layout content on a page. Instead, use the grid system.

How it works

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.

Table headers

Use table headers to tell users what the rows and columns represent. Use the scope attribute to help users of assistive technology distinguish between row and column headers.

There are 2 ways to use the table component. You can use HTML or, if you are using Nunjucks or the GOV.UK Prototype Kit, you can use the Nunjucks macro.

<table class="govuk-table">
  <caption class="govuk-table__caption">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. Array of table rows and cells. See rows.
head array Array of table head cells. 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, first cell in table row will be a TH instead of a TD.
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 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 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 ignore
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.
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 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 ignore
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.
{% from "govuk/components/table/macro.njk" import govukTable %}

{{ govukTable({
  caption: "Dates and amounts",
  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"
      }
    ]
  ]
}) }}

Numbers in a table

When comparing columns of numbers, align the numbers to the right in table cells.

<table class="govuk-table">
  <caption class="govuk-table__caption">Months and rates</caption>
  <thead class="govuk-table__head">
    <tr class="govuk-table__row">
      <th scope="col" class="govuk-table__header">Month you apply</th>
      <th scope="col" class="govuk-table__header govuk-table__header--numeric">Rate for bicycles</th>
      <th scope="col" class="govuk-table__header govuk-table__header--numeric">Rate for vehicles</th>
    </tr>
  </thead>
  <tbody class="govuk-table__body">
    <tr class="govuk-table__row">
      <th scope="row" class="govuk-table__header">January</th>
      <td class="govuk-table__cell govuk-table__cell--numeric">£85</td>
      <td class="govuk-table__cell govuk-table__cell--numeric">£95</td>
    </tr>
    <tr class="govuk-table__row">
      <th scope="row" class="govuk-table__header">February</th>
      <td class="govuk-table__cell govuk-table__cell--numeric">£75</td>
      <td class="govuk-table__cell govuk-table__cell--numeric">£55</td>
    </tr>
    <tr class="govuk-table__row">
      <th scope="row" class="govuk-table__header">March</th>
      <td class="govuk-table__cell govuk-table__cell--numeric">£165</td>
      <td class="govuk-table__cell govuk-table__cell--numeric">£125</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. Array of table rows and cells. See rows.
head array Array of table head cells. 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, first cell in table row will be a TH instead of a TD.
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 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 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 ignore
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.
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 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 ignore
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.
{% from "govuk/components/table/macro.njk" import govukTable %}

{{ govukTable({
  caption: "Months and rates",
  firstCellIsHeader: true,
  head: [
    {
      text: "Month you apply"
    },
    {
      text: "Rate for bicycles",
      format: "numeric"
    },
    {
      text: "Rate for vehicles",
      format: "numeric"
    }
  ],
  rows: [
    [
      {
        text: "January"
      },
      {
        text: "£85",
        format: "numeric"
      },
      {
        text: "£95",
        format: "numeric"
      }
    ],
    [
      {
        text: "February"
      },
      {
        text: "£75",
        format: "numeric"
      },
      {
        text: "£55",
        format: "numeric"
      }
    ],
    [
      {
        text: "March"
      },
      {
        text: "£165",
        format: "numeric"
      },
      {
        text: "£125",
        format: "numeric"
      }
    ]
  ]
}) }}

Custom column widths

You can use the width override classes to set the width of table columns.

<table class="govuk-table">
  <caption class="govuk-table__caption">Month you apply</caption>
  <thead class="govuk-table__head">
    <tr class="govuk-table__row">
      <th scope="col" class="govuk-table__header govuk-!-width-one-half">Date</th>
      <th scope="col" class="govuk-table__header govuk-!-width-one-quarter">Rate for vehicles</th>
      <th scope="col" class="govuk-table__header govuk-!-width-one-quarter">Rate for bicycles</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>
      <td class="govuk-table__cell">£59.10 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">£159.80 per week</td>
      <td class="govuk-table__cell">£89.10 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>
      <td class="govuk-table__cell">£2,182.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. Array of table rows and cells. See rows.
head array Array of table head cells. 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, first cell in table row will be a TH instead of a TD.
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 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 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 ignore
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.
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 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 ignore
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.
{% from "govuk/components/table/macro.njk" import govukTable %}

{{ govukTable({
  caption: "Month you apply",
  firstCellIsHeader: true,
  head: [
    {
      text: "Date",
      classes: 'govuk-!-width-one-half'
    },
    {
      text: "Rate for vehicles",
      classes: 'govuk-!-width-one-quarter'
    },
    {
      text: "Rate for bicycles",
      classes: 'govuk-!-width-one-quarter'
    }
  ],
  rows: [
    [
      {
        text: "First 6 weeks"
      },
      {
        text: "£109.80 per week"
      },
      {
        text: "£59.10 per week"
      }
    ],
    [
      {
        text: "Next 33 weeks"
      },
      {
        text: "£159.80 per week"
      },
      {
        text: "£89.10 per week"
      }
    ],
    [
      {
        text: "Total estimated pay"
      },
      {
        text: "£4,282.20"
      },
      {
        text: "£2,182.20"
      }
    ]
  ]
}) }}

If the width override classes do not meet your needs you can create your own width classes and apply them to the cells in the table head. These can be added using the classes option in the Nunjucks macro or adding the class directly to the individual cells within govuk-table__head as below.

To learn more about this, read guidance on extending and modifying components in production.

<table class="govuk-table">
  <caption class="govuk-table__caption">Month you apply</caption>
  <thead class="govuk-table__head">
    <tr class="govuk-table__row">
      <th scope="col" class="govuk-table__header app-custom-class">Date</th>
      <th scope="col" class="govuk-table__header app-custom-class">Rate for vehicles</th>
      <th scope="col" class="govuk-table__header app-custom-class">Rate for bicycles</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>
      <td class="govuk-table__cell">£59.10 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">£159.80 per week</td>
      <td class="govuk-table__cell">£89.10 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>
      <td class="govuk-table__cell">£2,182.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. Array of table rows and cells. See rows.
head array Array of table head cells. 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, first cell in table row will be a TH instead of a TD.
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 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 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 ignore
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.
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 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 ignore
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.
{% from "govuk/components/table/macro.njk" import govukTable %}

{{ govukTable({
  caption: "Month you apply",
  firstCellIsHeader: true,
  head: [
    {
      text: "Date",
      classes: 'app-custom-class'
    },
    {
      text: "Rate for vehicles",
      classes: 'app-custom-class'
    },
    {
      text: "Rate for bicycles",
      classes: 'app-custom-class'
    }
  ],
  rows: [
    [
      {
        text: "First 6 weeks"
      },
      {
        text: "£109.80 per week"
      },
      {
        text: "£59.10 per week"
      }
    ],
    [
      {
        text: "Next 33 weeks"
      },
      {
        text: "£159.80 per week"
      },
      {
        text: "£89.10 per week"
      }
    ],
    [
      {
        text: "Total estimated pay"
      },
      {
        text: "£4,282.20"
      },
      {
        text: "£2,182.20"
      }
    ]
  ]
}) }}

Help improve this page

To help make sure that this page is useful, relevant and up to date, you can:

Need help?

If you’ve got a question about the GOV.UK Design System, contact the team.