Table
Use the table component to make information easier to compare and scan for users.
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.
How it works
Default Table
The default table includes horizontal lines.
The header row can be either dark or white depending on the brand color used as a background.
- Use
govgr-table--lightfor white background color (default). - Use
govgr-table--darkfor dark background color.
Table with light header
Table with dark header
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.
There are other styling options for table captions. You can use the above classes to make table header larger or smaller depending on the preference. The default value for the table header is m (medium).
- Use
govgr-table__caption--sclass for small header incaptiontag. - Use
govgr-table__caption--mclass for medium header (default) incaptiontag. - Use
govgr-table__caption--lclass for large header incaptiontag. - Use
govgr-table__caption--xlclass for xlarge header incaptiontag.
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 and create horizontal and vertical headers respectively.
- Horizontal headers can be used to create tables that have row header column.
- Vertical headers can be used to create tables that have both a header row and a header column. Note that the empty header cell on the top left corner has
role="presentation"attribute.
Numbers in a table
When comparing columns of numbers, align the numbers to the right in table cells.
- Use
govgr-table__header--numericclass inthtag. - Use
govgr-table__cell--numericclass intdtag.
Zebra rows
Zebra rows (alternating row colours) should be used on tables that have very long rows. It makes it easier to visually scan the table and follow rows.
- Use
govgr-table--zebraclass intabletag.
Vertical lines
Vertical lines can be used on tables that have a lot of columns or a lot of similar data (e.g. numbers).
- Use
govgr-table--with-vertical-headerandgovgr-table--with-vertical-linesclass intabletag.
Dense tables
If your table has a large amount of data, you can use the govgr-table--dense class to force mobile spacing on all screen sizes. This allows more data to fit into the view at the same time.
Custom column widths
You can use the width override classes to set the width of table columns.
- Use
govgr-!-width-one-quarterclass for one-quarter width. - Use
govgr-!-width-one-thirdclass for one-third width, - Use
govgr-!-width-one-halfclass for one-half width. - Use
govgr-!-width-two-thirdsclass for two-thirds width. - Use
govgr-!-width-three-quartersclass for three-quarters width. - Use
govgr-!-width-fullclass for full width.
Table container
Αvoid using tables that are too wide. Users might miss important information they need because some cells will be hidden from them. If you have no alternative, you can use a container class name for the table to contain the table in the width of the viewport.
You can also add the class govgr-table-container--border next to the govgr-table-container class to add a distinctive border at the container.