Performance: Responsive tables
Responsive tables affect page load speed and rendering performance by controlling how table data adapts to different screen sizes without causing layout shifts or excessive reflows.
<div class="table-responsive"> <table class="table"> <thead> <tr><th>Name</th><th>Email</th><th>Phone</th><th>Address</th></tr> </thead> <tbody> <tr><td>John</td><td>john@example.com</td><td>123-456</td><td>123 Street</td></tr> <!-- many rows --> </tbody> </table> </div>
<table class="table"> <thead> <tr><th>Name</th><th>Email</th><th>Phone</th><th>Address</th></tr> </thead> <tbody> <tr><td>John</td><td>john@example.com</td><td>123-456</td><td>123 Street</td></tr> <!-- many rows --> </tbody> </table>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Table overflow without container | Low | Multiple on resize | High due to layout shifts | [X] Bad |
| Table inside .table-responsive container | Low | Single on load | Low, smooth scrolling | [OK] Good |
| Changing table cells to block on small screens | High | N reflows (N=cells) | High paint cost | [X] Bad |
| Using horizontal scroll with nowrap inside container | Low | Single reflow | Low paint cost | [OK] Good |
div with the class table-responsive in Bootstrap?table-responsivetable-responsive class wraps the table and adds horizontal scrolling on smaller screens.table-bordered or CSS, not table-responsive.table-responsive enables horizontal scroll [OK]table-responsive with styling classes<table> inside a <div> with class table-responsive.<div class='table-responsive'><table class='table'>...</table></div> correctly wraps the table inside div.table-responsive. The other options use incorrect class names or attributes.div.table-responsive [OK]div.table-responsive for responsiveness [OK]table-responsive directly to tableresponsive-table<div class='table-responsive'>
<table class='table table-striped'>
<thead>
<tr><th>Name</th><th>Age</th></tr>
</thead>
<tbody>
<tr><td>Alice</td><td>30</td></tr>
<tr><td>Bob</td><td>25</td></tr>
</tbody>
</table>
</div>table-responsive behaviortable-responsive wrapper adds horizontal scrolling on small screens if the table is wider than the viewport.<table class='table table-bordered'>
<thead>
<tr><th>Product</th><th>Price</th></tr>
</thead>
<tbody>
<tr><td>Book</td><td>$10</td></tr>
</tbody>
</table>div.table-responsive wrapper that enables horizontal scrolling on small screens.table-responsive class directly to table or replacing table-bordered is incorrect. Inline styles on table won't work properly for responsiveness.div with class table-responsive -> Option Cdiv.table-responsive for scroll [OK]div.table-responsive for scrolling [OK]table-responsive class to table instead of wrappertable instead of wrappertable-responsive-sm, table-responsive-md, etc., which enable horizontal scrolling below the specified breakpoint.table-responsive-md. This means scrolling activates below the medium breakpoint.table-responsive-md -> Option Atable-responsive-md for scroll below medium screens [OK]-md for responsive scroll [OK]table-responsive without breakpoint (scrolls always)Pass the test and this pattern moves unknown