Bootstrap5 Tables

Bootstrap 5's Table component provides a series of features and styles, making tables easier to build, responsive, and beautiful.

We can easily create tables with different styles, sorting functionality, pagination, and responsive layouts.

Bootstrap5 Basic Tables

In Bootstrap 5, the basic structure for creating a table is very simple; you only need to use standard HTML<table>elements, and addtablethe class.

Bootstrap5 uses the.tableclass to set the basic table style, as shown below:

Example

<table class="table"> <thead> <tr> <th>Firstname</th> <th>Lastname</th> <th>Email</th> </tr> </thead> <tbody> <tr> <td>John</td> <td>Doe</td> <td>[email protected]</td> </tr> <tr> <td>Mary</td> <td>Moe</td> <td>[email protected]</td> </tr> <tr> <td>July</td> <td>Dooley</td> <td>[email protected]</td> </tr> </tbody> </table>

Try it yourself »

Striped Table

By adding.table-stripedclass, you will<tbody>see stripes on the rows within, as shown in the example below:

Example

<table class="table table-striped"> <thead> <tr> <th>Firstname</th> <th>Lastname</th> <th>Email</th> </tr> </thead> <tbody> <tr> <td>John</td> <td>Doe</td> <td>[email protected]</td> </tr> <tr> <td>Mary</td> <td>Moe</td> <td>[email protected]</td> </tr> <tr> <td>July</td> <td>Dooley</td> <td>[email protected]</td> </tr> </tbody> </table>

Try it yourself »

Bordered Table

.table-borderedThe class can add borders to the table.

Example

<table class="table table-bordered"> <thead> <tr> <th>Firstname</th> <th>Lastname</th> <th>Email</th> </tr> </thead> <tbody> <tr> <td>John</td> <td>Doe</td> <td>[email protected]</td> </tr> <tr> <td>Mary</td> <td>Moe</td> <td>[email protected]</td> </tr> <tr> <td>July</td> <td>Dooley</td> <td>[email protected]</td> </tr> </tbody> </table>

Try it yourself »

Hover State Table

.table-hoverThe class can add a mouse hover effect (gray background) to each row of the table:

Example

<table class="table table-hover"> <thead> <tr> <th>Firstname</th> <th>Lastname</th> <th>Email</th> </tr> </thead> <tbody> <tr> <td>John</td> <td>Doe</td> <td>[email protected]</td> </tr> <tr> <td>Mary</td> <td>Moe</td> <td>[email protected]</td> </tr> <tr> <td>July</td> <td>Dooley</td> <td>[email protected]</td> </tr> </tbody> </table>

Try it yourself »

Dark Table

.table-darkThe class can add a black background to the table:

Example

<table class="table table-dark"> <thead> <tr> <th>Firstname</th> <th>Lastname</th> <th>Email</th> </tr> </thead> <tbody> <tr> <td>John</td> <td>Doe</td> <td>[email protected]</td> </tr> <tr> <td>Mary</td> <td>Moe</td> <td>[email protected]</td> </tr> <tr> <td>July</td> <td>Dooley</td> <td>[email protected]</td> </tr> </tbody> </table>

Try it yourself »

Dark Striped Table

Combining.table-darkand.table-stripedclasses can create a black striped table:

Example

<table class="table table-dark table-striped"> <thead> <tr> <th>Firstname</th> <th>Lastname</th> <th>Email</th> </tr> </thead> <tbody> <tr> <td>John</td> <td>Doe</td> <td>[email protected]</td> </tr> <tr> <td>Mary</td> <td>Moe</td> <td>[email protected]</td> </tr> <tr> <td>July</td> <td>Dooley</td> <td>[email protected]</td> </tr> </tbody> </table>

Try it yourself »

Hover Effect - Dark Table

Combining.table-darkand.table-hoverclasses can set the mouse hover effect on a dark table:

Example

<table class="table table-dark table-hover"> <thead> <tr> <th>Firstname</th> <th>Lastname</th> <th>Email</th> </tr> </thead> <tbody> <tr> <td>John</td> <td>Doe</td> <td>[email protected]</td> </tr> <tr> <td>Mary</td> <td>Moe</td> <td>[email protected]</td> </tr> <tr> <td>July</td> <td>Dooley</td> <td>[email protected]</td> </tr> </tbody> </table>

Try it yourself »

Borderless Table

.table-borderlessThe class can create a table without borders:

Example

<table class="table table-borderless"> <thead> <tr> <th>Firstname</th> <th>Lastname</th> <th>Email</th> </tr> </thead> <tbody> <tr> <td>John</td> <td>Doe</td> <td>[email protected]</td> </tr> <tr> <td>Mary</td> <td>Moe</td> <td>[email protected]</td> </tr> <tr> <td>July</td> <td>Dooley</td> <td>[email protected]</td> </tr> </tbody> </table>

