Discover how a tiny change in table style can make your webpage look cleaner and more professional instantly!
Why Small and compact tables in Bootsrap? - Purpose & Use Cases
Imagine you have a webpage showing a list of products with prices and descriptions. You create a big table with lots of space between rows and columns to make it look neat.
But the table takes up too much space, pushing important content down. Users have to scroll a lot, especially on small screens. Making the table smaller by hand means changing many styles and risking readability.
Bootstrap's small and compact tables let you shrink the table's padding and spacing easily. This keeps the table readable but uses less space, making your page cleaner and easier to navigate.
<table> <tr><td>Product 1</td><td>$10</td></tr> <tr><td>Product 2</td><td>$20</td></tr> </table>
<table class="table table-sm"> <tr><td>Product 1</td><td>$10</td></tr> <tr><td>Product 2</td><td>$20</td></tr> </table>
You can create neat, space-saving tables that fit well on all devices without extra work.
On a dashboard showing many stats, small tables let you display more data at once without overwhelming the user or cluttering the page.
Manual spacing in tables can waste space and hurt user experience.
Bootstrap's small tables reduce padding for compact, readable layouts.
This helps build cleaner, more user-friendly pages quickly.
Practice
table-sm do when added to a table?Solution
Step 1: Understand the purpose of
Thetable-smtable-smclass 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, whichtable-smdoes not control.Final Answer:
Makes the table smaller and more compact by reducing padding -> Option AQuick Check:
table-sm= smaller, compact table [OK]
- Confusing
table-smwith color or border classes - Thinking it changes font size or weight
- Assuming it adds table stripes or hover effects
Solution
Step 1: Identify Bootstrap's official class for small tables
Bootstrap usestable-smto make tables small and compact, nottable-small,small-table, orcompact.Step 2: Verify syntax correctness
The correct syntax includes bothtableandtable-smclasses inside theclassattribute.Final Answer:
<table class='table table-sm'> -> Option DQuick Check:
Usetable-smwithtableclass [OK]
table-sm with table class [OK]- Using incorrect class names like 'table-small' or 'compact'
- Forgetting to include the base 'table' class
- Misspelling the class name as 'table sm'
<table class='table table-sm'> <tr><td>Item</td><td>Price</td></tr> <tr><td>Apple</td><td>$1</td></tr> </table>
Solution
Step 1: Understand the effect of
Thetable-smon table cellstable-smclass reduces the padding inside each cell, making the table appear smaller and more compact.Step 2: Check other options for unrelated styles
Italic text, background color, or striped rows are not caused bytable-smbut by other classes liketable-stripedor custom CSS.Final Answer:
The table cells have less padding, making the table more compact -> Option AQuick Check:
table-sm= less padding, compact table [OK]
- Assuming
table-smchanges text style or colors - Confusing with striped or hover effects
- Expecting background color changes
<table class='table small'> <tr><td>Name</td><td>Age</td></tr> <tr><td>John</td><td>30</td></tr> </table>
What is the error?
Solution
Step 1: Check the class name for compact tables
The classsmallis not a valid Bootstrap class for tables. The correct class to make tables compact istable-sm.Step 2: Verify other code parts
The table tag is properly closed,tbodyis optional, andtdis valid for data cells. These are not errors causing lack of compactness.Final Answer:
The class should betable-sm, notsmall-> Option BQuick Check:
Usetable-smfor compact tables [OK]
table-sm, not 'small' [OK]- Using 'small' instead of 'table-sm'
- Thinking missing
tbodybreaks compact style - Confusing
tdandthroles
Solution
Step 1: Identify required Bootstrap classes
Bootstrap requires the basetableclass plus modifiers liketable-smfor small tables,table-stripedfor striped rows, andtable-hoverfor hover effect.Step 2: Check each option for correctness
Onlytable table-sm table-striped table-hoverincludes all correct classes with proper prefixes. The other options miss the basetableclass or use invalid class names.Final Answer:
table table-sm table-striped table-hover -> Option CQuick Check:
Combinetablewith all needed modifiers [OK]
table class with modifiers [OK]- Omitting the base
tableclass - Using invalid class names like 'table-small' or 'compact'
- Forgetting to add hover or striped classes properly
Ready to prove it?
Pass the test and this pattern moves unknown
