📖 Scenario: You are creating a simple webpage to display a small and compact table of employee data for a company directory.
🎯 Goal: Build a small and compact table using Bootstrap classes that shows employee names, roles, and departments in a neat, space-saving style.
📋 What You'll Learn
Use Bootstrap 5 classes to style the table
Create a table with three columns: Name, Role, Department
Make the table small and compact using Bootstrap's table-sm class
Use semantic HTML elements for accessibility
Ensure the table is responsive on small screens
💡 Why This Matters
🌍 Real World
Small and compact tables are useful for displaying data clearly in dashboards, reports, or directories where space is limited.
💼 Career
Knowing how to use Bootstrap tables helps web developers quickly build professional and responsive data displays for clients and users.
Progress0 / 4 steps
1
Create the basic HTML table structure
Create a table element with a thead containing a row with three headers: Name, Role, and Department. Then add a tbody with three rows of employee data: Alice Johnson as Developer in Engineering, Bob Smith as Designer in Marketing, and Carol Lee as Manager in Sales.
Bootsrap
Hint
Use the <table> element with <thead> and <tbody>. Add three columns in the header and three rows in the body with the exact employee data.
2
Add Bootstrap table classes for styling
Add the Bootstrap classes table and table-bordered to the table element to style it with borders and default Bootstrap table styling.
Bootsrap
Hint
Add the classes table and table-bordered inside the class attribute of the table tag.
3
Make the table small and compact
Add the Bootstrap class table-sm to the table element along with the existing classes to make the table smaller and more compact.
Bootsrap
Hint
Add the class table-sm to the existing class attribute on the table tag to make it smaller and more compact.
4
Make the table responsive
Wrap the table element inside a div with the Bootstrap class table-responsive to make the table scroll horizontally on small screens.
Bootsrap
Hint
Wrap the entire table element inside a div with the class table-responsive to enable horizontal scrolling on small screens.
Practice
(1/5)
1. What does the Bootstrap class table-sm do when added to a table?
easy
A. Makes the table smaller and more compact by reducing padding
B. Changes the table background color to gray
C. Adds borders around each table cell
D. Makes the table text bold and larger
Solution
Step 1: Understand the purpose of table-sm
The table-sm class in Bootstrap reduces the padding inside table cells, making the table smaller and more compact.
Step 2: Compare with other options
Other options describe unrelated styles like background color, borders, or text size, which table-sm does not control.
Final Answer:
Makes the table smaller and more compact by reducing padding -> Option A
Quick Check:
table-sm = smaller, compact table [OK]
Hint: Remember: 'sm' means small and compact table padding [OK]
Common Mistakes:
Confusing table-sm with color or border classes
Thinking it changes font size or weight
Assuming it adds table stripes or hover effects
2. Which is the correct way to apply a small and compact style to a Bootstrap table?
easy
A. <table class='table compact'>
B. <table class='table table-small'>
C. <table class='table small-table'>
D. <table class='table table-sm'>
Solution
Step 1: Identify Bootstrap's official class for small tables
Bootstrap uses table-sm to make tables small and compact, not table-small, small-table, or compact.
Step 2: Verify syntax correctness
The correct syntax includes both table and table-sm classes inside the class attribute.
Final Answer:
<table class='table table-sm'> -> Option D
Quick Check:
Use table-sm with table class [OK]
Hint: Always pair table-sm with table class [OK]
Common Mistakes:
Using incorrect class names like 'table-small' or 'compact'
Forgetting to include the base 'table' class
Misspelling the class name as 'table sm'
3. What will be the visual difference when rendering this table with Bootstrap classes?
The class small is not a valid Bootstrap class for tables. The correct class to make tables compact is table-sm.
Step 2: Verify other code parts
The table tag is properly closed, tbody is optional, and td is valid for data cells. These are not errors causing lack of compactness.
Final Answer:
The class should be table-sm, not small -> Option B
Quick Check:
Use table-sm for compact tables [OK]
Hint: Use exact class table-sm, not 'small' [OK]
Common Mistakes:
Using 'small' instead of 'table-sm'
Thinking missing tbody breaks compact style
Confusing td and th roles
5. You want a table that is small and compact but also has striped rows and hover effect. Which is the correct class combination?
hard
A. table table-small striped hover
B. table-sm table-striped table-hover
C. table table-sm table-striped table-hover
D. table compact striped hover
Solution
Step 1: Identify required Bootstrap classes
Bootstrap requires the base table class plus modifiers like table-sm for small tables, table-striped for striped rows, and table-hover for hover effect.
Step 2: Check each option for correctness
Only table table-sm table-striped table-hover includes all correct classes with proper prefixes. The other options miss the base table class or use invalid class names.
Final Answer:
table table-sm table-striped table-hover -> Option C
Quick Check:
Combine table with all needed modifiers [OK]
Hint: Always include base table class with modifiers [OK]
Common Mistakes:
Omitting the base table class
Using invalid class names like 'table-small' or 'compact'
Forgetting to add hover or striped classes properly
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.