Mastering Table Styling with Bootstrap 5
In the ever-evolving landscape of web development, Bootstrap has consistently been a go-to library for responsive design and rapid prototyping. With the release of Bootstrap 5, table styling has become more intuitive and powerful. Let's delve into the world of table styling with Bootstrap 5, exploring its features, classes, and customization options.
Bootstrap 5 Table Basics
Bootstrap 5 introduces a new table component that improves upon its predecessor. It's built with flexibility and responsiveness in mind, ensuring your tables look great on all devices. The basic structure of a Bootstrap table is as follows:
| # | First | Last | Handle |
|---|---|---|---|
| 1 | Mark | Otto | @mdo |
| 2 | Jacob | Thornton | @fat |
| 3 | Larry | the Bird |
Responsive Tables
Bootstrap 5 tables are responsive by default, thanks to the use of CSS media queries. You can control the responsiveness of your tables using the .table-responsive class. Here's how you can make a table responsive:

Styling Tables with Bootstrap 5
Table Variants
Bootstrap 5 offers several table variants to help you style your tables. You can use the following classes to apply different styles to your tables:
.table-primary- for a light blue table.table-secondary- for a light gray table.table-success- for a green table.table-danger- for a red table.table-warning- for a yellow table.table-info- for a light blue table.table-light- for a white table with dark text.table-dark- for a dark table with white text
Table Borders
You can also add borders to your tables using the .table-bordered class. For a more subtle border, use the .border class along with .table-bordered.
Striped and Hoverable Tables
To make your tables more readable, you can add stripes using the .table-striped class. For interactive tables, use the .table-hover class to enable hover effects.

Customizing Tables with Bootstrap 5
Bootstrap 5 allows you to customize your tables further by using custom CSS. You can target table elements using the following selectors:
.table- for the table element.table th- for table headers.table td- for table data.table thead- for the table header group.table tbody- for the table body group.table tfoot- for the table footer group
With these selectors, you can style your tables to match your website's design perfectly. For more customization options, refer to the official Bootstrap 5 documentation on tables.