📖 Scenario: You are creating a simple webpage to display a list of fruits and their colors in a neat table. You want to use Bootstrap to make the table look clean and professional.
🎯 Goal: Build a webpage with a Bootstrap styled table showing fruit names and their colors.
📋 What You'll Learn
Use Bootstrap 5 CSS from CDN
Create a table with two columns: Fruit and Color
Add Bootstrap classes to style the table with borders and stripes
Make sure the page uses semantic HTML and is responsive
💡 Why This Matters
🌍 Real World
Tables are common on websites to show data like product lists, schedules, or reports. Using Bootstrap makes tables look good quickly without writing custom CSS.
💼 Career
Knowing how to use Bootstrap for tables is useful for front-end web developers and designers to create professional and responsive layouts efficiently.
Progress0 / 4 steps
1
Create the basic HTML structure with a table
Create a basic HTML5 page with lang="en", charset="UTF-8", and a viewport meta tag. Inside the <body>, add a <table> element with a thead containing two headers: Fruit and Color. Add a tbody with three rows: Apple with color Red, Banana with color Yellow, and Grape with color Purple.
Bootsrap
Hint
Remember to use <thead> for headers and <tbody> for the data rows.
2
Add Bootstrap CSS link
Add the Bootstrap 5 CSS CDN link inside the <head> section, before the <title> tag. Use the href https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css and set rel="stylesheet".
Bootsrap
Hint
Use a <link> tag with rel="stylesheet" and the Bootstrap CDN URL as href.
3
Add Bootstrap classes to style the table
Add the Bootstrap classes table, table-bordered, and table-striped to the <table> element to add borders and striped rows.
Bootsrap
Hint
Add all three classes inside the class attribute separated by spaces.
4
Wrap the table in a responsive container
Wrap the <table> inside a <div> with the Bootstrap class table-responsive to make the table scroll horizontally on small screens.
Bootsrap
Hint
Put the entire <table> inside a <div> with class table-responsive.
Practice
(1/5)
1. What does adding class="table" to a <table> element in Bootstrap do?
easy
A. Adds sorting functionality to the table columns
B. Makes the table responsive automatically
C. Applies basic Bootstrap styling to the table for better appearance
D. Changes the table background color to blue
Solution
Step 1: Understand the role of class="table"
This class applies Bootstrap's default styling to tables, improving their look with padding, borders, and font styles.
Step 2: Identify what it does not do
It does not make tables responsive, add sorting, or change background color by default.
Final Answer:
Applies basic Bootstrap styling to the table for better appearance -> Option C
Quick Check:
Bootstrap table class = basic styling [OK]
Hint: Remember: table class styles tables simply [OK]
Common Mistakes:
Thinking it makes tables responsive
Assuming it adds sorting features
Believing it changes background color automatically
2. Which of the following is the correct way to add striped rows to a Bootstrap table?
easy
A. <table class="table-striped-table">
B. <table class="table-striped">
C. <table class="striped">
D. <table class="table table-striped">
Solution
Step 1: Understand Bootstrap table classes
The base class table must always be included for Bootstrap table styling to work.
Step 2: Add table-striped alongside table
To get striped rows, both classes must be present: class="table table-striped".
Final Answer:
<table class="table table-striped"> -> Option D
Quick Check:
Base table + table-striped = striped rows [OK]
Hint: Always include table class first for Bootstrap tables [OK]
Common Mistakes:
Using only table-striped without table
Swapping class order incorrectly
Using wrong class names like striped
3. What will be the visual effect of this code snippet?