Tables
Bootstrap table styles turn a plain HTML <table> into a readable, consistently spaced data table by adding a few classes. You use them for things like price lists, timetables, order histories and admin screens, anywhere rows and columns of real data need to be shown.
Starting with the base class
Bootstrap deliberately leaves raw tables unstyled, because tables are also used inside other widgets. To opt in, add class="table". That single class gives you padding in each cell, horizontal dividers and full width. Everything else builds on top of it.
<div class="table-responsive">
<table class="table table-striped table-hover align-middle">
<caption>Recent orders</caption>
<thead class="table-light">
<tr>
<th scope="col">Order</th>
<th scope="col">Customer</th>
<th scope="col" class="text-end">Amount</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">#1021</th>
<td>Riya</td>
<td class="text-end">1,250.00</td>
</tr>
<tr class="table-warning">
<th scope="row">#1022</th>
<td>Arjun</td>
<td class="text-end">640.00</td>
</tr>
</tbody>
</table>
</div>
Modifier classes you will use most
| Class | Effect |
|---|---|
table-striped | Shades every other row in the body. |
table-hover | Highlights a row when the mouse is over it. |
table-bordered | Adds borders on every side of every cell. |
table-borderless | Removes all borders. |
table-sm | Halves the cell padding for dense data. |
table-dark | Light text on a dark background. |
These can be combined freely. A compact, striped admin list might use table table-sm table-striped. Striping helps the eye follow a long row across many columns, while hover is most useful when clicking a row opens a detail view. If rows are not clickable, hover can mislead users into thinking they are, so add it only when it means something.
Under the hood, Bootstrap 5 drives these styles with CSS variables such as --bs-table-bg and --bs-table-striped-bg. That means you can adjust colours for one table in your own stylesheet without overriding long selector chains.
Colouring rows and cells
Contextual classes such as table-success, table-danger, table-warning and table-info can be placed on a <tr>, a single <td>, or the whole table. They are useful for marking a failed payment or a low-stock item. Colour alone is not enough for people who cannot see it, so pair it with text such as "Overdue" in a status column.
For header rows, table-light or table-dark on the <thead> gives a distinct header band. Vertical alignment inside rows is set with align-middle, align-top or align-bottom.
The mobile pitfall: tables that overflow
Tables do not shrink the way text does. A table with six or seven columns will push past a phone screen and create a sideways scroll on the whole page, which feels broken. Wrap it in <div class="table-responsive"> so only the table area scrolls horizontally. Use table-responsive-md or a similar variant if you want the scroll only below a certain breakpoint.
Another frequent mistake is placing the responsive class on the <table> itself. It must go on a wrapping element, otherwise it does nothing.
Keeping tables accessible
- Use
<th>for headings and addscope="col"orscope="row"so screen readers can link each cell to its heading. - Add a
<caption>describing the table. Bootstrap places it below the table by default;caption-topon the table moves it above. - Right-align numbers with
text-endso digits line up and are easier to compare.
Remember: table first, modifiers second, and a table-responsive wrapper around any table that might be wider than a phone.
Ready to master real-world web development?
Learn HTML, CSS3, Bootstrap and JavaScript hands-on with mentor-led sessions.