Small and compact tables help show data neatly in less space. They make tables easier to read on small screens or when you want a simple look.
Small and compact tables in Bootsrap
<table class="table table-sm"> ... table content ... </table>
Use the table-sm class with the table class to make the table compact.
This reduces the padding inside table cells, making rows smaller.
table-sm for compact spacing.<table class="table table-sm"> <thead> <tr> <th>#</th> <th>Name</th> <th>Age</th> </tr> </thead> <tbody> <tr> <td>1</td> <td>Alice</td> <td>25</td> </tr> <tr> <td>2</td> <td>Bob</td> <td>30</td> </tr> </tbody> </table>
table-bordered and table-sm.<table class="table table-bordered table-sm"> <thead> <tr> <th>Product</th> <th>Price</th> </tr> </thead> <tbody> <tr> <td>Pen</td> <td>$1</td> </tr> <tr> <td>Notebook</td> <td>$3</td> </tr> </tbody> </table>
This example shows a small, striped table with less padding using Bootstrap's table-sm class. It is responsive and accessible with proper aria-label and scope attributes.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Small and Compact Table Example</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@4.2.1/dist/css/bootstrap.min.css" rel="stylesheet" /> </head> <body> <main class="container my-4"> <h1>Small and Compact Table</h1> <p>This table uses Bootstrap's <code>table-sm</code> class for a compact look.</p> <table class="table table-striped table-sm" aria-label="Small compact table example"> <thead> <tr> <th scope="col">ID</th> <th scope="col">Name</th> <th scope="col">City</th> </tr> </thead> <tbody> <tr> <td>1</td> <td>Emma</td> <td>New York</td> </tr> <tr> <td>2</td> <td>Liam</td> <td>Chicago</td> </tr> <tr> <td>3</td> <td>Olivia</td> <td>San Francisco</td> </tr> </tbody> </table> </main> </body> </html>
Always add aria-label or caption for accessibility so screen readers understand the table.
Use table-striped or table-bordered with table-sm to improve readability if needed.
Compact tables are great for mobile views but make sure text is still readable.
Use table-sm class with Bootstrap tables to make them small and compact.
Compact tables save space and improve readability on small screens.
Combine with other Bootstrap table classes for better style and accessibility.
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
