Tables in Bootstrap
In Bootstrap we can easily design our table just by implementing the class of table.
Let’s understand these class:-
The .table class adds only basic style in table .
Let’s understand this by following program
<!DOCTYPE html>
<html lang="en">
<head>
<title> bootstrap 4 Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body>
<div class="container">
<h2>Basic Table</h2>
<table class="table">
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Rollno</th>
</tr>
</thead>
<tbody>
<tr>
<td>suman</td>
<td>Rani</td>
<td>22</td>
</tr>
<tr>
<td>kiran</td>
<td>Rani</td>
<td>28</td>
</tr>
<tr>
<td>Neelam</td>
<td>Rani</td>
<td>29</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
</div>
Output of this Program
So here so easily we have created our basic table .
The .table-bordered class adds border in the table .
Let’s understand this by following program
<!DOCTYPE html>
<html lang="en">
<head>
<title> bootstrap 4 Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body>
<div class="container">
<h2>Striped Rows</h2>
<table class="table table-bordered">
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Rollno</th>
</tr>
</thead>
<tbody>
<tr>
<td>suman</td>
<td>Rani</td>
<td>22</td>
</tr>
<tr>
<td>kiran</td>
<td>Rani</td>
<td>28</td>
</tr>
<tr>
<td>Neelam</td>
<td>Rani</td>
<td>29</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
Output of this Program
Here by .table-bordered we get border in our table
The .table-striped class adds border in the table .
Let’s understand this by following program
<!DOCTYPE html>
<html lang="en">
<head>
<title> bootstrap 4 Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body>
<div class="container">
<h2>Striped Rows</h2>
<table class="table table-striped">
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Rollno</th>
</tr>
</thead>
<tbody>
<tr>
<td>suman</td>
<td>Rani</td>
<td>22</td>
</tr>
<tr>
<td>kiran</td>
<td>Rani</td>
<td>28</td>
</tr>
<tr>
<td>Neelam</td>
<td>Rani</td>
<td>29</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
Output of this Program
The .table-dark class adds border in the table .
Let’s understand this by following program
<!DOCTYPE html>
<html lang="en">
<head>
<title> bootstrap 4 Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body>
<div class="container">
<h2>Black/Dark Table</h2>
<table class="table table-dark">
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Rollno</th>
</tr>
</thead>
<tbody>
<tr>
<td>suman</td>
<td>Rani</td>
<td>22</td>
</tr>
<tr>
<td>kiran</td>
<td>Rani</td>
<td>28</td>
</tr>
<tr>
<td>Neelam</td>
<td>Rani</td>
<td>29</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
Output of this Program
Name | Description |
.table-striped | Adds Zebra stripes on table rows |
.table-hover | Adds hover effect on table rows |
.table-dark | Adds black background to table |
.table-primary | Blue color indicating an important action |
.table-success | Green color indicating a successful or positive action |
.table-danger | Red: Indicates a dangerous or potentially negative action |
.table-info | Light blue: Indicates a neutral informative change or action |
.table-warning | Orange: Indicates a warning that might need attention |
.table-active | Grey: Applies the hover color to the table row or table cell |
.table-secondary | Grey: Indicates a slightly less important action |
.table-light | Light grey table or table row background |
.table-dark | Dark grey table or table row background |