June 28, 2025
How to make HTML table responsive in bootstrap 4
Sometimes, when a table contains many columns, it can overflow horizontally beyond the screen width. To handle this in Bootstrap 4, we can use the .table-responsive class to make the HTML table responsive. Simply wrap the <table> element inside a <div> with the .table-responsive class. This will enable horizontal scrolling on smaller screens, ensuring the layout remains clean and user-friendly without breaking the design. An example is provided below:
Responsive table sample code
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th>#</th>
<th>Student First Name</th>
<th>Student Last Name</th>
<th>Student Email</th>
<th>Student Class</th>
<th>Student Grade</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Rama</td>
<td>Kumar</td>
<td>rama.kumar@example.com</td>
<td>4th</td>
<td>A++</td>
</tr>
</tbody>
</table>
</div>
FAQ
1. Does Bootstrap 4 support responsive HTML tables?
Yes, Bootstrap 4 provides built-in responsive table functionality through the table-responsive class. You can apply it to a wrapper element around your existing HTML table.
2. Do I need to modify my existing table HTML to make it responsive?
No, you generally do not need to change your existing table rows, headings, or data cells. Simply place your current table inside a responsive wrapper to enable horizontal scrolling on smaller devices.
3. Will a responsive Bootstrap 4 table work on mobile devices?
Yes, responsive tables work on mobile devices, including smartphones and tablets. When the table is wider than the available screen space, visitors can scroll horizontally to view the remaining columns.