Skip to main content
Components

Table

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

Children are the body rows.

Read the Design System guidance for table

Import

import * as Table from 'govuk-react/table';

Examples

Default

Code
<Table.Composite
  caption="Dates and amounts"
  captionSize="m"
  head={(
    <>
      <Table.ColumnHeader>Date</Table.ColumnHeader>
      <Table.ColumnHeader>Amount</Table.ColumnHeader>
    </>
  )}
>
  {(
    <>
      <Table.Row>
        <Table.RowHeader>First 6 weeks</Table.RowHeader>
        <Table.Cell>£109.80 per week</Table.Cell>
      </Table.Row>
      <Table.Row>
        <Table.RowHeader>Next 33 weeks</Table.RowHeader>
        <Table.Cell>£109.80 per week</Table.Cell>
      </Table.Row>
      <Table.Row>
        <Table.RowHeader>Total estimated pay</Table.RowHeader>
        <Table.Cell>£4,282.20</Table.Cell>
      </Table.Row>
    </>
  )}
</Table.Composite>

Numbers in a table

Code
<Table.Composite
  caption="Months and rates"
  captionSize="m"
  head={(
    <>
      <Table.ColumnHeader>Month you apply</Table.ColumnHeader>
      <Table.ColumnHeader numeric>Rate for bicycles</Table.ColumnHeader>
      <Table.ColumnHeader numeric>Rate for vehicles</Table.ColumnHeader>
    </>
  )}
>
  {(
    <>
      <Table.Row>
        <Table.RowHeader>January</Table.RowHeader>
        <Table.Cell numeric>£85</Table.Cell>
        <Table.Cell numeric>£95</Table.Cell>
      </Table.Row>
      <Table.Row>
        <Table.RowHeader>February</Table.RowHeader>
        <Table.Cell numeric>£75</Table.Cell>
        <Table.Cell numeric>£55</Table.Cell>
      </Table.Row>
      <Table.Row>
        <Table.RowHeader>March</Table.RowHeader>
        <Table.Cell numeric>£165</Table.Cell>
        <Table.Cell numeric>£125</Table.Cell>
      </Table.Row>
    </>
  )}
</Table.Composite>

Custom column widths

Code
<Table.Composite
  caption="Month you apply"
  captionSize="m"
  head={(
    <>
      <Table.ColumnHeader className={overrideClasses({ width: 'one-half' })}>Date</Table.ColumnHeader>
      <Table.ColumnHeader className={overrideClasses({ width: 'one-quarter' })}>Rate for vehicles</Table.ColumnHeader>
      <Table.ColumnHeader className={overrideClasses({ width: 'one-quarter' })}>Rate for bicycles</Table.ColumnHeader>
    </>
  )}
>
  {(
    <Table.Row>
      <Table.RowHeader>First 6 weeks</Table.RowHeader>
      <Table.Cell>£109.80 per week</Table.Cell>
      <Table.Cell>£159.80 per week</Table.Cell>
    </Table.Row>
  )}
</Table.Composite>

API reference

Table.Root

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

PropType
smallTextUntilTabletboolean

Table.Body

No props of its own. Other props are passed to the element it renders.

Table.Caption

PropType
size"m" | "l" | "xl"

Table.Cell

PropType
numericboolean

Table.ColumnHeader

PropType
numericboolean

Table.Composite

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

Children are the body rows.

PropType
smallTextUntilTabletboolean
caption

Caption text.

ReactNode
captionSize"m" | "l" | "xl"
head

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

ReactNode

Table.Head

No props of its own. Other props are passed to the element it renders.

Table.Header

PropType
numericboolean

Table.Row

No props of its own. Other props are passed to the element it renders.

Table.RowHeader

PropType
numericboolean