How To Create A Responsive Bootstrap Table

A Bootstrap table is basically an HTML table, which is responsive – it adjusts itself on all the screen sizes (desktops to smartphones). Thus, whatever is the screen size of Bootstrap table, it will automatically adjust itself and you don’t have to worry for anything. In this table, you can create any number of columns and any number of rows, which depends upon your needs.

To use a Bootstrap table in your Website, you should know how to use Bootstrap in your Website. This also includes the knowledge of Bootstrap grid system.

Thus, let me start with creating Bootstrap tables.

Where to put Bootstrap table in your Website 

 You have to place the Bootstrap table inside any column, where you want to show it. The column can be .col-xs-*, .col-sm-*, .col-md-* or .col-lg-*. 

Bootstrap table code

Bootstrap table is given below, which has 1 column and 1 row in it.

  1. <div class="table-responsive">  
  2.      <table class="table">  
  3.           <thead>  
  4.               <tr>  
  5.                   <th>Column 1</th>  
  6.               </tr>  
  7.           </thead>  
  8.           <tbody>  
  9.               <tr>  
  10.                   <td>Row 1</td>  
  11.                </tr>  
  12.           </tbody>  
  13.     </table>  
  14. </div>  

Now, let us create Bootstrap table of 1 column and 3 rows. 

  1. <div class="table-responsive">  
  2.     <table class="table">  
  3.         <thead>  
  4.             <tr>  
  5.                 <th>Column 1</th>  
  6.             </tr>  
  7.         </thead>  
  8.         <tbody>  
  9.             <tr>  
  10.                 <td>Row 1</td>  
  11.             </tr>  
  12.             <tr>  
  13.                 <td>Row 2</td>  
  14.             </tr>  
  15.             <tr>  
  16.                 <td>Row 3</td>  
  17.             </tr>  
  18.         </tbody>  
  19.     </table>  
  20. </div>  

Similarly, a Bootstrap table of 3 columns and 3 rows will be, as shown below.

  1. <div class="table-responsive">  
  2.     <table class="table">  
  3.         <thead>  
  4.             <tr>  
  5.                 <th>Column 1</th>  
  6.                 <th>Column 2</th>  
  7.                 <th>Column 3</th>  
  8.             </tr>  
  9.         </thead>  
  10.         <tbody>  
  11.             <tr>  
  12.                 <td>Row 1 Column 1</td>  
  13.                 <td>Row 1 Column 2</td>  
  14.                 <td>Row 1 Column 3</td>  
  15.             </tr>  
  16.             <tr>  
  17.                 <td>Row 2 Column 1</td>  
  18.                 <td>Row 2 Column 2</td>  
  19.                 <td>Row 2 Column 3</td>  
  20.             </tr>  
  21.             <tr>  
  22.                 <td>Row 3 Column 1</td>  
  23.                 <td>Row 3 Column 2</td>  
  24.                 <td>Row 3 Column 3</td>  
  25.             </tr>  
  26.         </tbody>  
  27.     </table>  
  28. </div>  
Let’s make a bigger table, which contains 5 columns and 4 rows. 
  1. <div class="table-responsive">  
  2.     <table class="table">  
  3.         <thead>  
  4.             <tr>  
  5.                 <th>Column 1</th>  
  6.                 <th>Column 2</th>  
  7.                 <th>Column 3</th>  
  8.                 <th>Column 4</th>  
  9.                 <th>Column 5</th>  
  10.             </tr>  
  11.         </thead>  
  12.         <tbody>  
  13.             <tr>  
  14.                 <td>Row 1 Column 1</td>  
  15.                 <td>Row 1 Column 2</td>  
  16.                 <td>Row 1 Column 3</td>  
  17.                 <td>Row 1 Column 4</td>  
  18.                 <td>Row 1 Column 5</td>  
  19.             </tr>  
  20.             <tr>  
  21.                 <td>Row 2 Column 1</td>  
  22.                 <td>Row 2 Column 2</td>  
  23.                 <td>Row 2 Column 3</td>  
  24.                 <td>Row 2 Column 4</td>  
  25.                 <td>Row 2 Column 5</td>  
  26.             </tr>  
  27.             <tr>  
  28.                 <td>Row 3 Column 1</td>  
  29.                 <td>Row 3 Column 2</td>  
  30.                 <td>Row 3 Column 3</td>  
  31.                 <td>Row 3 Column 4</td>  
  32.                 <td>Row 3 Column 5</td>  
  33.             </tr>  
  34.             <tr>  
  35.                 <td>Row 4 Column 1</td>  
  36.                 <td>Row 4 Column 2</td>  
  37.                 <td>Row 4 Column 3</td>  
  38.                 <td>Row 4 Column 4</td>  
  39.                 <td>Row 4 Column 5</td>  
  40.             </tr>  
  41.         </tbody>  
  42.     </table>  
  43. </div>  

Testing Bootstrap Table Responsive feature

 
All the tables which I have created will look full size on the big screen of laptops and desktops but on smaller size screens of the tablets and smartphones, the columns will have horizontal scrolling.

On laptops and desktops

On laptops and desktops, all the 4 tables will be fully visible.

 

On tablets

On tablets, the screens of all the 4 tables will be fully visible.

 

On smartphones

On smartphones screens (including all iphones 4 to 8 and Galaxy’s) the top 2 tables will be fully visible while the other 2 columns will have horizontal scrolling.

 
 
Summary

In this way, you can create responsive tables in Bootstrap and show your text in grid form. If you have any questions, please ask me. Thank you. 

Ebook Download
View all
CSS by AI
Read by 3 people
Download Now!
Learn
View all