Tables

Source: https://getbootstrap.com/docs/6.0/content/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 theme-specific color classes to style tables, table rows, or individual cells. These adapt to color modes as well.

<Example code={[ &lt;table class="table"> &lt;thead> &lt;tr> &lt;th scope="col">Class&lt;/th> &lt;th scope="col">Heading&lt;/th> &lt;th scope="col">Heading&lt;/th> &lt;/tr> &lt;/thead> &lt;tbody> &lt;tr> &lt;th scope="row">Default&lt;/th> &lt;td>Cell&lt;/td> &lt;td>Cell&lt;/td> &lt;/tr>, ...getData('theme-colors').map((themeColor) => &lt;tr class="theme-${themeColor.name}"> &lt;th scope="row">${themeColor.title}&lt;/th> &lt;td>Cell&lt;/td> &lt;td>Cell&lt;/td> &lt;/tr>), &lt;/tbody> &lt;/table> ]} customMarkup={[ <!-- On tables -->, ...getData('theme-colors').map((themeColor) => <table class="table theme-${themeColor.name}">...</table>), `

<!-- On rows -->, ...getData('theme-colors').map((themeColor) =>...), \n\n <!-- On cells (`td` or `th`) --> <tr>, ...getData('theme-colors').map((themeColor) => ...),` ]} />

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.

