Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Bootstrap5 Tables

Bootstrap5 Tables

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

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

Bootstrap5 Basic Table

In Bootstrap 5, the basic structure for creating a table is simple - just use standard HTML

elements, and add table class.

Bootstrap5 uses the .table class to style basic tables, as shown in the following example:

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

john@example.com

td

tr

<

tr

<

td

Mary

td

<

td

Moe

td

<

td

mary@example.com

td

tr

<

tr

<

td

July

td

<

td

Dooley

td

<

td

july@example.com

td

tr

tbody

table

Try it »


Striped table

By adding the .table-striped class, you will , 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

john@example.com

td

tr

<

tr

<

td

Mary

td

<

td

Moe

td

<

td

mary@example.com

td

tr

<

tr

<

td

July

td

<

td

Dooley

td

<

td

july@example.com

td

tr

tbody

table

Try it »


Bordered Table

The .table-bordered 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

john@example.com

td

tr

<

tr

<

td

Mary

td

<

td

Moe

td

<

td

mary@example.com

td

tr

<

tr

<

td

July

td

<

td

Dooley

td

<

td

july@example.com

td

tr

tbody

table

Try it »


Hover State Table

The .table-hover 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

john@example.com

td

tr

<

tr

<

td

Mary

td

<

td

Moe

td

<

td

mary@example.com

td

tr

<

tr

<

td

July

td

<

td

Dooley

td

<

td

july@example.com

td

tr

tbody

table

Try it »


Black Background Table

The .table-dark 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

john@example.com

td

tr

<

tr

<

td

Mary

td

<

td

Moe

td

<

td

mary@example.com

td

tr

<

tr

<

td

July

td

<

td

Dooley

td

<

td

july@example.com

td

tr

tbody

table

Try it »


Black Striped Table

Using the .table-dark and .table-striped classes together 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

john@example.com

td

tr

<

tr

<

td

Mary

td

<

td

Moe

td

<

td

mary@example.com

td

tr

<

tr

<

td

July

td

<

td

Dooley

td

<

td

july@example.com

td

tr

tbody

table

Try it »


Hover Effect - Black Background Table

Using the .table-dark and .table-hover classes together can set the hover effect of a black background 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

john@example.com

td

tr

<

tr

<

td

Mary

td

<

td

Moe

td

<

td

mary@example.com

td

tr

<

tr

<

td

July

td

<

td

Dooley

td

<

td

july@example.com

td

tr

tbody

table

Try it »


Borderless Table

The .table-borderless class can set a borderless table:

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

john@example.com

td

tr

<

tr

<

td

Mary

td

<

td

Moe

td

<

td

mary@example.com

td

tr

<

tr

<

td

July

td

<

td

Dooley

td

<

td

july@example.com

td

tr

tbody

table

Try it »


Meaningful Color Classes

Meaningful color classes 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

def@somemail.com

td

tr

<

tr

class

=

"

table-primary

"

<

td

Primary

td

<

td

Joe

td

<

td

joe@example.com

td

tr

<

tr

class

=

"

table-success

"

<

td

Success

td

<

td

Doe

td

<

td

john@example.com

td

tr

<

tr

class

=

"

table-danger

"

<

td

Danger

td

<

td

Moe

td

<

td

mary@example.com

td

tr

<

tr

class

=

"

table-info

"

<

td

Info

td

<

td

Dooley

td

<

td

july@example.com

td

tr

<

tr

class

=

"

table-warning

"

<

td

Warning

td

<

td

Refs

td

<

td

bo@example.com

td

tr

<

tr

class

=

"

table-active

"

<

td

Active

td

<

td

Activeson

td

<

td

act@example.com

td

tr

<

tr

class

=

"

table-secondary

"

<

td

Secondary

td

<

td

Secondson

td

<

td

sec@example.com

td

tr

<

tr

class

=

"

table-light

"

<

td

Light

td

<

td

Angie

td

<

td

angie@example.com

td

tr

<

tr

class

=

"

table-dark text-dark

"

<

td

Dark

td

<

td

Bo

td

<

td

bo@example.com

td

tr

tbody

table

Try it »

The table below lists the descriptions of table color classes:

Class Names Description
.table-primary Blue: Indicates this is an important action
.table-success Green: Indicates this is a permitted action
.table-danger Red: Indicates this is a dangerous action
.table-info Light blue: Indicates the content has changed
.table-warning Orange: Indicates an action that needs attention
.table-active Gray: Used for hover effects
.table-secondary Gray: Indicates the content is not very important
.table-light Light gray, can be the background of a table row
.table-dark Dark gray, can be the background of a table row

Table Header Colors

We can also set the color of the table header. For example, the .table-dark class adds a black background to the header, and the .table-light class adds a gray background to the 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

john@example.com

td

tr

<

tr

<

td

Mary

td

<

td

Moe

td

<

td

mary@example.com

td

tr

<

tr

<

td

July

td

<

td

Dooley

td

<

td

july@example.com

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

john@example.com

td

tr

<

tr

<

td

Mary

td

<

td

Moe

td

<

td

mary@example.com

td

tr

<

tr

<

td

July

td

<

td

Dooley

td

<

td

july@example.com

td

tr

tbody

table

Try it »


Smaller Table

The .table-sm class is used to set 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

john@example.com

td

tr

<

tr

<

td

Mary

td

<

td

Moe

td

<

td

mary@example.com

td

tr

<

tr

<

td

July

td

<

td

Dooley

td

<

td

july@example.com

td

tr

tbody

table

Try it »


Responsive table

The .table-responsive class is used to create a responsive table: a horizontal scrollbar is created when the screen width is less than 992px; if the visible area width is greater than 992px, a different effect is shown (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 »

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

Class Names 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 »