Lesson 21 of 60 – Bootstrap Tables
35%

Bootstrap Tables

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.

Note: The basic Bootstrap table is created by adding the .table class to an HTML <table> element.

1. What Is a Bootstrap Table?

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

2. The .table Class

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

3. Table Headers

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.

4. Table Body

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.

5. Table Footer

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

6. Striped Tables

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

7. Bordered Tables

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

8. Borderless Tables

The .table-borderless class removes the table's borders.

<table class="table table-borderless">
    ...
</table>
Name Course
Rahul HTML
Amit Python

9. Hoverable Rows

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.

10. Small Tables

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.

11. Dark Tables

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

12. Dark Striped Tables

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

13. Table Row Colors

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

14. Table Cell Colors

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

15. Responsive Tables

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 Email 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.

16. Responsive Table at Breakpoints

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-xxl

17. Table Alignment

Bootstrap 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

18. Vertical Alignment

The align-middle, align-top, and align-bottom utilities can be used for vertical alignment.

<td class="align-middle">
Content
</td>
Top Middle Bottom

19. Table Captions

The HTML <caption> element can provide a description or title for a table.

<table class="table">

    <caption>
    List of Students
    </caption>

    ...
    
</table>
List of Students
ID Name
101 Rahul
102 Amit

Captions can help explain what the table represents.

20. Table with Badges

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

21. Table with Buttons

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>
ID Name Actions
101 Rahul View Edit Delete
102 Amit View Edit Delete

22. Table with Images

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
Rahul Rahul ADCA
Amit Amit Python

23. Payment Table Example

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

24. Attendance Table Example

Attendance records can be displayed using badges and table styling.

Student Monday Tuesday Wednesday
Rahul Present Present Absent
Amit Present Late Present

25. Marks Table Example

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

26. Table Accessibility

Tables should be structured properly so that their information is easy to understand, including for users of assistive technologies.

  • Use <caption> when a table needs a title or description.
  • Use <thead> for table headings.
  • Use <tbody> for the main table data.
  • Use <tfoot> for totals or summaries when appropriate.
  • Use meaningful column headings.
  • Do not use tables for page layout.
  • Make wide tables usable on smaller screens.
Tip: HTML tables should represent tabular data, not be used to build the overall layout of a webpage.

27. Common Table Mistakes

Common mistakes include:

  • Using tables for page layout.
  • Creating very wide tables without responsive handling.
  • Using unclear column headings.
  • Putting too much information into one cell.
  • Using color as the only indicator of status.
  • Forgetting mobile users.
  • Using excessive buttons inside every row.

A good table should present information in a clear and easy-to-scan format.

28. Bootstrap Table Classes Reference

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.

29. Practical Student Management Table

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>
ID Name Course Status Actions
101 Rahul ADCA Active View Edit Delete
102 Amit Python Pending View Edit Delete

30. Complete Bootstrap Table Example

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>
Student Management
ID Student Course Fee Status Actions
101 Rahul Kumar ADCA ₹10,000 Paid View Edit
102 Amit Kumar Python ₹15,000 Pending View Edit

📌 Key Points

  • Use .table for basic Bootstrap table styling.
  • Use .table-striped for alternating row styling.
  • Use .table-bordered to add borders.
  • Use .table-borderless to remove borders.
  • Use .table-hover for row hover effects.
  • Use .table-sm for compact tables.
  • Use .table-dark for a dark table.
  • Use contextual classes such as .table-success and .table-danger.
  • Use .table-responsive for wide tables on smaller screens.
  • Use <thead>, <tbody>, and <tfoot> for proper table structure.
  • Use <caption> when a table needs a title or description.
  • Tables should be used for tabular data, not page layout.
  • Badges and buttons can be placed inside table cells.
  • Always consider mobile usability when designing wide tables.

🧠 Quick Quiz

Question: Which Bootstrap class is used to create a responsive table wrapper?