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.
| # | First | Last | Handle |
|---|---|---|---|
| 1 | Mark | Otto | @mdo |
| 2 | Jacob | Thornton | @fat |
| 3 | John | Doe | @social |
Variants
Use theme-specific color classes to style tables, table rows, or individual cells. 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 table row or cell by adding the .table-active class.
| # | 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
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.
| # | First | Last | Handle |
|---|---|---|---|
| 1 | Mark | Otto | @mdo |
| 2 | Jacob | Thornton | @fat |
| 3 | John | Doe | @social |
Border color utilities can be added 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
Compose border, border radius, and overflow utilities. Drop the table's bottom margin with .mb-0.
| # | First | Last | Handle |
|---|---|---|---|
| 1 | Mark | Otto | @mdo |
| 2 | Jacob | Thornton | @fat |
| 3 | John | Doe | @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.
| # | First | Last | Handle |
|---|---|---|---|
| 1 | Mark | Otto | @mdo |
| 2 | Jacob | Thornton | @fat |
| 3 | John | Doe | @social |
Small tables
Add the small prop to make any .table 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 a thicker, darker border between table groups—<thead>, <tbody>, and <tfoot>—with
.table-group-divider. Customize the color by changing the border-top-color.
| # | First | Last | Handle |
|---|---|---|---|
| 1 | Mark | Otto | @mdo |
| 2 | Jacob | Thornton | @fat |
| 3 | John | Doe | @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 | This cell inherits | This cell inherits | 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 | This cell inherits | This cell inherits | 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 | This cell inherits | 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 |
You can also put the <caption> on the top of the table with .caption-top.
| # | First | Last | Handle |
|---|---|---|---|
| 1 | Mark | Otto | @mdo |
| 2 | Jacob | Thornton | @fat |
| 3 | John | Doe | @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.
| 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 variable and Sass reference.