Bootstrap

Bootstrap CSS Table

ootstrap CSS Tables Overview

Bootstrap offers ready-made table classes that make styling tables easy and consistent.

Basic Table

html
<table class="table">
<thead>
<tr>
<th>Title</th>
<th>Author</th>
<th>Date</th>
</tr>
</thead>
<tbody>
<tr>
<td>How to CSS Tables</td>
<td>John Doe</td>
<td>2025-07-30</td>
</tr>
<tr>
<td>Bootstrap Tips</td>
<td>Jane Smith</td>
<td>2025-07-29</td>
</tr>
</tbody>
</table>

Key Bootstrap Table Classes

  • .table — basic styling (borders, padding)

  • .table-striped — zebra-striping rows

  • .table-bordered — adds borders to all cells

  • .table-hover — highlights rows on hover

  • .table-sm — smaller, compact table

  • .table-responsive — makes the table horizontally scrollable on small screens


Example with multiple Bootstrap classes for blog content

html
<div class="table-responsive">
<table class="table table-striped table-bordered table-hover table-sm">
<thead class="thead-dark">
<tr>
<th>Post Title</th>
<th>Author</th>
<th>Date Published</th>
<th>Comments</th>
</tr>
</thead>
<tbody>
<tr>
<td>Understanding CSS Tables</td>
<td>Emily</td>
<td>2025-07-25</td>
<td>12</td>
</tr>
<tr>
<td>Bootstrap Table Basics</td>
<td>Michael</td>
<td>2025-07-20</td>
<td>8</td>
</tr>
</tbody>
</table>
</div>

Explanation:

  • .table-responsive wraps the table to make it scrollable on small devices.

  • .table-striped adds alternating row colors for better readability.

  • .table-bordered gives a border around all table cells.

  • .table-hover highlights the row under the mouse pointer.

  • .table-sm makes the table more compact.

  • .thead-dark styles the header row with a dark background (optional, you can use .thead-light for a light header).


How to include Bootstrap CSS

Make sure you add Bootstrap’s CSS in your project:

html
<!-- Bootstrap 5 CDN -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet" />

Using Bootstrap tables in a blog context

  • Use tables to show post metadata (author, date, comments).

  • Combine .table-responsive to ensure mobile usability.

  • Use .table-hover for interactivity.

  • Customize with additional CSS if needed for your blog style.

Leave a Reply

Your email address will not be published. Required fields are marked *