Try it yourself »

Contextual Color Classes

Through contextual color classes, you can set colors for table rows or cells:

Example

<table class="table"> <thead> <tr> <th>Firstname</th> <th>Lastname</th> <th>Email</th> </tr> </thead> <tbody> <tr> <td>Default</td> <td>Defaultson</td> <td>[email protected]</td> </tr> <tr class="table-primary"> <td>Primary</td> <td>Joe</td> <td>[email protected]</td> </tr> <tr class="table-success"> <td>Success</td> <td>Doe</td> <td>[email protected]</td> </tr> <tr class="table-danger"> <td>Danger</td> <td>Moe</td> <td>[email protected]</td> </tr> <tr class="table-info"> <td>Info</td> <td>Dooley</td> <td>[email protected]</td> </tr> <tr class="table-warning"> <td>Warning</td> <td>Refs</td> <td>[email protected]</td> </tr> <tr class="table-active"> <td>Active</td> <td>Activeson</td> <td>[email protected]</td> </tr> <tr class="table-secondary"> <td>Secondary</td> <td>Secondson</td> <td>[email protected]</td> </tr> <tr class="table-light"> <td>Light</td> <td>Angie</td> <td>[email protected]</td> </tr> <tr class="table-dark text-dark"> <td>Dark</td> <td>Bo</td> <td>[email protected]</td> </tr> </tbody> </table>

Try it yourself »

The table below lists the descriptions of the table color classes:

Class Name Description
.table-primary Blue: Indicates an important operation
.table-success Green: Indicates an operation that is allowed to perform
.table-danger Red: Indicates a dangerous operation
.table-info Light blue: Indicates content has changed
.table-warning Orange: Indicates an operation that needs attention
.table-active Gray: Used for the mouse hover effect
.table-secondary Gray: Indicates content is not very important
.table-light Light gray: Can be the background of table rows
.table-dark Dark gray: Can be the background of table rows

Table Head Colors

We can also set the color of the table header, for example.table-darkthe class is used to add a black background to the table header,.table-lightthe class is used to add a gray background to the table header:

Example

<table class="table"> <thead class="table-dark"> <tr> <th>Firstname</th> <th>Lastname</th> <th>Email</th> </tr> </thead> <tbody> <tr> <td>John</td> <td>Doe</td> <td>[email protected]</td> </tr> <tr> <td>Mary</td> <td>Moe</td> <td>[email protected]</td> </tr> <tr> <td>July</td> <td>Dooley</td> <td>[email protected]</td> </tr> </tbody> </table> <table class="table"> <thead class="table-light"> <tr> <th>Firstname</th> <th>Lastname</th> <th>Email</th> </tr> </thead> <tbody> <tr> <td>John</td> <td>Doe</td> <td>[email protected]</td> </tr> <tr> <td>Mary</td> <td>Moe</td> <td>[email protected]</td> </tr> <tr> <td>July</td> <td>Dooley</td> <td>[email protected]</td> </tr> </tbody> </table>

Try it yourself »

Small Table

.table-smThe class is used to create a smaller table by reducing padding:

Example

<table class="table table-bordered table-sm"> <thead> <tr> <th>Firstname</th> <th>Lastname</th> <th>Email</th> </tr> </thead> <tbody> <tr> <td>John</td> <td>Doe</td> <td>[email protected]</td> </tr> <tr> <td>Mary</td> <td>Moe</td> <td>[email protected]</td> </tr> <tr> <td>July</td> <td>Dooley</td> <td>[email protected]</td> </tr> </tbody> </table>

Try it yourself »

Responsive Tables

.table-responsiveThe class is used to create responsive tables: when the screen width is less than 992px, a horizontal scrollbar is created; if the viewport width is greater than 992px, a different effect is displayed (no scrollbar):

Example

<div class="table-responsive"> <table class="table"> <thead> <tr> <th>#</th> <th>Firstname</th> <th>Lastname</th> <th>Age</th> <th>City</th> <th>Country</th> <th>Sex</th> <th>Example</th> <th>Example</th> <th>Example</th> <th>Example</th> </tr> </thead> <tbody> <tr> <td>1</td> <td>Anna</td> <td>Pitt</td> <td>35</td> <td>New York</td> <td>USA</td> <td>Female</td> <td>Yes</td> <td>Yes</td> <td>Yes</td> <td>Yes</td> </tr> </tbody> </table> </div>

Try it Yourself »

You can use the following classes to display scrollbars at specified screen widths:

Class name Screen width
.table-responsive-sm < 576px
.table-responsive-md < 768px
.table-responsive-lg < 992px
.table-responsive-xl < 1200px
.table-responsive-xxl < 1400px

Example

<div class="table-responsive-sm"> <table class="table"> ... </table> </div>

Try it Yourself »
Other extensions