Reprence Html CSS javascript PHP MySQL Bootsrap

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.

tb1

Variants

Use contextual classes to color tables, table rows or individual cells.

tb2

Accented tables

Striped rows

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

tb3

Striped columns

Use .table-striped-columns to add zebra-striping to any table column.

tb4

These classes can also be added to table variants:

tb5 tb6 tb7 tb8

Hoverable rows

Add .table-hover to enable a hover state on table rows within a .tbody>.

tb9 tb10

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

tb11

Active tables

Highlight a table row or cell by adding a .table-active class.

tb12 tb13

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:

tb14

Table borders

Bordered tables

Add .table-bordered for borders on all sides of the table and cells.

tb15

Border color utilities can be added to change colors:

tb16

Tables without borders

Add .table-borderless for a table without borders.

tb17 tb18

Small tables

Add .table-sm to make any .table more compact by cutting all cell padding in half.

tb19 tb20

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).

tb21

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.

tb22tb23tb24

Nesting

Border styles, active styles, and table variants are not inherited by nested tables.

tb25

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.

tb26tb27

Table foot

tb28

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.

tb29

You can also put the

on the top of the table with .caption-top.

tb30

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.

tb31

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.

tb32 tb33

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.