Add the .table class to a plain <table> and Bootstrap gives it full width, padding in every cell and a thin line between rows. Nothing else is required, and no JavaScript is involved.
Page setup
Bootstrap 5 no longer needs jQuery, and the separate bootstrap-theme.css from version 3 is gone. A minimal page loads one stylesheet from jsDelivr. The script bundle is only needed for interactive components such as dropdowns and modals, but it does no harm to include it once in your layout:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Bootstrap table</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<main class="container py-4">
<!-- table goes here -->
</main>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
The table
<div class="table-responsive">
<table class="table">
<caption>Points per player</caption>
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">First name</th>
<th scope="col">Last name</th>
<th scope="col" class="text-end">Points</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">1</th>
<td>George</td>
<td>Hagi</td>
<td class="text-end">100</td>
</tr>
<tr>
<th scope="row">2</th>
<td>Jill</td>
<td>Smith</td>
<td class="text-end">70</td>
</tr>
<tr>
<th scope="row">3</th>
<td>Eve</td>
<td>Jackson</td>
<td class="text-end">20</td>
</tr>
<tr>
<th scope="row">4</th>
<td>Adam</td>
<td>Johnson</td>
<td class="text-end">15</td>
</tr>
</tbody>
</table>
</div>
A few details in this markup are there on purpose.
scope on header cells. scope="col" tells a screen reader that a header applies to the cells below it, and scope="row" on the first cell of each row marks it as the row header. Bootstrap’s own examples use both, and they cost nothing.
Right-aligned numbers. .text-end (called .text-right in Bootstrap 3 and 4) lines up the digits so values can be compared at a glance. Apply it to the header cell too, or the heading will sit to the left of its column.
The caption. A <caption> names the table for assistive technology. Bootstrap places it below the table by default; add .caption-top to the <table> if you want it above.
The responsive wrapper. A wide table on a phone pushes the whole page sideways. Wrapping it in .table-responsive gives the table its own horizontal scrollbar instead. If you only need that below a certain width, use a breakpoint variant such as .table-responsive-md.
Useful modifier classes
All of these go on the <table> element next to .table:
| Class | Effect |
|---|---|
.table-striped | Shades every other body row |
.table-hover | Highlights the row under the mouse |
.table-bordered | Borders on all sides of every cell |
.table-borderless | Removes all borders |
.table-sm | Halves the cell padding (was .table-condensed in Bootstrap 3) |
.table-dark | Dark background, light text |
.align-middle | Vertically centers cell content (the default is top) |
Bootstrap 5.2 also added .table-group-divider, which you put on a <tbody> or <tfoot> to draw a thicker line above it.
Things that catch people out
Bootstrap styles the table through CSS variables on the cells. That means a background utility such as .bg-warning on a <tr> is painted over by the cells’ own background and seems to do nothing. Use the table variants (.table-warning and friends) instead.
The table is 100% wide by default. If you want it to shrink to its content, .w-auto on the <table> does that.
And if you build the table from data in ASP.NET Core, the markup is identical: loop over your model in Razor and emit one <tr> per item. Bootstrap does not care where the HTML came from.
Related examples
- Striped Bootstrap table
- Hover state on Bootstrap table rows
- Bootstrap table emphasis classes
- Bootstrap pagination samples
- Tables in the Bootstrap documentation