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 modifiers, and responsive to wrap the table in .table-responsive (pass a breakpoint to use the responsive variant, for example responsive="md").

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—the wrapper does it—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.

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

Variants

Use theme-specific color classes to style tables, table rows, or individual cells. 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 table row or cell by adding the .table-active class.

#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 table variants are the .theme-* classes: each one sets --bs-theme-bg-subtle and --bs-theme-fg on the table, row, or cell it is added to, 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

Border color utilities can be added 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

Compose border, border radius, and overflow utilities. Drop the table's bottom margin with .mb-0.

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

With .table-card

Use .table-card for the same look. It 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

Add the small prop to make any .table more compact by cutting all cell padding in half.

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

Table group dividers

Add a thicker, darker border between table groups—<thead>, <tbody>, and <tfoot>—with .table-group-divider. Customize the color by changing the border-top-color.

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

Vertical alignment

Table cells of <thead> are always vertical aligned to the bottom. Table cells in <tbody> inherit their alignment from <table> and are aligned to the top by default. Use the vertical align classes to re-align where needed.

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.

#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

You can also put the <caption> on the top of the table with .caption-top.

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

Stacked tables

Add .table-stacked to convert a table's 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 <td>.

Both .table-stacked and .table-responsive use container queries, so the responsive wrapper is required as the query container. Use .md:table-stacked, .lg:table-stacked, etc. to only stack below a specific container width. The default .table-stacked always stacks.

NameTypeDefaultDescription
backdropboolean or 'static'true

Includes 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 variable and Sass reference.