bootstrap_ref_css_tables
Bootstrap 5 CSS Tables Reference
Section titled “Bootstrap 5 CSS Tables Reference”Table Styling Classes
Section titled “Table Styling Classes”Use these foundational classes to style your HTML tables. Bootstrap 5 offers a clean, modern look for tables with minimal effort.
ClassDescriptionExample
.tableAdds basic styling (light padding and horizontal dividers) to any <table>. This is the base class for all table styles.Try it
.table-stripedAdds zebra-striping to table rows within <tbody> for improved readability. Achieved using CSS :nth-child selectors.Try it
.table-borderedAdds borders on all sides of the table and cells.Try it
.table-borderlessRemoves all borders on the table and cells, including the default top border from .table.Try it
.table-hoverEnables a hover state (a subtle background color change) on table rows within a <tbody>.Try it
.table-smMakes the table more compact by cutting cell padding in half. Replaces the older .table-condensed class.Try it
.caption-topPositions the table caption (<caption> element) on the top of the table.Try it
Combining table classesThese classes can be combined for more customized table styling. For example, <table class="table table-striped table-hover table-bordered">Try itContextual Classes for Rows and Cells
Section titled “Contextual Classes for Rows and Cells”Use these contextual classes to color table rows () or individual cells (, ). These classes convey meaning through color.
ClassDescriptionExample
.table-activeApplies a hover-like color to a particular row or cell, often used to indicate an active selection.Try it
.table-primaryIndicates a primary action or information (typically blue).Try it
.table-secondaryIndicates a secondary action or less important information (typically gray).Try it
.table-successIndicates a successful or positive action (typically green).Try it
.table-dangerIndicates a dangerous or potentially negative action (typically red).Try it
.table-warningIndicates a warning that might need attention (typically yellow/orange).Try it
.table-infoIndicates a neutral informative change or action (typically light blue/cyan).Try it
.table-lightSpecifies a light gray background for rows or cells.Try it
.table-darkSpecifies a dark gray background, often used for headers or to invert colors.Try itResponsive Tables
Section titled “Responsive Tables”To make tables responsive, wrap any .table in .table-responsive. This will make the table scroll horizontally on small devices (below a certain breakpoint). You can also use breakpoint-specific responsive classes like .table-responsive-sm, .table-responsive-md, etc., to control when the table becomes scrollable.
For example, .table-responsive-md will make the table scroll horizontally on screens smaller than 768px (Bootstrap’s ‘md’ breakpoint).
<div class="table-responsive"> <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> <tr> <th scope="row">3</th> <td colspan="2">Larry the Bird</td> <td>@twitter</td> </tr> </tbody> </table></div>
<!-- Example for responsive table up to medium breakpoint --><div class="table-responsive-md"> <table class="table"> <!-- table content --> </table></div>Application Scenario: Displaying user data in an admin dashboard. A responsive table ensures that all user details are accessible even on smaller screens, with horizontal scrolling if necessary. Contextual classes can highlight new users (.table-info) or users with overdue payments (.table-danger).
For more advanced table features and customization, refer to the official Bootstrap documentation on tables.