How to align a table in center using bootstrap?

Hi Friends 👋,

Welcome To aGuideHub! ❤️

Today, I am going to show you. How to align a table in center using bootstrap with code example.

Here, we will use .table class to make a text in center.

Let’s look at the following example to understand how it basically works:

We add this class to the html tag:

<!doctype html>
<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">

    <title>How to Align Responsive Image in Center in Bootstrap</title>

    <style type="text/css">
      .table {
          margin: 0 auto;
          width: 80%;
      }
       
 </style>
      
  </head>
  <body>

    <div class="container">
      <table class="table table-striped table-hover">
          <thead>
              <tr>
                  <th>#</th>
                  <th>Name</th>
                  <th>Customer-ID</th>
                  <th>Email</th>
              </tr>
          </thead>
          <tbody>
              <tr>
                  <td>1</td>
                  <td>Arush</td>
                  <td>AUSXYZ1481</td>
                  <td>[email protected]</td>
              </tr>
              <tr>
                  <td>2</td>
                  <td>Gita</td>
                  <td>AUSXYZ2932</td>
                  <td>[email protected]</td>
              </tr>
              <tr>
                  <td>3</td>
                  <td>Ashtha</td>
                  <td>AUSXYZ6381</td>
                  <td>[email protected]</td>
              </tr>
              <tr>
                  <td>4</td>
                  <td>Viraj</td>
                  <td>AUSXYZ7264</td>
                  <td>[email protected]</td>
              </tr>
              <tr>
                  <td>5</td>
                  <td>Ayush</td>
                  <td>AUSXYZ8330</td>
                  <td>[email protected]</td>
              </tr>
          </tbody>
      </table>
  </div>

    <!-- Bootstrap Bundle with Popper -->
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>

  </body>
</html>

In the above code, we have used .table method to align image in center .of div

Check the output of the above code example.

Bootstrap, Table

All the best 👍