Tables
Documentation and examples for opt-in styling of tables (given their prevalent use in JavaScript plugins) with Bootstrap.
Overview
Due to the widespread use of table> elements across third-party widgets like calendars and date pickers, Bootstrap’s tables are opt-in. Add the base class .table to any .table>, then extend with our optional modifier classes or custom styles. All table styles are not inherited in Bootstrap, meaning any nested tables can be styled independent from the parent.
Using the most basic table markup, here’s how .table-based tables look in Bootstrap.
Variants
Use contextual classes to color tables, table rows or individual cells.
Accented tables
Striped rows
Use .table-striped to add zebra-striping to any table row within the .tbody>.
Striped columns
Use .table-striped-columns to add zebra-striping to any table column.
These classes can also be added to table variants:
Hoverable rows
Add .table-hover to enable a hover state on table rows within a .tbody>.
These hoverable rows can also be combined with the striped rows variant:
Active tables
Highlight a table row or cell by adding a .table-active class.
How do the variants and accented tables work?
For the accented tables (striped rows, striped columns, hoverable rows, and active tables), we used some techniques to make these effects work for all our table variants:
Table borders
Bordered tables
Add .table-bordered for borders on all sides of the table and cells.
Border color utilities can be added to change colors:
Tables without borders
Add .table-borderless for a table without borders.
Small tables
Add .table-sm to make any .table more compact by cutting all cell padding in half.
Table group dividers
Add a thicker border, darker between table groups—,
, and —with .table-group-divider. Customize the color by changing the border-top-color (which we don’t currently provide a utility class for at this time).
Vertical alignment
Table cells of are always vertical aligned to the bottom. Table cells in
inherit their alignment from and are aligned to the top by default. Use the vertical align classes to re-align where needed.
Nesting
Border styles, active styles, and table variants are not inherited by nested tables.
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
s as direct children of a table, those
will be wrapped in a
by default, thus making our selectors work as intended.
Anatomy
Table head
Similar to tables and dark tables, use the modifier classes .table-light or .table-dark to make s appear light or dark gray.
Table foot
Captions
A
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.
You can also put the
on the top of the table with .caption-top.
Responsive tables
Responsive tables allow tables to be scrolled horizontally with ease. Make any table responsive across all viewports by wrapping a .table with .table-responsive. Or, pick a maximum breakpoint with which to have a responsive table up to by using .table-responsive{-sm|-md|-lg|-xl|-xxl}.
Always responsive
Across every breakpoint, use .table-responsive for horizontally scrolling tables.
Breakpoint specific
Use .table-responsive{-sm|-md|-lg|-xl|-xxl} 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.
These tables may appear broken until their responsive styles apply at specific viewport widths.
CSS
Sass variables
Sass loops
Customizing
The factor variables ($table-striped-bg-factor, $table-active-bg-factor & $table-hover-bg-factor) are used to determine the contrast in table variants.
Apart from the light & dark table variants, theme colors are lightened by the $table-bg-scale variable.