Hello Devs,
In this tutorial, we will learn How to create Tables Bootstrap 4
Basic Table:
The .table class adds basic styling to a table:
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Basic Table Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h2>Basic Table</h2>
<p>The .table class adds basic styling (light padding and horizontal dividers) to a table:</p>
<table class="table">
<thead>
<tr>
<th>id</th>
<th>Name</th>
<th>Roll No</th>
</tr>
</thead>
<tr>
<td>1</td>
<td>John Doe</td>
<td>1225</td>
</tr>
<tr>
<td>2</td>
<td>Mary Moe</td>
<td>1226</td>
</tr>
<tr>
<td>3</td>
<td>July Dooley</td>
<td>1227</td>
</tr>
</table>
</div>
</body>
</html>
Striped Rows:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Striped Rows</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h2>Striped Rows</h2>
<p>The .table-striped class adds zebra-stripes to a table:</p>
<table class="table table-striped">
<thead>
<tr>
<th>id</th>
<th>Name</th>
<th>Roll No</th>
</tr>
</thead>
<tr>
<td>1</td>
<td>John Doe</td>
<td>1225</td>
</tr>
<tr>
<td>2</td>
<td>Mary Moe</td>
<td>1226</td>
</tr>
<tr>
<td>3</td>
<td>July Dooley</td>
<td>1227</td>
</tr>
</table>
</div>
</body>
</html>
Bordered Table:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Bordered Table Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h2>Bordered Table</h2>
<p>The .table-bordered class adds borders on all sides of the table and the cells:</p>
<table class="table table-bordered">
<thead>
<tr>
<th>id</th>
<th>Name</th>
<th>Roll No</th>
</tr>
</thead>
<tr>
<td>1</td>
<td>John Doe</td>
<td>1225</td>
</tr>
<tr>
<td>2</td>
<td>Mary Moe</td>
<td>1226</td>
</tr>
<tr>
<td>3</td>
<td>July Dooley</td>
<td>1227</td>
</tr>
</table>
</div>
</body>
</html>
Hover Rows:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Hover Rows Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h2>Hover Rows</h2>
<p>The .table-hover class enables a hover state (grey background on mouse over) on table rows:</p>
<table class="table table-bordered table-hover">
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Roll No</th>
</tr>
</thead>
<tr>
<td>Alen</td>
<td>john@example.com</td>
<td>2400</td>
</tr>
<tr>
<td>sanjiv</td>
<td>mary@example.com</td>
<td>2401</td>
</tr>
<tr>
<td>July</td>
<td>july@example.com</td>
<td>2402</td>
</tr>
</table>
</div>
</body>
</html>
Responsive Tables:
Example
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Responsive Table Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h2>Responsive Table</h2>
<div class="table-responsive">
<table class="table table-bordered">
<thead>
<tr>
<th>#</th>
<th>name</th>
<th>Email</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>
<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>1</td>
<td>sakil Pitt</td>
<td>sakil@gmail.com</td>
<td>35</td>
<td>New York</td>
<td>USA</td>
<td>Male</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
</tr>
</tbody>
</table>
</div>
</div>
</body>
</html>
May this example help you.