We can create different types of Bootstrap tables by using different classes to style them.
Bootstrap Basic Table:
The basic Bootstrap table has a light padding and only horizontal dividers. The .table class is used to add basic styling to a table.
Bootstrap Striped Rows Table:
The .table-striped class is used to add zebra-stripes to a table:
Bootstrap Bordered table:
The .table-bordered class is used to add borders on all sides of the table and cells:
Bootstrap Hover rows Table:
The .table-hover class is used to enable a hover state on table rows:
Bootstrap Condensed table:
The .table-condensed class is used to make a table more compact by cutting cell padding in half:
Bootstrap Contextual classes:.
Contextual classes are used to color table rows (<tr>) or table cells (<td>):
Following are the different contextual classes:
|It is used to apply the hover color to the table row or table cell
|It indicates a successful or positive action
|It indicates a neutral informative change or action
|It specifies a warning that might need attention
|It indicates a dangerous or potentially negative action
The .table-responsive class is used to create a responsive table. You can open the responsible table even on small devices (under 768px). Then the table will be scrolled horizontally. Displays larger than 768px wide, there is no difference.
See this example:
Some newly added tables in Bootstrap 4:
The .table-dark class is used to add a black background to the table:
Dark Striped Table
Combine the .table-dark class and .table-striped class to create a dark, striped table:
Hoverable Dark Table
The .table-hover class is used to add a hover effect (grey background color) on table rows:
Bootstrap 4 Contextual Table
Contextual classes can be used to color the whole table (<table>), the table rows (<tr>) or table cells (<td>).
The classes that can be used are:
.table-primary, .table-success, .table-info, .table-warning, .table-danger, .table-active, .table-secondary, .table-light and .table-dark:
Let's take an example to see the usage of all contextual classes in a Bootstrap 4 table.
Table Head Colors
You can change the background color of the table header by using .thead-dark class to add a black background to table headers, and the .thead-light class to add a grey background to table headers.
The .table-sm class is used to make the table smaller by cutting cell padding in half.