.table-hover highlights the row under the mouse pointer. On a wide table with many columns it helps the reader keep track of which row they are on. The class works in Bootstrap 5.3 exactly as it did in version 3, so old markup needs no change here.
Load the Bootstrap stylesheet (https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css); the effect is pure CSS, so no script or jQuery is required.
Example
<table class="table table-hover">
<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>
Only rows inside <tbody> react. The header row stays as it is.
.table-hover combines with the other table classes. table table-striped table-hover is a common choice for data grids, and it also works on .table-dark and on rows that carry a color variant such as .table-warning, where the hover shade is a darker tone of that color.
Changing the hover color
The highlight comes from the --bs-table-hover-bg CSS variable. Override it on one table or in your stylesheet:
.table-hover {
--bs-table-hover-bg: rgba(13, 110, 253, 0.08);
}
This changes ordinary rows only. Rows with a color variant such as .table-warning set their own --bs-table-hover-bg, so they keep a darker shade of their own color. On a striped table the hover color replaces the stripe while the pointer is on the row.
Hover is not interaction
A hover effect tells the user “this row is under your pointer”. Many people read it as “this row is clickable”, so either make the row clickable or think twice about the effect. And when rows are clickable, do it in a way that works without a mouse.
The common approach, an onclick handler on the <tr>, fails keyboard and screen reader users: a table row cannot receive focus and is not announced as a link. Put a real link inside the row instead:
<tr>
<th scope="row">1</th>
<td><a href="/players/1">George</a></td>
<td>Hagi</td>
<td class="text-end">100</td>
</tr>
The link is reachable with Tab, opens in a new tab with a middle click, and shows its address in the status bar. If you also want the whole row to respond to clicks, add a small script that forwards a click anywhere in the row to that link, and leave the link in place for everyone else:
document.querySelectorAll('table.table-hover tbody tr').forEach(row => {
const link = row.querySelector('a[href]');
if (!link) return;
row.style.cursor = 'pointer';
row.addEventListener('click', e => {
if (e.target.closest('a, button, input, select, textarea')) return;
link.click();
});
});
The check on e.target stops the handler from firing a second time when the user clicks the link itself or another control in the row.
Touch screens have no hover. On a phone the first tap may briefly trigger the highlight, but nothing should depend on it.
Related examples
- Simple Bootstrap table
- Striped Bootstrap table
- Bootstrap table emphasis classes
- Hoverable rows in the Bootstrap documentation