Bootstrap Tables
Bootstrap's table classes turn plain HTML tables into styled, responsive components. This lesson covers the core table modifiers and how to keep tables usable on small screens.
Bootstrap Tables Overview
Adding .table to a standard HTML table applies consistent padding, borders, and typography. From there, modifier classes like table-striped, table-bordered, table-hover, and table-dark let you combine visual styles without writing custom CSS.
Because tables don't naturally shrink on small screens, Bootstrap provides a .table-responsive wrapper that adds horizontal scrolling instead of letting the table break the page layout, which is essential for any table with many columns.
| Concept | Description | Common Usage |
| .table | Base table styling with padding and borders | Any HTML table needing consistent styling |
| table-striped | Zebra-striping on alternating rows | Improving readability of dense tables |
| table-bordered / table-borderless | Adds or removes all cell borders | Strong grid lines or a cleaner, minimal look |
| table-hover | Highlights rows on mouse hover | Interactive data tables |
| .table-responsive | Wrapper enabling horizontal scroll on small screens | Wide tables with many columns |
Bootstrap Tables Example
<div class="table-responsive">
<table class="table table-striped table-hover align-middle">
<thead class="table-dark">
<tr>
<th>#</th>
<th>Name</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Alice</td>
<td><span class="badge bg-success">Active</span></td>
</tr>
<tr class="table-warning">
<td>2</td>
<td>Bob</td>
<td><span class="badge bg-warning text-dark">Pending</span></td>
</tr>
</tbody>
</table>
</div>
The table-responsive wrapper ensures the table scrolls horizontally on narrow screens instead of breaking the layout. table-striped and table-hover combine for readability and interactivity, table-dark styles the header, and the contextual table-warning class highlights a specific row.
Top 10 Bootstrap Tables Examples
These are the table modifier classes you'll combine most often when styling tabular data.
| # | Example | Syntax |
| 1 | Base table | <table class="table">...</table> |
| 2 | Striped rows | <table class="table table-striped">...</table> |
| 3 | Bordered table | <table class="table table-bordered">...</table> |
| 4 | Borderless table | <table class="table table-borderless">...</table> |
| 5 | Hoverable rows | <table class="table table-hover">...</table> |
| 6 | Dark table | <table class="table table-dark">...</table> |
| 7 | Small/compact table | <table class="table table-sm">...</table> |
| 8 | Responsive wrapper | <div class="table-responsive"><table class="table">...</table></div> |
| 9 | Contextual row color | <tr class="table-success">...</tr> |
| 10 | Vertically centered cells | <table class="table align-middle">...</table> |
Popular Real-World Bootstrap Tables Examples
These table patterns are commonly used in admin panels, pricing pages, and data-heavy dashboards.
| Scenario | Pattern |
| Admin user list | <table class="table table-striped table-hover align-middle">...</table> |
| Order history with status badges | <td><span class="badge bg-success">Paid</span></td> |
| Pricing comparison table | <table class="table table-bordered text-center">...</table> |
| Compact dense data table | <table class="table table-sm table-striped">...</table> |
| Highlighted row for current user | <tr class="table-primary">You</tr> |
| Dark-themed dashboard table | <table class="table table-dark table-hover">...</table> |
| Scrollable wide report table | <div class="table-responsive"><table class="table">...</table></div> |
| Invoice line items | <table class="table table-borderless">...</table> |
Best Practices
- Always wrap tables in .table-responsive when column count could overflow small screens.
- Use table-striped for long tables to help users track rows visually.
- Combine table-hover with clickable rows to signal interactivity.
- Use contextual row classes (table-success, table-danger) sparingly to highlight meaningful status.
- Pair table-dark headers with a lighter table body for clear visual separation.
- Use table-sm on dense admin tables to fit more rows without scrolling.
- Keep table headers using proper <th> elements with scope attributes for accessibility.
Common Mistakes
- Forgetting .table-responsive, causing wide tables to break page layout on mobile.
- Overusing contextual row colors until the table loses meaningful visual hierarchy.
- Using table-bordered and table-borderless together, which conflicts visually.
- Not using semantic thead/tbody/tfoot structure, hurting accessibility and styling consistency.
- Applying table-dark only to the whole table when just the header needed emphasis.
- Nesting interactive elements like buttons in narrow cells without enough padding, hurting usability.
Key Takeaways
- The base .table class provides consistent baseline styling for any HTML table.
- Modifier classes like striped, bordered, hover, and dark can be combined freely.
- .table-responsive prevents wide tables from breaking small-screen layouts.
- Contextual classes highlight specific rows or cells with theme colors.
- table-sm and align-middle fine-tune density and vertical alignment.
Pro Tip
For dashboards with many columns, combine table-responsive with table-sm and align-middle to maximize the amount of readable data that fits on screen without sacrificing usability.