Bootstrap 5 can offer several enhancements to an otherwise ordinary HTML table. A basic Bootstrap 5 enhanced table gives the table a light padding, horizontal dividers, and preset sizing styles.
The .table
class is added to a table element to add basic Bootstrap 5 styling:
<!DOCTYPE html>
<html lang ="en" >
<head >
<title >Bootstrap 5 Color Example </title >
<meta charset ="utf-8" >
<meta name ="viewport" content ="width=device-width, initial-scale=1" >
<link href ="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel ="stylesheet" >
<script src ="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" ></script >
</head >
<body >
<div class ="container mt-3" >
<table class ="table" >
<thead >
<tr >
<th >First Name </th >
<th >Last Name </th >
<th >Email </th >
</tr >
</thead >
<tbody >
<tr >
<td >John </td >
<td >Doe </td >
<td >JD@home.net </td >
</tr >
<tr >
<td >Bugs </td >
<td >Bunny </td >
<td >Bugs@example.com </td >
</tr >
<tr >
<td >Bruce </td >
<td >Wayne </td >
<td >Batman@justiceleague.com </td >
</tr >
</tbody >
</table >
</div >
</body >
</html >
First Name | Last Name | |
---|---|---|
John | Doe | JD@home.net |
Bugs | Bunny | Bugs@example.com |
Bruce | Wayne | Batman@justiceleague.com |
The .table-striped
class adds zebra-stripes to a table, meaning that the background color of the table rows alternate between light and dark:
<!DOCTYPE html>
<html lang ="en" >
<head >
<title >Bootstrap 5 Color Example </title >
<meta charset ="utf-8" >
<meta name ="viewport" content ="width=device-width, initial-scale=1" >
<link href ="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel ="stylesheet" >
<script src ="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" ></script >
</head >
<body >
<div class ="container mt-3" >
<table class ="table table-striped" >
<thead >
<tr >
<th >First Name </th >
<th >Last Name </th >
<th >Email </th >
</tr >
</thead >
<tbody >
<tr >
<td >John </td >
<td >Doe </td >
<td >JD@home.net </td >
</tr >
<tr >
<td >Bugs </td >
<td >Bunny </td >
<td >Bugs@example.com </td >
</tr >
<tr >
<td >Bruce </td >
<td >Wayne </td >
<td >Batman@justiceleague.com </td >
</tr >
</tbody >
</table >
</div >
</body >
</html >
First Name | Last Name | |
---|---|---|
John | Doe | JD@home.net |
Bugs | Bunny | Bugs@example.com |
Bruce | Wayne | Batman@justiceleague.com |
The .table-bordered
class adds thin visible borders (horizontal and vertical) on all sides of the table and cells:
<!DOCTYPE html>
<html lang ="en" >
<head >
<title >Bootstrap 5 Color Example </title >
<meta charset ="utf-8" >
<meta name ="viewport" content ="width=device-width, initial-scale=1" >
<link href ="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel ="stylesheet" >
<script src ="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" ></script >
</head >
<body >
<div class ="container mt-3" >
<table class ="table table-bordered" >
<thead >
<tr >
<th >First Name </th >
<th >Last Name </th >
<th >Email </th >
</tr >
</thead >
<tbody >
<tr >
<td >John </td >
<td >Doe </td >
<td >JD@home.net </td >
</tr >
<tr >
<td >Bugs </td >
<td >Bunny </td >
<td >Bugs@example.com </td >
</tr >
<tr >
<td >Bruce </td >
<td >Wayne </td >
<td >Batman@justiceleague.com </td >
</tr >
</tbody >
</table >
</div >
</body >
</html >
First Name | Last Name | |
---|---|---|
John | Doe | JD@home.net |
Bugs | Bunny | Bugs@example.com |
Bruce | Wayne | Batman@justiceleague.com |
The .table-hover
class adds a hover effect to the table rows, so that if someone moves their mouse pointer over a table row then it will highlight itself by temporarily changing that table rows background color to grey:
<!DOCTYPE html>
<html lang ="en" >
<head >
<title >Bootstrap 5 Color Example </title >
<meta charset ="utf-8" >
<meta name ="viewport" content ="width=device-width, initial-scale=1" >
<link href ="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel ="stylesheet" >
<script src ="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" ></script >
</head >
<body >
<div class ="container mt-3" >
<table class ="table table-hover" >
<thead >
<tr >
<th >First Name </th >
<th >Last Name </th >
<th >Email </th >
</tr >
</thead >
<tbody >
<tr >
<td >John </td >
<td >Doe </td >
<td >JD@home.net </td >
</tr >
<tr >
<td >Bugs </td >
<td >Bunny </td >
<td >Bugs@example.com </td >
</tr >
<tr >
<td >Bruce </td >
<td >Wayne </td >
<td >Batman@justiceleague.com </td >
</tr >
</tbody >
</table >
</div >
</body >
</html >
First Name | Last Name | |
---|---|---|
John | Doe | JD@home.net |
Bugs | Bunny | Bugs@example.com |
Bruce | Wayne | Batman@justiceleague.com |
The .table-dark
class adds a black background to the table and changes the text color to white:
<!DOCTYPE html>
<html lang ="en" >
<head >
<title >Bootstrap 5 Color Example </title >
<meta charset ="utf-8" >
<meta name ="viewport" content ="width=device-width, initial-scale=1" >
<link href ="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel ="stylesheet" >
<script src ="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" ></script >
</head >
<body >
<div class ="container mt-3" >
<table class ="table table-dark" >
<thead >
<tr >
<th >First Name </th >
<th >Last Name </th >
<th >Email </th >
</tr >
</thead >
<tbody >
<tr >
<td >John </td >
<td >Doe </td >
<td >JD@home.net </td >
</tr >
<tr >
<td >Bugs </td >
<td >Bunny </td >
<td >Bugs@example.com </td >
</tr >
<tr >
<td >Bruce </td >
<td >Wayne </td >
<td >Batman@justiceleague.com </td >
</tr >
</tbody >
</table >
</div >
</body >
</html >
First Name | Last Name | |
---|---|---|
John | Doe | JD@home.net |
Bugs | Bunny | Bugs@example.com |
Bruce | Wayne | Batman@justiceleague.com |
The .table-borderless
class removes all visible borders from the table and cells:
<!DOCTYPE html>
<html lang ="en" >
<head >
<title >Bootstrap 5 Color Example </title >
<meta charset ="utf-8" >
<meta name ="viewport" content ="width=device-width, initial-scale=1" >
<link href ="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel ="stylesheet" >
<script src ="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" ></script >
</head >
<body >
<div class ="container mt-3" >
<table class ="table table-borderless" >
<thead >
<tr >
<th >First Name </th >
<th >Last Name </th >
<th >Email </th >
</tr >
</thead >
<tbody >
<tr >
<td >John </td >
<td >Doe </td >
<td >JD@home.net </td >
</tr >
<tr >
<td >Bugs </td >
<td >Bunny </td >
<td >Bugs@example.com </td >
</tr >
<tr >
<td >Bruce </td >
<td >Wayne </td >
<td >Batman@justiceleague.com </td >
</tr >
</tbody >
</table >
</div >
</body >
</html >
First Name | Last Name | |
---|---|---|
John | Doe | JD@home.net |
Bugs | Bunny | Bugs@example.com |
Bruce | Wayne | Batman@justiceleague.com |
The Contextual Colors classes can be used to color the entire table (<table>
), the table rows (<tr>
), or the table cells (<td>
):
<!DOCTYPE html>
<html lang ="en" >
<head >
<title >Bootstrap 5 Color Example </title >
<meta charset ="utf-8" >
<meta name ="viewport" content ="width=device-width, initial-scale=1" >
<link href ="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel ="stylesheet" >
<script src ="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" ></script >
</head >
<body >
<div class ="container mt-3" >
<table class ="table" >
<thead >
<tr >
<th >First Name </th >
<th >Last Name </th >
<th >Email </th >
</tr >
</thead >
<tbody >
<tr >
<td >John </td >
<td >Doe </td >
<td >JD@home.net </td >
</tr >
<tr class ="table-primary" >
<td >Bugs </td >
<td >Bunny </td >
<td >Bugs@example.com </td >
</tr >
<tr class ="table-success" >
<td >Bruce </td >
<td >Wayne </td >
<td >Batman@justiceleague.com </td >
</tr >
</tbody >
</table >
</div >
</body >
</html >
First Name | Last Name | |
---|---|---|
John | Doe | JD@home.net |
Bugs | Bunny | Bugs@example.com |
Bruce | Wayne | Batman@justiceleague.com |
The .table-responsive
class adds scrollbars to the table when needed, so that larger tables fit the page instead of the page size being changed to include the table. However, unlike the other table classes, the .table-responsive
class is added to a <div>
element which is then wrapped around a table element:
<!DOCTYPE html>
<html lang ="en" >
<head >
<title >Bootstrap 5 Color Example </title >
<meta charset ="utf-8" >
<meta name ="viewport" content ="width=device-width, initial-scale=1" >
<link href ="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel ="stylesheet" >
<script src ="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" ></script >
</head >
<body >
<div class ="container mt-3" >
<div class ="table-responsive" >
<table class ="table table-bordered" >
<thead >
<tr >
<th >First Name </th >
<th >Last Name </th >
<th >Email </th >
<th >Example </th >
<th >Example </th >
<th >Example </th >
<th >Example </th >
<th >Example </th >
<th >Example </th >
<th >Example </th >
<th >Example </th >
<th >Example </th >
<th >Example </th >
<th >Example </th >
<th >Example </th >
<th >Example </th >
<th >Example </th >
<th >Example </th >
</tr >
</thead >
<tbody >
<tr >
<td >John </td >
<td >Doe </td >
<td >JD@home.net </td >
<td >Yes </td >
<td >No </td >
<td >Yes </td >
<td >No </td >
<td >Yes </td >
<td >No </td >
<td >Yes </td >
<td >No </td >
<td >Yes </td >
<td >No </td >
<td >Yes </td >
<td >No </td >
<td >Yes </td >
<td >No </td >
<td >Yes </td >
</tr >
<tr >
<td >Bugs </td >
<td >Bunny </td >
<td >Bugs@example.com </td >
<td >Yes </td >
<td >No </td >
<td >Yes </td >
<td >No </td >
<td >Yes </td >
<td >No </td >
<td >Yes </td >
<td >No </td >
<td >Yes </td >
<td >No </td >
<td >Yes </td >
<td >No </td >
<td >Yes </td >
<td >No </td >
<td >Yes </td >
</tr >
<tr >
<td >Bruce </td >
<td >Wayne </td >
<td >Batman@justiceleague.com </td >
<td >Yes </td >
<td >No </td >
<td >Yes </td >
<td >No </td >
<td >Yes </td >
<td >No </td >
<td >Yes </td >
<td >No </td >
<td >Yes </td >
<td >No </td >
<td >Yes </td >
<td >No </td >
<td >Yes </td >
<td >No </td >
<td >Yes </td >
</tr >
</tbody >
</table >
</div >
</div >
</body >
</html >
First Name | Last Name | Example | Example | Example | Example | Example | Example | Example | Example | Example | Example | Example | Example | Example | Example | Example | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
John | Doe | JD@home.net | Yes | No | Yes | No | Yes | No | Yes | No | Yes | No | Yes | No | Yes | No | Yes |
Bugs | Bunny | Bugs@example.com | Yes | No | Yes | No | Yes | No | Yes | No | Yes | No | Yes | No | Yes | No | Yes |
Bruce | Wayne | Batman@justiceleague.com | Yes | No | Yes | No | Yes | No | Yes | No | Yes | No | Yes | No | Yes | No | Yes |
What is even more helpful is that multiple table classes can be used at the same time on the same table.
Thank you for reading, I hope you found this blog post (tutorial) educational and helpful.
About | Contact Us | Privacy | Terms & Conditions | © 2024 - T&J Divisions, LLC, All Rights Reserved |