Bootstrap Table
-
Style and manage responsive tables using Bootstrap classes.
Introduction to Tables in Bootstrap
Tables are used to display structured data in rows and columns, such as:
User lists
Product details
Reports
Records
Admin data
In Bootstrap 5, tables are pre-styled, responsive-friendly, and easy to customize using utility classes.
Bootstrap tables are built on standard HTML <table> elements, enhanced with Bootstrap classes.
Basic Bootstrap Table
What Is a Basic Table ?
A basic table uses the .table class to apply Bootstrap styling.
Creating a Basic Styled Table
The .table class adds basic Bootstrap styling to an HTML table.
<table class="table">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Age</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Alice</td>
<td>22</td>
</tr>
<tr>
<td>2</td>
<td>Bob</td>
<td>25</td>
</tr>
</tbody>
</table>
What .table Does
Adds padding
Adds borders between rows
Improves readability
Applies clean default styling
Table Head Styling
Dark Table Header
Use .table-dark with <thead>.
Styling Table Headers with Dark Theme
Using .table-dark inside applies a dark background to the table header.
Used when: Header needs emphasis Data-heavy tables Striped tables add alternating background colors to rows for better readability.
The .table-striped class adds alternating row colors for improved readability.
Used when: Table has many rows Visual scanning is important
The .table-bordered class adds borders to all table cells.
Effect: Adds borders to all cells Makes table grid clear Used in: Reports Admin dashboards Financial data
The .table-borderless class removes all borders from the table.
Used when: Clean UI is needed Minimal design Hoverable Rows
The .table-hover class adds a hover effect to table rows for better user interaction.
Effect: Highlights row on mouse hover Common use: Clickable data rows Interactive tables
The .table-sm class reduces padding to create a smaller, compact table.
Effect: Reduced padding Compact row height Used in: Dense data views Dashboards
Contextual classes like .table-success and .table-danger add color-based meaning to table rows.
Used for: Status indication Highlighting important rows
The .table-dark class applies a dark background and light text to the entire table.
Effect: Dark background Light text Used in: Dark UI themes Admin panels
The .table-responsive class makes tables scroll horizontally on small screens.
Effect: Horizontal scroll on small screens No layout break
The Purpose: Describes table content Improves accessibility Common Mistakes Forgetting .table class Not using <thead> and <tbody> Ignoring responsiveness Overusing colors Using tables for page layout Tables should be used only for tabular data, not layout. Best Practices for Bootstrap Tables Use .table as base Add features only when needed Keep tables readable Always make tables responsive Avoid overcrowding cells<table class="table">
<thead class="table-dark">
<tr>
<th>Name</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<tr>
<td>John</td>
<td>john@email.com</td>
</tr>
</tbody>
</table>
Striped Rows
What Are Striped Tables ?
Creating Striped Rows
<table class="table table-striped"></table>
Bordered Table
Adding Borders to a Table
<table class="table table-bordered"></table>
Borderless Table
Creating a Borderless Table
<table class="table table-borderless"></table>
Creating Hoverable Rows in a Table
<table class="table table-hover"></table>
Small Table
Creating a Compact Table
<table class="table table-sm"></table>
Contextual Table Classes
Applying Contextual Colors to Table Rows
<tr class="table-success"></tr>
<tr class="table-danger"></tr>
<tr class="table-warning"></tr>
<tr class="table-info"></tr>
<!-- Example -->
<tr class="table-success">
<td>Payment Received</td>
</tr>
Table with Dark Theme
Creating a Dark-Themed Table
<table class="table table-dark"></table>
Responsive Tables
Why Responsive Tables Are Needed
Tables can overflow on small screens.
Bootstrap solves this using .table-responsive.
Creating Responsive Tables
<div class="table-responsive">
<table class="table">
<tr>
<th>Name</th>
<th>Email</th>
<th>Phone</th>
</tr>
<tr>
<td>Alice</td>
<td>a@email.com</td>
<td>1234567890</td>
</tr>
</table>
</div>
Table Caption
Adding a Caption
<table class="table">
<caption>User List</caption>
</table>