Introduction
In this write-up, we will learn about Bootstrap 4 Tables classes. Bootstrap is an open source framework to create responsive web applications. Bootstrap 4 has brought some major updates. In this blog, we will discuss the newly added table classes.
In this blog, we will cover the following classes.
- Dark Table
- Table Head Styles
- Contextual Classes
- Condensed Tables
Dark Table class
This class adds a dark background to an HTML table.
Open Visual Studio and create a new project. Rename it as Bootstrap4 Table and add the reference of the Bootstrap 4 files into the page's head section.
Add a table and add .dark-table class.
- <table class="table table-dark"> </table>
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8" />
- <title>Bootstarp 4</title>
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
- <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
- </head>
- <body>
- <div class="container">
- <h4 class="text-center">Bootstrap 4 Dark Table</h4>
- <table class="table table-dark">
- <thead>
- <tr>
- <th>Name</th>
- <th>Gender</th>
- <th>City</th>
- <th>Country</th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td>Sam</td>
- <td>Male</td>
- <td>Jaipur</td>
- <td>India</td>
- </tr>
- <tr>
- <td>Sam</td>
- <td>Male</td>
- <td>Jaipur</td>
- <td>India</td>
- </tr>
- <tr>
- <td>Sam</td>
- <td>Male</td>
- <td>Jaipur</td>
- <td>India</td>
- </tr>
- <tr>
- <td>Sam</td>
- <td>Male</td>
- <td>Jaipur</td>
- <td>India</td>
- </tr>
- </tbody>
- </table>
- </div>
- </body>
- </html>
Run the project and check the result.
Table Head Styles
These classes add style to the HTML Table header
- .thead-dark
- .thead-light
Add a table and add these header classes in the head section of the table.
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8" />
- <title>Bootstarp 4</title>
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
- <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
- </head>
- <body>
- <div class="container">
- <h4 class="text-center">Bootstrap 4 Table Head</h4>
- <table class="table">
- <thead class="thead-light">
- <tr>
- <th>Name</th>
- <th>Gender</th>
- <th>City</th>
- <th>Country</th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td>Sam</td>
- <td>Male</td>
- <td>Jaipur</td>
- <td>India</td>
- </tr>
- <tr>
- <td>Zack</td>
- <td>Male</td>
- <td>Delhi</td>
- <td>India</td>
- </tr>
- <tr>
- <td>Nisha</td>
- <td>Female</td>
- <td>Jaipur</td>
- <td>India</td>
- </tr>
- <tr>
- <td>Suresh</td>
- <td>Male</td>
- <td>Jaipur</td>
- <td>India</td>
- </tr>
- </tbody>
- </table>
- </div>
- </body>
- </html>
Run the project and check the result.

Contextual Classes
These classes add color to a table or a table row or table cells.
Following is the list of contextual classes.
- .table-dark
- table-primary
- .table-secondary
- .table-success
- .table-danger
- .table-info
- .table-warning
- .table-active
- .table-light
Now, add some divs and add these classes.
- <!DOCTYPE html>
- <html>
- <head>
- <title>Bootstrap 4</title>
- <meta charset="utf-8" />
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
- <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
- </head>
- <body>
- <div class="container">
- <h4 class="text-center">Bootstrap 4 Contextual Class</h4>
- <table class="table">
- <thead class="thead-light">
- <tr>
- <th>Name</th>
- <th>Gender</th>
- <th>City</th>
- <th>Country</th>
- </tr>
- </thead>
- <tbody>
- <tr class="table-dark">
- <td>Sam</td>
- <td>Male</td>
- <td>Jaipur</td>
- <td>India</td>
- </tr>
- <tr class="table-primary">
- <td>Sam</td>
- <td>Male</td>
- <td>Jaipur</td>
- <td>India</td>
- </tr>
- <tr class="table-secondary">
- <td>Zack</td>
- <td>Male</td>
- <td>Delhi</td>
- <td>India</td>
- </tr>
- <tr class="table-success">
- <td>Nisha</td>
- <td>Female</td>
- <td>Jaipur</td>
- <td>India</td>
- </tr>
- <tr class="table-danger">
- <td>Suresh</td>
- <td>Male</td>
- <td>Jaipur</td>
- <td>India</td>
- </tr>
- <tr class="table-info">
- <td>Aman</td>
- <td>Male</td>
- <td>Jaipur</td>
- <td>India</td>
- </tr>
- <tr class="table-warning">
- <td>Sunita</td>
- <td>Male</td>
- <td>Jaipur</td>
- <td>India</td>
- </tr>
- </tbody>
- </table>
- </div>
- </body>
- </html>
Run the project and check the result.
Summary
In this blog, we learned some important Bootstrap Table classes. I hope this will help you while designing a bootstrap-based application.

Join the conversation! Your thoughts help the community grow.