Tables
Documentation and examples for opt-in styling of tables (given their prevalent use in JavaScript plugins) with Bootstrap.
Idea React provides the Table wrapper for these examples. Use the striped,
stripedColumns, hover, bordered, borderless, and small props for the corresponding
variants; card adds the card wrapper, while responsive adds a responsive wrapper. Set
verticalAlign, captionTop, and stacked to apply the corresponding table styles. Pass a
breakpoint to responsive or stacked to apply its style responsively, for example
responsive="md".
The as prop replaces the table root, or the outer wrapper when responsive is enabled.
With an explicit as, additional props, className, and the ref are forwarded to that root;
responsive tables retain their inner table and its Bootstrap variants.
Overview
Due to the widespread use of tables across third-party widgets like calendars and date pickers,
Table styles are opt-in. The wrapper applies the base styling; use its variant props or
className to customize the table. Nested tables can be styled independently from their parent.
Here is the default appearance of Table.
| # | First | Last | Handle |
|---|---|---|---|
| 1 | Mark | Otto | @mdo |
| 2 | Jacob | Thornton | @fat |
| 3 | John | Doe | @social |
Variants
Use theme color utilities through className to style a table, row, or cell. These adapt to color
modes as well.
| Class | Heading | Heading |
|---|---|---|
| Default | Cell | Cell |
| Primary | Cell | Cell |
| Accent | Cell | Cell |
| Secondary | Cell | Cell |
| Success | Cell | Cell |
| Danger | Cell | Cell |
| Warning | Cell | Cell |
| Info | Cell | Cell |
| Light | Cell | Cell |
| Dark | Cell | Cell |
| Inverse | Cell | Cell |
Accented tables
Striped rows
Use the striped prop to add zebra-striping to any table row within the <tbody>.
| # | First | Last | Handle |
|---|---|---|---|
| 1 | Mark | Otto | @mdo |
| 2 | Jacob | Thornton | @fat |
| 3 | John | Doe | @social |
Striped columns
Use the stripedColumns prop to add zebra-striping to any table column.
| # | First | Last | Handle |
|---|---|---|---|
| 1 | Mark | Otto | @mdo |
| 2 | Jacob | Thornton | @fat |
| 3 | John | Doe | @social |
These props can also be combined with table variants:
| # | First | Last | Handle |
|---|---|---|---|
| 1 | Mark | Otto | @mdo |
| 2 | Jacob | Thornton | @fat |
| 3 | John | Doe | @social |
Hoverable rows
Add the hover prop to enable a hover state on table rows within a <tbody>.
| # | First | Last | Handle |
|---|---|---|---|
| 1 | Mark | Otto | @mdo |
| 2 | Jacob | Thornton | @fat |
| 3 | John | Doe | @social |
These hoverable rows can also be combined with the striped rows variant:
| # | First | Last | Handle |
|---|---|---|---|
| 1 | Mark | Otto | @mdo |
| 2 | Jacob | Thornton | @fat |
| 3 | John | Doe | @social |
Active tables
Highlight a row or cell by passing className="table-active" to it.
| # | First | Last | Handle |
|---|---|---|---|
| 1 | Mark | Otto | @mdo |
| 2 | Jacob | Thornton | @fat |
| 3 | John | Doe | @social |
How do the variants and accented tables work?
For the accented tables (striped rows, striped columns, hoverable rows, and active tables), we start
by setting the background of a table cell to var(--bs-theme-bg-subtle, var(--bs-table-bg)). The
theme utility classes each set --bs-theme-bg-subtle and --bs-theme-fg on the table, row, or cell
whose className includes the utility, and the cells inside pick them up. This way, we don't get
into trouble if semi-transparent colors are used as table backgrounds.
A box shadow is layered on top of any specified background-color, and the stripe, active, and hover
factors mix the theme foreground into the cells. Text colors are generated the same way, and borders
use --bs-theme-border when a theme class sets it, or --bs-table-border-color otherwise.
Table borders
Bordered tables
Add the bordered prop for borders on all sides of the table and cells.
| # | First | Last | Handle |
|---|---|---|---|
| 1 | Mark | Otto | @mdo |
| 2 | Jacob | Thornton | @fat |
| 3 | John | Doe | @social |
Pass border-color utilities through className to change colors:
| # | First | Last | Handle |
|---|---|---|---|
| 1 | Mark | Otto | @mdo |
| 2 | Jacob | Thornton | @fat |
| 3 | John | Doe | @social |
Tables without borders
Add the borderless prop for a table without borders.
| # | First | Last | Handle |
|---|---|---|---|
| 1 | Mark | Otto | @mdo |
| 2 | Jacob | Thornton | @fat |
| 3 | John | Doe | @social |
Card-like tables
Need a bordered, rounded table without nesting it in a card? Wrap the table and clip the corners.
With utilities
Use border, border-radius, and overflow utilities through the wrapper's className. Pass a margin
utility through Table's className to remove its bottom margin.
| # | First | Last | Handle |
|---|---|---|---|
| 1 | Mark | Otto | @mdo |
| 2 | Jacob | Thornton | @fat |
| 3 | John | Doe | @social |
With a card wrapper
Set card on Table to add a wrapper that rounds corners like a card, clips cell backgrounds,
and removes the last row's bottom border so it does not stack on the wrapper.
| # | First | Last | Handle |
|---|---|---|---|
| 1 | Mark | Otto | @mdo |
| 2 | Jacob | Thornton | @fat |
| 3 | John | Doe | @social |
Small tables
Set the small prop on Table to make it more compact by cutting all cell padding in half.
| # | First | Last | Handle |
|---|---|---|---|
| 1 | Mark | Otto | @mdo |
| 2 | Jacob | Thornton | @fat |
| 3 | John | Doe | @social |
Table group dividers
Add className="table-group-divider" to a row group to add a thicker, darker border between table
groups. Customize its color with the border-top-color style.
| # | First | Last | Handle |
|---|---|---|---|
| 1 | Mark | Otto | @mdo |
| 2 | Jacob | Thornton | @fat |
| 3 | John | Doe | @social |
Vertical alignment
Header cells are vertically aligned to the bottom. Body cells inherit their alignment from the
table and are aligned to the top by default. Set verticalAlign on Table to control body cell
alignment; vertical-alignment utility classes can still be passed through className on individual
rows or cells.
| Heading 1 | Heading 2 | Heading 3 | Heading 4 |
|---|---|---|---|
This cell inherits vertical-align: middle; from the table | This cell inherits vertical-align: middle; from the table | This cell inherits vertical-align: middle; from the table | This here is some placeholder text, intended to take up quite a bit of vertical space, to demonstrate how the vertical alignment works in the preceding cells. |
This cell inherits vertical-align: bottom; from the table row | This cell inherits vertical-align: bottom; from the table row | This cell inherits vertical-align: bottom; from the table row | This here is some placeholder text, intended to take up quite a bit of vertical space, to demonstrate how the vertical alignment works in the preceding cells. |
This cell inherits vertical-align: middle; from the table | This cell inherits vertical-align: middle; from the table | This cell is aligned to the top. | This here is some placeholder text, intended to take up quite a bit of vertical space, to demonstrate how the vertical alignment works in the preceding cells. |
Nesting
Border styles, active styles, and table variants are not inherited by nested tables.
| # | First | Last | Handle | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | Mark | Otto | @mdo | ||||||||||||
| |||||||||||||||
| 3 | John | Doe | @social | ||||||||||||
How nesting works
To prevent any styles from leaking to nested tables, we use the child combinator (>) selector in
our CSS. Since we need to target all the tds and ths in the thead, tbody, and tfoot, our
selector would look pretty long without it. As such, we use the rather odd looking
.table > :not(caption) > * > * selector to target all tds and ths of the .table, but none of
any potential nested tables.
Note that if you add <tr>s as direct children of a table, those <tr> will be wrapped in a
<tbody> by default, thus making our selectors work as intended.
Footer
| # | First | Last | Handle |
|---|---|---|---|
| 1 | Mark | Otto | @mdo |
| 2 | Jacob | Thornton | @fat |
| 3 | John | Doe | @social |
| Footer | Footer | Footer | Footer |
Caption
A <caption> functions like a heading for a table. It helps users with screen readers to find a
table and understand what it's about and decide if they want to read it.
| # | First | Last | Handle |
|---|---|---|---|
| 1 | Mark | Otto | @mdo |
| 2 | Jacob | Thornton | @fat |
| 3 | John | Doe | @social |
Set the captionTop prop on Table to place its caption above the table.
| # | First | Last | Handle |
|---|---|---|---|
| 1 | Mark | Otto | @mdo |
| 2 | Jacob | Thornton | @fat |
| 3 | John | Doe | @social |
Stacked tables
Set stacked on Table to convert its rows into stacked blocks when space is limited. Each
row becomes a vertical block with the first cell acting as a bold title and the remaining cells
displayed as label–value pairs. Labels are generated from data-cell attributes on each cell.
The responsive prop provides the container query required for responsive stacking. Pass
stacked="md" or another breakpoint to stack only below a specific container width. Without a
breakpoint, the rows are always stacked.
| Name | Type | Default | Description |
|---|---|---|---|
| backdrop | boolean or 'static' | true | Includes a backdrop element. Specify static for a backdrop which doesn't close on click. |
| keyboard | boolean | true | Closes the component when escape key is pressed. |
| focus | boolean | true | Puts the focus on the component when initialized. |
Responsive tables
Responsive tables allow tables to be scrolled horizontally with ease. Make any table responsive
across all viewports with the responsive prop. Or, pick a maximum breakpoint with which to have a
responsive table up to by using responsive="sm", responsive="md", responsive="lg",
responsive="xl", or responsive="2xl".
The wrapper also acts as the container query context for stacked tables.
Responsive tables make use of overflow-y: hidden, which clips off any content that goes beyond the
bottom or top edges of the table. In particular, this can clip off menus and other third-party
widgets.
Always responsive
Across every breakpoint, use responsive for horizontally scrolling tables.
| # | Heading | Heading | Heading | Heading | Heading | Heading | Heading | Heading | Heading |
|---|---|---|---|---|---|---|---|---|---|
| 1 | Cell | Cell | Cell | Cell | Cell | Cell | Cell | Cell | Cell |
| 2 | Cell | Cell | Cell | Cell | Cell | Cell | Cell | Cell | Cell |
| 3 | Cell | Cell | Cell | Cell | Cell | Cell | Cell | Cell | Cell |
Breakpoint specific
Use responsive="sm", responsive="md", responsive="lg", responsive="xl", or
responsive="2xl" as needed to create responsive tables up to a particular breakpoint. From that
breakpoint and up, the table will behave normally and not scroll horizontally.
| # | Heading | Heading | Heading | Heading | Heading | Heading | Heading | Heading |
|---|---|---|---|---|---|---|---|---|
| 1 | Cell | Cell | Cell | Cell | Cell | Cell | Cell | Cell |
| 2 | Cell | Cell | Cell | Cell | Cell | Cell | Cell | Cell |
| 3 | Cell | Cell | Cell | Cell | Cell | Cell | Cell | Cell |
CSS
Tables use CSS variables for real-time customization. Since .table styles are opt-in, nested
tables stay independent from their parent. The factor variables (--table-striped-bg-factor,
--table-active-bg-factor, and --table-hover-bg-factor) determine the contrast in table variants.
See the upstream table CSS for the CSS custom property reference.