Bootstrap Tables
Master Bootstrap Tables — learn how to create professional data tables with striped rows, borders, hover effects, responsive design, and color variants. Complete guide with real-world examples.
In This Lesson
- What is Bootstrap Tables
- Basic Table Structure
- Table Class
- Striped Tables
- Bordered Tables
- Hover Effects
- Dark Tables
- Responsive Tables
- Color Variants
- Table Sizing
- Combined Styling
- Real Examples
- Best Practices
- FAQ
What is Bootstrap Tables?
Bootstrap Tables are HTML tables enhanced with Bootstrap's built-in CSS classes. They provide professional-looking, responsive data tables with minimal custom styling required. Bootstrap automatically applies proper padding, borders, alignment, and responsiveness to create modern tables.
Why use Bootstrap Tables?
Common uses for Bootstrap Tables
- Product lists — Display products with prices and details
- Pricing tables — Compare different pricing plans
- User data — Show user information in dashboards
- Reports — Display statistics and analytics
- Comparison charts — Compare features between options
Basic Table Structure
All Bootstrap tables start with standard HTML table elements. Understanding the structure is essential for using Bootstrap table classes correctly.
HTML table structure
<table> <!-- Table header --> <thead> <tr> <th>Column 1</th> <th>Column 2</th> <th>Column 3</th> </tr> </thead> <!-- Table body --> <tbody> <tr> <td>Data 1</td> <td>Data 2</td> <td>Data 3</td> </tr> </tbody> </table>
Table elements explained
The Table Class
The .table class is the foundation for Bootstrap tables. Add it to the <table> element to apply Bootstrap's default table styling.
Basic table example
<table class="table"> <thead> <tr> <th>ID</th> <th>Name</th> <th>Email</th> </tr> </thead> <tbody> <tr> <td>1</td> <td>John</td> <td>john@email.com</td> </tr> </tbody> </table>
The .table class adds:
- Padding — Proper spacing inside cells
- Borders — Subtle borders between rows
- Alignment — Proper text alignment
- Typography — Professional font sizing
Striped Tables
Add the .table-striped class to create alternating row colors (zebra striping). This improves readability, especially for large tables with many rows.
Striped table example
<table class="table table-striped"> <!-- Table content --> </table>
Striped tables alternate between normal and slightly darker background colors, making it easier to follow rows across columns.
Bordered Tables
The .table-bordered class adds borders to all cells, creating a grid-like appearance. This is useful for displaying structured data that requires clear cell boundaries.
Bordered table example
<table class="table table-bordered"> <!-- Table content --> </table>
Hover Effect Tables
Add the .table-hover class to highlight rows when users hover over them. This improves user interaction and makes it clear which row is being selected.
Hover table example
<table class="table table-hover"> <!-- Table content --> </table>
Dark Tables
Use the .table-dark class to create a dark-themed table with light text. This is perfect for dark mode interfaces and modern dashboards.
Dark table example
<table class="table table-dark"> <!-- Table content --> </table>
Responsive Tables
Mobile-friendly tables are essential for modern websites. Wrap your table in a .table-responsive div to make it scroll horizontally on smaller screens.
Responsive table structure
<div class="table-responsive"> <table class="table"> <!-- Table content --> </table> </div>
The .table-responsive class enables horizontal scrolling on screens smaller than 992px. You can also use responsive variants:
Table Color Variants
Bootstrap provides color classes for rows and individual cells. Use semantic colors to highlight important information.
Row color classes
Color example
<table class="table"> <tbody> <tr class="table-success"> <td>Success row</td> </tr> <tr class="table-danger"> <td>Danger row</td> </tr> </tbody> </table>
Table Sizing
Control table and cell sizes with Bootstrap utilities. Use .table-sm for compact tables or adjust padding as needed.
Small table example
<table class="table table-sm"> <!-- Compact table with less padding --> </table>
Combined Table Styling
Combine multiple table classes for enhanced styling. This is the most common approach for professional-looking tables.
Combined example
<div class="table-responsive"> <table class="table table-striped table-bordered table-hover"> <thead class="table-dark"> <tr> <th>ID</th> <th>Product</th> <th>Price</th> </tr> </thead> <tbody> <tr> <td>101</td> <td>Laptop</td> <td>$899</td> </tr> </tbody> </table> </div>
What this includes
- Responsive wrapper — Mobile-friendly scrolling
- Striped rows — Alternating colors for readability
- Borders — Clear cell boundaries
- Hover effect — Interactive highlighting
- Dark header — Professional appearance
Real-World Table Examples
Example 1: User List
<div class="table-responsive"> <table class="table table-striped table-hover"> <thead class="table-dark"> <tr> <th>ID</th> <th>Name</th> <th>Email</th> <th>Status</th> </tr> </thead> <tbody> <tr class="table-success"> <td>1</td> <td>John</td> <td>john@email.com</td> <td>Active</td> </tr> </tbody> </table> </div>
Example 2: Pricing Table
<table class="table table-bordered"> <thead class="table-primary"> <tr> <th>Plan</th> <th>Features</th> <th>Price</th> </tr> </thead> <tbody> <tr> <td>Basic</td> <td>10 GB Storage</td> <td>$9.99/mo</td> </tr> </tbody> </table>
Bootstrap Tables Best Practices
Frequently Asked Questions
Common questions about Bootstrap Tables:
Bootstrap Tables are HTML tables enhanced with Bootstrap's CSS classes. They provide professional styling, responsiveness, and various visual options like striped rows, borders, and hover effects without custom CSS.
The table-striped class adds alternating row colors (zebra striping) to tables, improving readability. Every other row gets a slightly darker background color, making it easier to follow rows across columns.
Wrap your table in a div with the table-responsive class. This enables horizontal scrolling on screens smaller than 992px, making tables mobile-friendly and preventing layout breaking on small devices.
Bootstrap offers table-primary (blue), table-success (green), table-danger (red), table-warning (yellow), table-info (light blue), and table-light classes. Apply them to rows or table sections to highlight important data.
Yes, you can combine multiple classes like table table-striped table-bordered table-hover. This creates more feature-rich tables with enhanced styling and interactivity.
Use the table-hover class to highlight rows when users hover over them. This improves user experience by making it clear which row is being selected or viewed.