bootstrap
  1. bootstrap-tables

Bootstrap Tables

Bootstrap provides several classes that can be used to enhance HTML tables. These classes can be used to add styling, sorting, pagination, and more to tables.

Syntax

To create a basic table in Bootstrap, you can use the following HTML code:

<table class="table">
  <thead>
    <tr>
      <th>Header 1</th>
      <th>Header 2</th>
      <th>Header 3</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Row 1, Cell 1</td>
      <td>Row 1, Cell 2</td>
      <td>Row 1, Cell 3</td>
    </tr>
    <tr>
      <td>Row 2, Cell 1</td>
      <td>Row 2, Cell 2</td>
      <td>Row 2, Cell 3</td>
    </tr>
  </tbody>
</table>

Example

Here is an example of how to create a table with striped rows and hover effect

<table class="table table-striped table-hover">
  <thead>
    <tr>
      <th>Header 1</th>
      <th>Header 2</th>
      <th>Header 3</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Row 1, Cell 1</td>
      <td>Row 1, Cell 2</td>
      <td>Row 1, Cell 3</td>
    </tr>
    <tr>
      <td>Row 2, Cell 1</td>
      <td>Row 2, Cell 2</td>
      <td>Row 2, Cell 3</td>
    </tr>
  </tbody>
</table>
Try Playground

Bordered Table

<table class="table table-bordered">
  <thead>
    <tr>
      <th>Header 1</th>
      <th>Header 2</th>
      <th>Header 3</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Row 1, Cell 1</td>
      <td>Row 1, Cell 2</td>
      <td>Row 1, Cell 3</td>
    </tr>
    <tr>
      <td>Row 2, Cell 1</td>
      <td>Row 2, Cell 2</td>
      <td>Row 2, Cell 3</td>
    </tr>
  </tbody>
</table>
Try Playground

Responsive Table

<div class="table-responsive">
  <table class="table">
    <thead>
      <tr>
        <th>Header 1</th>
        <th>Header 2</th>
        <th>Header 3</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>Row 1, Cell 1</td>
        <td>Row 1, Cell 2</td>
        <td>Row 1, Cell 3</td>
      </tr>
      <tr>
        <td>Row 2, Cell 1</td>
        <td>Row 2, Cell 2</td>
        <td>Row 2, Cell 3</td>
      </tr>
    </tbody>
  </table>
</div>
Try Playground

Table with Dark Background

<table class="table table-dark">
  <thead>
    <tr>
      <th>Header 1</th>
      <th>Header 2</th>
      <th>Header 3</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Row 1, Cell 1</td>
      <td>Row 1, Cell 2</td>
      <td>Row 1, Cell 3</td>
    </tr>
    <tr>
      <td>Row 2, Cell 1</td>
      <td>Row 2, Cell 2</td>
      <td>Row 2, Cell 3</td>
    </tr>
  </tbody>
</table>
Try Playground

Explanation

In the code above, we used the following classes to enhance the table:

  • table: this is the main class that indicates that this is a table.
  • table-striped: this class adds striped rows to a table.
  • table-hover: this class adds a hover effect to a table.

Use

Bootstrap provides several classes that can be used to enhance HTML tables. These classes can be used to add styling, sorting, pagination, and more to tables. You can also use JavaScript libraries such as DataTables to further enhance the functionality of the tables.

Important Points

  • Bootstrap provides several classes that can be used to enhance HTML tables.
  • You can add styling, sorting, pagination, and more to tables using Bootstrap classes.
  • You can also use JavaScript libraries such as DataTables to further enhance the functionality of tables.

Summary

Bootstrap provides a simple and easy way to enhance HTML tables. By using the classes provided by Bootstrap, you can create beautiful and functional tables with ease.

Published on: