Bootstrap provides an extremely simple way to invert the colors of your table, creating a sleek dark-themed data grid. By adding a single class, .table-dark, the background immediately turns dark grey and the text becomes light for high-contrast readability.
To create a dark table, you must include the base .table class, followed by the modifier .table-dark class.
| # | First Name | Last Name | Username |
|---|---|---|---|
| 1 | Mark | Otto | @mdo |
| 2 | Jacob | Thornton | @fat |
| 3 | Larry | the Bird |
<div class="table-responsive">
<table class="table table-dark">
<!-- Table Content -->
</table>
</div>
You can mix the dark table utility with the other modifier classes we learned recently. For example, adding .table-striped creates alternating darker/lighter grey rows that look fantastic in dark mode dashboards.
| ID | Product | Price | Stock |
|---|---|---|---|
| 401 | Basic T-Shirt | $15.00 | In Stock |
| 402 | Denim Jeans | $45.00 | Low Stock |
| 403 | Hoodie | $35.00 | Out of Stock |
<!-- Striping works perfectly on dark backgrounds -->
<table class="table table-dark table-striped">...</table>
Combining .table-dark with .table-hover allows users to trace horizontal data by highlighting the row underneath their cursor with a slightly brighter shade of grey.
| Invoice # | Date | Status |
|---|---|---|
| INV-1001 | Oct 24, 2023 | Paid |
| INV-1002 | Oct 26, 2023 | Pending |
| INV-1003 | Nov 01, 2023 | Overdue |
<table class="table table-dark table-hover">...</table>
What if you want the table body to remain light, but want a strong, high-contrast header row at the top to anchor the data? You can apply the .table-dark class specifically to the <thead> tag instead of the entire table!
| # | City | Country | Population |
|---|---|---|---|
| 1 | Tokyo | Japan | 37,400,000 |
| 2 | Delhi | India | 29,300,000 |
<table class="table">
<!-- Applying darkness only to the header block -->
<thead class="table-dark">
<tr>
<th>...</th>
</tr>
</thead>
<tbody>
<tr>
<td>...</td>
</tr>
</tbody>
</table>