Bs5 Tables in Bootstrap
Absolutely! Here’s a handy guide to Bootstrap 5 Tables — styled tables with various features for responsive and clean data presentation.
?? Bootstrap 5 Tables
Bootstrap 5 provides easy-to-use classes to style HTML tables with borders, stripes, hover effects, and responsiveness.
1. Basic Table
<table class="table"> <thead> <tr> <th scope="col">#</th> <th scope="col">First</th> <th scope="col">Last</th> <th scope="col">Handle</th> </tr> </thead> <tbody> <tr> <th scope="row">1</th> <td>Mark</td> <td>Otto</td> <td>@mdo</td> </tr> <tr> <th scope="row">2</th> <td>Jacob</td> <td>Thornton</td> <td>@fat</td> </tr> </tbody></table>2. Table Variants
| Class | Description |
|---|---|
.table-striped | Adds zebra-striping rows |
.table-bordered | Adds borders on all cells |
.table-hover | Adds hover effect on rows |
.table-sm | Smaller, compact table |
.table-borderless | Removes borders |
Example:
<table class="table table-striped table-hover table-bordered"> ...</table>3. Table Dark Variant
For dark backgrounds:
<table class="table table-dark"> ...</table>Can combine with other classes like .table-striped:
<table class="table table-dark table-striped"> ...</table>4. Responsive Tables
Wrap your table in .table-responsive to enable horizontal scrolling on small devices:
<div class="table-responsive"> <table class="table"> ... </table></div>For responsive behavior at specific breakpoints, use:
.table-responsive-sm.table-responsive-md.table-responsive-lg.table-responsive-xl.table-responsive-xxl
5. Caption
Add a caption to describe the table:
<table class="table"> <caption>List of users</caption> ...</table>6. Alignment and Vertical Alignment
Use utility classes for text alignment:
.text-start,.text-center,.text-end
For vertical alignment in cells:
.align-baseline.align-top.align-middle.align-bottom.align-text-bottom
Example:
<td class="text-center align-middle">Centered middle cell</td>Summary Table
| Class | Effect |
|---|---|
.table | Base Bootstrap table |
.table-striped | Zebra stripe rows |
.table-bordered | Borders on all cells |
.table-hover | Row hover effect |
.table-sm | Smaller compact table |
.table-dark | Dark themed table |
.table-responsive | Responsive scroll container |
If you want me to help create complex tables with sorting, pagination, or integrate with JS libraries like DataTables, just say!