Bootstrap 4 Javascript AJAX jQuery HTML PHP Example MORE

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>

Run it Yourself »

Striped Rows

The .table-striped class adds zebra-stripes to a table:

Example

<!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>

Run it Yourself »

Bordered Table

The .table-bordered class adds borders on all sides of the table and cells:

Example

<!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>

Run it Yourself »

Hover Rows

The .table-hover class adds a hover effect (grey background color) on table rows:

Example

<!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>

Run it Yourself »

The contextual classes that can be used are:

Class Description
.table-primary Blue: Indicates an important action
.table-success Green: Indicates 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

Responsive Tables

The .table-responsive class adds a scrollbar to the table when needed (when it is too big horizontally):

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>
Run it Yourself »

The contextual classes that can be used are:

Class Screen width
.table-responsive-sm < 576px
.table-responsive-md < 768px
.table-responsive-lg < 992px
.table-responsive-xl < 1200px