Loading...
Skip to main content

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.

#FirstLastHandle
1MarkOtto@mdo
2JacobThornton@fat
3JohnDoe@social

Variants

Use theme color utilities through className to style a table, row, or cell. These adapt to color modes as well.

ClassHeadingHeading
DefaultCellCell
PrimaryCellCell
AccentCellCell
SecondaryCellCell
SuccessCellCell
DangerCellCell
WarningCellCell
InfoCellCell
LightCellCell
DarkCellCell
InverseCellCell

Accented tables

Striped rows

Use the striped prop to add zebra-striping to any table row within the <tbody>.

#FirstLastHandle
1MarkOtto@mdo
2JacobThornton@fat
3JohnDoe@social

Striped columns

Use the stripedColumns prop to add zebra-striping to any table column.

#FirstLastHandle
1MarkOtto@mdo
2JacobThornton@fat
3JohnDoe@social

These props can also be combined with table variants:

#FirstLastHandle
1MarkOtto@mdo
2JacobThornton@fat
3JohnDoe@social

Hoverable rows

Add the hover prop to enable a hover state on table rows within a <tbody>.

#FirstLastHandle
1MarkOtto@mdo
2JacobThornton@fat
3JohnDoe@social

These hoverable rows can also be combined with the striped rows variant:

#FirstLastHandle
1MarkOtto@mdo
2JacobThornton@fat
3JohnDoe@social

Active tables

Highlight a row or cell by passing className="table-active" to it.

#FirstLastHandle
1MarkOtto@mdo
2JacobThornton@fat
3JohnDoe@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.

#FirstLastHandle
1MarkOtto@mdo
2JacobThornton@fat
3JohnDoe@social

Pass border-color utilities through className to change colors:

#FirstLastHandle
1MarkOtto@mdo
2JacobThornton@fat
3JohnDoe@social

Tables without borders

Add the borderless prop for a table without borders.

#FirstLastHandle
1MarkOtto@mdo
2JacobThornton@fat
3JohnDoe@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.

#FirstLastHandle
1MarkOtto@mdo
2JacobThornton@fat
3JohnDoe@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.

#FirstLastHandle
1MarkOtto@mdo
2JacobThornton@fat
3JohnDoe@social

Small tables

Set the small prop on Table to make it more compact by cutting all cell padding in half.

#FirstLastHandle
1MarkOtto@mdo
2JacobThornton@fat
3JohnDoe@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.

#FirstLastHandle
1MarkOtto@mdo
2JacobThornton@fat
3JohnDoe@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 1Heading 2Heading 3Heading 4
This cell inherits vertical-align: middle; from the tableThis cell inherits vertical-align: middle; from the tableThis cell inherits vertical-align: middle; from the tableThis 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 rowThis cell inherits vertical-align: bottom; from the table rowThis cell inherits vertical-align: bottom; from the table rowThis 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 tableThis cell inherits vertical-align: middle; from the tableThis 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.

#FirstLastHandle
1MarkOtto@mdo
HeaderHeaderHeader
AFirstLast
BFirstLast
CFirstLast
3JohnDoe@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

#FirstLastHandle
1MarkOtto@mdo
2JacobThornton@fat
3JohnDoe@social
FooterFooterFooterFooter

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.

List of users
#FirstLastHandle
1MarkOtto@mdo
2JacobThornton@fat
3JohnDoe@social

Set the captionTop prop on Table to place its caption above the table.

List of users
#FirstLastHandle
1MarkOtto@mdo
2JacobThornton@fat
3JohnDoe@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.

NameTypeDefaultDescription
backdropboolean or 'static'trueIncludes a backdrop element. Specify static for a backdrop which doesn't close on click.
keyboardbooleantrueCloses the component when escape key is pressed.
focusbooleantruePuts 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.

#HeadingHeadingHeadingHeadingHeadingHeadingHeadingHeadingHeading
1CellCellCellCellCellCellCellCellCell
2CellCellCellCellCellCellCellCellCell
3CellCellCellCellCellCellCellCellCell

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.

#HeadingHeadingHeadingHeadingHeadingHeadingHeadingHeading
1CellCellCellCellCellCellCellCell
2CellCellCellCellCellCellCellCell
3CellCellCellCellCellCellCellCell

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.

Documentation navigation
On this page
On this page