Skip to main content

Components

Table

Table is used to display structured information in a neat and organized manner. Tables can make it easier for users to scan and compare information.

zebra
Description

Will give the table zebra striping

Type
boolean
Default
false
stickyHeader
Description

Will make the table header sticky

Type
boolean
Default
false
border
Description

Will give the table a rounded border

Type
boolean
Default
false
hover
Description

Will give the table a hover effect on rows

Type
boolean
Default
false
NameTypeDefaultDescription
zebrabooleanfalse

Will give the table zebra striping

stickyHeaderbooleanfalse

Will make the table header sticky

borderbooleanfalse

Will give the table a rounded border

hoverbooleanfalse

Will give the table a hover effect on rows

TableHeaderCell

sort
Description

If 'none' | 'ascending' | 'descending' | 'other' will add a button to the header cell and change aria-sort and icon

Type
"none" | "ascending" | "descending" | "other"
Default
undefined
NameTypeDefaultDescription
sort"none" | "ascending" | "descending" | "other"undefined

If 'none' | 'ascending' | 'descending' | 'other' will add a button to the header cell and change aria-sort and icon

Use

Example

Zebra Stripes

With border

Sorting

You can use props on Table.HeaderCell to show that the table can be sorted by the contents of a column.

  • Use the sort prop to indicate the sort direction:
  • "none" - no sorting
  • "ascending" - ascending order
  • "descending" - descending order
  • Use onClick to handle what happens when the user clicks on the column header.

Fixed column width

You can use table-layout: fixed to prevent column widths from changing when the table content is updated. This provides a smoother layout, and helps the browser draw the table faster.

This is especially useful in tables with pagination or other dynamically updated content, where stable column widths provide a better user experience.

HTML

It is recommended to read about <table> on MDN (mozilla.org) for a thorough review of HTML tables and their semantics.

The class name ds-table is applied to the <table> element.

Sorting

By placing <button> in a <th> with aria-sort="*" you create a visual button for sorting.

You connect the logic for sorting to the button yourself.

Note that we apply type="button" to avoid the button behaving like a submit button.

CSS variables and data attributes

CSS Variables
NameValue
--dsc-table-background--hovervar(--ds-color-surface-hover)
--dsc-table-background--zebravar(--ds-color-surface-tinted)
--dsc-table-backgroundtransparent
--dsc-table-border-colorvar(--ds-color-border-subtle)
--dsc-table-border-radiusvar(--ds-border-radius-md)
--dsc-table-border-stylesolid
--dsc-table-border-widthvar(--ds-border-width-default)
--dsc-table-colorvar(--ds-color-text-default)
--dsc-table-divider-border-colorvar(--dsc-table-border-color)
--dsc-table-divider-border-stylesolid
--dsc-table-divider-border-widthcalc(var(--ds-border-width-default) + 1px)
--dsc-table-header-background--hovervar(--ds-color-surface-hover)
--dsc-table-header-background--sortedvar(--ds-color-surface-tinted)
--dsc-table-header-background--stickyvar(--ds-color-surface-default)
--dsc-table-header-backgroundtransparent
--dsc-table-paddingvar(--ds-size-2) var(--ds-size-3)
--dsc-table-sort-sizevar(--ds-size-6)
Data Attributes
NameValue
data-border
data-sticky-header
data-zebra
data-hover
Edit this page on github.com (opens in a new tab)