Styling HTML Tables with Bootstrap: A Comprehensive Guide

Learn how to create visually appealing and responsive tables using Bootstrap's styling classes. This tutorial covers basic table styles, adding zebra stripes, customizing borders, and creating responsive tables, enhancing the presentation of tabular data in your web projects.



Styling Tables with Bootstrap

Bootstrap provides a range of classes to style HTML tables, making them visually appealing and responsive. This guide shows various table styles and customizations.

Basic Bootstrap Table

The simplest Bootstrap table uses the `.table` class, adding light padding and horizontal dividers.

Test it Now

Striped Rows

Add zebra stripes using the `.table-striped` class.

Test it Now

Bordered Table

Add borders to all sides of the table and cells using the `.table-bordered` class.

Test it Now

Hover Effect

Enable a hover effect on rows using the `.table-hover` class.

Test it Now

Condensed Table

Make the table more compact with `.table-condensed`, reducing cell padding.

Test it Now

Contextual Classes

Add color to rows or cells using contextual classes. These provide visual cues:

Class Description
.table-active Applies hover color.
.table-success Indicates success.
.table-info Indicates information.
.table-warning Indicates a warning.
.table-danger Indicates danger.

Test Contextual Classes Now

Responsive Tables

Use the `.table-responsive` class to make tables scrollable on smaller screens (under 768px wide).

Test Responsive Table Now

Bootstrap 4 Table Styles

Dark Tables

Use `.table-dark` for a dark background table. Combine with `.table-striped` or `.table-hover` for additional styles.

Test Dark Table Now

Test Dark Striped Table Now

Test Hoverable Dark Table Now

Contextual Classes (Bootstrap 4)

Bootstrap 4 offers more contextual classes for tables, rows, and cells: `.table-primary`, `.table-success`, `.table-info`, `.table-warning`, `.table-danger`, `.table-active`, `.table-secondary`, `.table-light`, and `.table-dark`.

Test Bootstrap 4 Contextual Classes Now

Table Header Colors

Control header background color with `.thead-dark` (dark) and `.thead-light` (light).

Test Table Header Colors Now

Small Tables

Use `.table-sm` to create a smaller table with reduced padding.

Test Small Table Now