Bootstrap provides ready-made classes for creating clean, responsive, and attractive HTML tables. Tables are useful for displaying structured information such as student records, payment details, products, marks, attendance, reports, and employee information.
.table
class to an HTML <table> element.
A Bootstrap table is a normal HTML table enhanced with Bootstrap CSS classes.
<table class="table">
<tr>
<th>Name</th>
<th>Course</th>
</tr>
<tr>
<td>Rahul</td>
<td>HTML</td>
</tr>
</table>
| Name | Course |
|---|---|
| Rahul | HTML |
The .table class adds basic Bootstrap styling to an HTML
table.
<table class="table">
...
</table>
It provides spacing, alignment, borders between rows, and a clean default appearance.
| ID | Name | Course |
|---|---|---|
| 101 | Rahul | ADCA |
| 102 | Amit | Python |
Table headings are normally placed inside <thead>.
<table class="table">
<thead>
<tr>
<th>Student ID</th>
<th>Name</th>
<th>Course</th>
</tr>
</thead>
</table>
Using <thead> makes the table structure easier to
understand and maintain.
Table data rows are normally placed inside <tbody>.
<tbody>
<tr>
<td>101</td>
<td>Rahul</td>
<td>ADCA</td>
</tr>
</tbody>
The <tbody> element contains the main data displayed
in the table.
The <tfoot> element can be used for totals or summary
information.
<tfoot>
<tr>
<th colspan="2">
Total Students
</th>
<th>
50
</th>
</tr>
</tfoot>
| Course | Students |
|---|---|
| HTML | 20 |
| CSS | 30 |
| Total Students | 50 |
The .table-striped class adds alternating background
styling to table rows.
<table class="table table-striped">
...
</table>
| ID | Name | Course |
|---|---|---|
| 101 | Rahul | HTML |
| 102 | Amit | CSS |
| 103 | Ravi | JavaScript |
| 104 | Priya | Python |
The .table-bordered class adds borders around the table
and its cells.
<table class="table table-bordered">
...
</table>
| ID | Name | Status |
|---|---|---|
| 101 | Rahul | Active |
| 102 | Amit | Pending |
The .table-borderless class removes the table's borders.
<table class="table table-borderless">
...
</table>
| Name | Course |
|---|---|
| Rahul | HTML |
| Amit | Python |
The .table-hover class adds a hover effect to table rows.
<table class="table table-hover">
...
</table>
| ID | Student | Course |
|---|---|---|
| 101 | Rahul | ADCA |
| 102 | Amit | Python |
| 103 | Ravi | JavaScript |
Move the mouse over the rows to see the hover effect.
The .table-sm class reduces the padding inside table cells.
<table class="table table-sm">
...
</table>
| ID | Name | Course |
|---|---|---|
| 1 | Rahul | HTML |
| 2 | Amit | CSS |
Small tables are useful when a large amount of data needs to fit into a limited space.
Bootstrap supports contextual table color utilities. For example,
table-dark creates a dark table.
<table class="table table-dark">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
</tr>
</thead>
</table>
| ID | Name | Status |
|---|---|---|
| 101 | Rahul | Active |
| 102 | Amit | Pending |
You can combine .table-dark and
.table-striped.
<table class="table table-dark table-striped">
...
</table>
| ID | Name | Course |
|---|---|---|
| 101 | Rahul | HTML |
| 102 | Amit | CSS |
| 103 | Ravi | Python |
Bootstrap contextual classes can be applied to individual rows or cells.
<tr class="table-success">
<td>Rahul</td>
<td>Paid</td>
</tr>
<tr class="table-warning">
<td>Amit</td>
<td>Pending</td>
</tr>
<tr class="table-danger">
<td>Ravi</td>
<td>Failed</td>
</tr>
| Rahul | Paid |
| Amit | Pending |
| Ravi | Failed |
Contextual table classes can also be applied to individual cells.
<td class="table-success">
Paid
</td>
<td class="table-danger">
Due
</td>
| Student | Payment |
|---|---|
| Rahul | Paid |
| Amit | Due |
The .table-responsive class helps a wide table scroll
horizontally when necessary on smaller screens.
<div class="table-responsive">
<table class="table">
...
</table>
</div>
| ID | Name | Phone | Course | Duration | |
|---|---|---|---|---|---|
| 101 | Rahul | rahul@example.com | 9876543210 | ADCA | 12 Months |
| 102 | Amit | amit@example.com | 9876543211 | Python | 6 Months |
This prevents a wide table from forcing the entire page to overflow horizontally.
Bootstrap also provides breakpoint-specific responsive table wrappers.
For example, .table-responsive-md makes the table
responsive below the medium breakpoint.
<div class="table-responsive-md">
<table class="table">
...
</table>
</div>
Other available breakpoint versions include:
.table-responsive-sm.table-responsive-md.table-responsive-lg.table-responsive-xl.table-responsive-xxlBootstrap utility classes can be used to control the alignment of table content.
<td class="text-center">
100
</td>
<td class="text-end">
₹500
</td>
| Name | Marks | Fee |
|---|---|---|
| Rahul | 85 | ₹500 |
| Amit | 92 | ₹700 |
The align-middle, align-top, and
align-bottom utilities can be used for vertical alignment.
<td class="align-middle">
Content
</td>
| Top | Middle | Bottom |
The HTML <caption> element can provide a description
or title for a table.
<table class="table">
<caption>
List of Students
</caption>
...
</table>
| ID | Name |
|---|---|
| 101 | Rahul |
| 102 | Amit |
Captions can help explain what the table represents.
Badges can be used inside tables to show statuses.
<td>
<span class="badge text-bg-success">
Active
</span>
</td>
| Student | Status |
|---|---|
| Rahul | Active |
| Amit | Pending |
| Ravi | Inactive |
Buttons can be placed inside table cells for actions such as View, Edit, and Delete.
<td>
<a href="#"
class="btn btn-primary btn-sm">
View
</a>
<a href="#"
class="btn btn-warning btn-sm">
Edit
</a>
<a href="#"
class="btn btn-danger btn-sm">
Delete
</a>
</td>
Small images or profile pictures can be placed inside table cells.
<img src="profile.jpg"
class="rounded-circle"
style="width:40px;height:40px;"
alt="Student">
| Student | Course |
|---|---|
|
|
ADCA |
|
|
Python |
Bootstrap tables are useful for displaying payment information.
| Student | Course | Total Fee | Paid | Due | Status |
|---|---|---|---|---|---|
| Rahul | ADCA | ₹10,000 | ₹10,000 | ₹0 | Paid |
| Amit | Python | ₹15,000 | ₹10,000 | ₹5,000 | Pending |
| Ravi | JavaScript | ₹12,000 | ₹5,000 | ₹7,000 | Due |
Attendance records can be displayed using badges and table styling.
| Student | Monday | Tuesday | Wednesday |
|---|---|---|---|
| Rahul | Present | Present | Absent |
| Amit | Present | Late | Present |
Tables are also useful for displaying examination marks.
| Student | HTML | CSS | JavaScript | Total |
|---|---|---|---|---|
| Rahul | 85 | 80 | 90 | 255 |
| Amit | 75 | 88 | 82 | 245 |
| Priya | 92 | 90 | 95 | 277 |
Tables should be structured properly so that their information is easy to understand, including for users of assistive technologies.
<caption> when a table needs a title or description.<thead> for table headings.<tbody> for the main table data.<tfoot> for totals or summaries when appropriate.Common mistakes include:
A good table should present information in a clear and easy-to-scan format.
Important Bootstrap table classes include:
.table
.table-striped
.table-bordered
.table-borderless
.table-hover
.table-sm
.table-dark
.table-success
.table-danger
.table-warning
.table-info
.table-primary
.table-responsive
.table-responsive-sm
.table-responsive-md
.table-responsive-lg
.table-responsive-xl
.table-responsive-xxl
These classes can be combined to create different table designs.
Here is a practical student management table using several Bootstrap features.
<div class="table-responsive">
<table class="table table-striped table-hover table-bordered">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Course</th>
<th>Status</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<tr>
<td>101</td>
<td>Rahul</td>
<td>ADCA</td>
<td>
<span class="badge text-bg-success">
Active
</span>
</td>
<td>
<a href="#"
class="btn btn-primary btn-sm">
View
</a>
<a href="#"
class="btn btn-warning btn-sm">
Edit
</a>
<a href="#"
class="btn btn-danger btn-sm">
Delete
</a>
</td>
</tr>
</tbody>
</table>
</div>
The following example combines responsive behavior, striped rows, hover effects, borders, badges, buttons, and table headings.
<div class="table-responsive">
<table class="table table-striped table-hover table-bordered">
<caption>
Student Management
</caption>
<thead>
<tr>
<th>ID</th>
<th>Student</th>
<th>Course</th>
<th>Fee</th>
<th>Status</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<tr>
<td>101</td>
<td>Rahul Kumar</td>
<td>ADCA</td>
<td>₹10,000</td>
<td>
<span class="badge text-bg-success">
Paid
</span>
</td>
<td>
<a href="#"
class="btn btn-primary btn-sm">
View
</a>
<a href="#"
class="btn btn-warning btn-sm">
Edit
</a>
</td>
</tr>
<tr>
<td>102</td>
<td>Amit Kumar</td>
<td>Python</td>
<td>₹15,000</td>
<td>
<span class="badge text-bg-warning">
Pending
</span>
</td>
<td>
<a href="#"
class="btn btn-primary btn-sm">
View
</a>
<a href="#"
class="btn btn-warning btn-sm">
Edit
</a>
</td>
</tr>
</tbody>
</table>
</div>
.table for basic Bootstrap table styling..table-striped for alternating row styling..table-bordered to add borders..table-borderless to remove borders..table-hover for row hover effects..table-sm for compact tables..table-dark for a dark table..table-success and .table-danger..table-responsive for wide tables on smaller screens.<thead>, <tbody>, and <tfoot> for proper table structure.<caption> when a table needs a title or description.Question: Which Bootstrap class is used to create a responsive table wrapper?