<Example code={&lt;table class="table"> &lt;thead> &lt;tr> &lt;th scope="col">#&lt;/th> &lt;th scope="col">First&lt;/th> &lt;th scope="col">Last&lt;/th> &lt;th scope="col">Handle&lt;/th> &lt;/tr> &lt;/thead> &lt;tbody> &lt;tr class="table-active"> &lt;th scope="row">1&lt;/th> &lt;td>Mark&lt;/td> &lt;td>Otto&lt;/td> &lt;td>@mdo&lt;/td> &lt;/tr> &lt;tr> &lt;th scope="row">2&lt;/th> &lt;td>Jacob&lt;/td> &lt;td>Thornton&lt;/td> &lt;td>@fat&lt;/td> &lt;/tr> &lt;tr> &lt;th scope="row">3&lt;/th> &lt;td>John&lt;/td> &lt;td>Doe&lt;/td> &lt;td class="table-active">@social&lt;/td> &lt;/tr> &lt;/tbody> &lt;/table>} customMarkup={&lt;table class="table"> &lt;thead> ... &lt;/thead> &lt;tbody> &lt;tr class="table-active"> ... &lt;/tr> &lt;tr> ... &lt;/tr> &lt;tr> &lt;th scope="row">3&lt;/th> &lt;td>John&lt;/td> &lt;td>Doe&lt;/td> &lt;td class="table-active">@social&lt;/td> &lt;/tr> &lt;/tbody> &lt;/table>} />

<Example code={&lt;table class="table" data-bs-theme="dark"> &lt;thead> &lt;tr> &lt;th scope="col">#&lt;/th> &lt;th scope="col">First&lt;/th> &lt;th scope="col">Last&lt;/th> &lt;th scope="col">Handle&lt;/th> &lt;/tr> &lt;/thead> &lt;tbody> &lt;tr class="table-active"> &lt;th scope="row">1&lt;/th> &lt;td>Mark&lt;/td> &lt;td>Otto&lt;/td> &lt;td>@mdo&lt;/td> &lt;/tr> &lt;tr> &lt;th scope="row">2&lt;/th> &lt;td>Jacob&lt;/td> &lt;td>Thornton&lt;/td> &lt;td>@fat&lt;/td> &lt;/tr> &lt;tr> &lt;th scope="row">3&lt;/th> &lt;td>John&lt;/td> &lt;td>Doe&lt;/td> &lt;td class="table-active">@social&lt;/td> &lt;/tr> &lt;/tbody> &lt;/table>} customMarkup={&lt;table class="table" data-bs-theme="dark"> &lt;thead> ... &lt;/thead> &lt;tbody> &lt;tr class="table-active"> ... &lt;/tr> &lt;tr> ... &lt;/tr> &lt;tr> &lt;th scope="row">3&lt;/th> &lt;td>John&lt;/td> &lt;td>Doe&lt;/td> &lt;td class="table-active">@social&lt;/td> &lt;/tr> &lt;/tbody> &lt;/table>} />

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:

  • We start by setting the background of a table cell with the --bs-table-bg custom property. All table variants then set that custom property to colorize the table cells. This way, we don’t get into trouble if semi-transparent colors are used as table backgrounds.

  • Then we add an inset box shadow on the table cells with box-shadow: inset 0 0 0 9999px var(--bs-table-bg-state, var(--bs-table-bg-type, var(--bs-table-accent-bg))); to layer on top of any specified background-color. It uses custom cascade to override the box-shadow, regardless the CSS specificity. Because we use a huge spread and no blur, the color will be monotone. Since --bs-table-accent-bg is set to transparent by default, we don’t have a default box shadow.

  • When either .table-striped, .table-striped-columns, .table-hover or .table-active classes are added, either --bs-table-bg-type or --bs-table-bg-state (by default set to initial) are set to a semitransparent color (--bs-table-striped-bg, --bs-table-active-bg or --bs-table-hover-bg) to colorize the background and override default --bs-table-accent-bg.

  • For each table variant, we set --bs-table-bg-type or --bs-table-bg-state to a semi-transparent color derived from the current theme color. Those values are layered in the inset box shadow, while --bs-table-accent-bg remains a transparent fallback.

  • Text and border colors are generated the same way, and their colors are inherited by default.

Behind the scenes it looks like this:

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.

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.

<table class="table table-striped mb-0"> <thead> <tr> <th scope="col">#</th> <th scope="col">First</th> <th scope="col">Last</th> <th scope="col">Handle</th> </tr> </thead> <tbody> <tr> <th scope="row">1</th> <td>Mark</td> <td>Otto</td> <td>@mdo</td> </tr> <tr> <th scope="row">2</th> <td>Jacob</td> <td>Thornton</td> <td>@fat</td> </tr> <tr> <th scope="row">3</th> <td>John</td> <td>Doe</td> <td>@social</td> </tr> </tbody> </table> </div>} customMarkup={<div class="border rounded overflow-hidden"> <table class="table table-striped mb-0"> ... </table> </div>`} />

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.

<table class="table table-hover"> <thead> <tr> <th scope="col">#</th> <th scope="col">First</th> <th scope="col">Last</th> <th scope="col">Handle</th> </tr> </thead> <tbody> <tr> <th scope="row">1</th> <td>Mark</td> <td>Otto</td> <td>@mdo</td> </tr> <tr> <th scope="row">2</th> <td>Jacob</td> <td>Thornton</td> <td>@fat</td> </tr> <tr> <th scope="row">3</th> <td>John</td> <td>Doe</td> <td>@social</td> </tr> </tbody> </table> </div>} customMarkup={<div class="table-card"> <table class="table table-hover"> ... </table> </div>`} />

Combine it with a responsive wrapper when the table can overflow:

<table class="table table-striped"> <thead> <tr> <th scope="col">#</th> <th scope="col">Heading</th> <th scope="col">Heading</th> <th scope="col">Heading</th> <th scope="col">Heading</th> <th scope="col">Heading</th> <th scope="col">Heading</th> <th scope="col">Heading</th> <th scope="col">Heading</th> </tr> </thead> <tbody> <tr> <th scope="row">1</th> <td>Cell</td> <td>Cell</td> <td>Cell</td> <td>Cell</td> <td>Cell</td> <td>Cell</td> <td>Cell</td> <td>Cell</td> </tr> <tr> <th scope="row">2</th> <td>Cell</td> <td>Cell</td> <td>Cell</td> <td>Cell</td> <td>Cell</td> <td>Cell</td> <td>Cell</td> <td>Cell</td> </tr> <tr> <th scope="row">3</th> <td>Cell</td> <td>Cell</td> <td>Cell</td> <td>Cell</td> <td>Cell</td> <td>Cell</td> <td>Cell</td> <td>Cell</td> </tr> </tbody> </table> </div>`} />

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—<thead>, <tbody>, and <tfoot>—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).

<thead> <tr> <th scope="col">#</th> <th scope="col">First</th> <th scope="col">Last</th> <th scope="col">Handle</th> </tr> </thead> <tbody class="table-group-divider"> <tr> <th scope="row">1</th> <td>Mark</td> <td>Otto</td> <td>@mdo</td> </tr> <tr> <th scope="row">2</th> <td>Jacob</td> <td>Thornton</td> <td>@fat</td> </tr> <tr> <th scope="row">3</th> <td>John</td> <td>Doe</td> <td>@social</td> </tr> </tbody> </table>`} />

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.

<Example code={&lt;div class="table-responsive"> &lt;table class="table align-middle"> &lt;thead> &lt;tr> &lt;th scope="col" class="w-25">Heading 1&lt;/th> &lt;th scope="col" class="w-25">Heading 2&lt;/th> &lt;th scope="col" class="w-25">Heading 3&lt;/th> &lt;th scope="col" class="w-25">Heading 4&lt;/th> &lt;/tr> &lt;/thead> &lt;tbody> &lt;tr> &lt;td>This cell inherits &lt;code>vertical-align: middle;&lt;/code> from the table&lt;/td> &lt;td>This cell inherits &lt;code>vertical-align: middle;&lt;/code> from the table&lt;/td> &lt;td>This cell inherits &lt;code>vertical-align: middle;&lt;/code> from the table&lt;/td> &lt;td>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.&lt;/td> &lt;/tr> &lt;tr class="align-bottom"> &lt;td>This cell inherits &lt;code>vertical-align: bottom;&lt;/code> from the table row&lt;/td> &lt;td>This cell inherits &lt;code>vertical-align: bottom;&lt;/code> from the table row&lt;/td> &lt;td>This cell inherits &lt;code>vertical-align: bottom;&lt;/code> from the table row&lt;/td> &lt;td>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.&lt;/td> &lt;/tr> &lt;tr> &lt;td>This cell inherits &lt;code>vertical-align: middle;&lt;/code> from the table&lt;/td> &lt;td>This cell inherits &lt;code>vertical-align: middle;&lt;/code> from the table&lt;/td> &lt;td class="align-top">This cell is aligned to the top.&lt;/td> &lt;td>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.&lt;/td> &lt;/tr> &lt;/tbody> &lt;/table> &lt;/div>} customMarkup={&lt;div class="table-responsive"> &lt;table class="table align-middle"> &lt;thead> &lt;tr> ... &lt;/tr> &lt;/thead> &lt;tbody> &lt;tr> ... &lt;/tr> &lt;tr class="align-bottom"> ... &lt;/tr> &lt;tr> &lt;td>...&lt;/td> &lt;td>...&lt;/td> &lt;td class="align-top">This cell is aligned to the top.&lt;/td> &lt;td>...&lt;/td> &lt;/tr> &lt;/tbody> &lt;/table> &lt;/div>} />