Striped and hover tables make it easier to read rows by adding background colors and highlight effects. This helps users follow data across the table without losing their place.
Striped and hover tables in Bootsrap
<table class="table table-striped table-hover"> <!-- table content --> </table>
Use table-striped to add alternating background colors to rows.
Use table-hover to highlight a row when the mouse moves over it.
<table class="table table-striped"> <!-- striped rows only --> </table>
<table class="table table-hover"> <!-- hover effect only --> </table>
<table class="table table-striped table-hover"> <!-- both striped and hover --> </table>
This example shows a table with both striped rows and hover highlight using Bootstrap classes. The table is accessible with proper scope attributes and a descriptive aria-label. The container adds some spacing around the table.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Striped and Hover Table Example</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet" /> </head> <body> <main class="container my-4"> <h1>Striped and Hover Table</h1> <table class="table table-striped table-hover" aria-label="Sample striped and hover table"> <thead> <tr> <th scope="col">#</th> <th scope="col">Name</th> <th scope="col">Age</th> <th scope="col">City</th> </tr> </thead> <tbody> <tr> <th scope="row">1</th> <td>Alice</td> <td>28</td> <td>New York</td> </tr> <tr> <th scope="row">2</th> <td>Bob</td> <td>34</td> <td>Chicago</td> </tr> <tr> <th scope="row">3</th> <td>Carol</td> <td>22</td> <td>San Francisco</td> </tr> </tbody> </table> </main> </body> </html>
Always use <thead> and <tbody> for better structure and accessibility.
Use scope="col" on header cells and scope="row" on row headers for screen readers.
Bootstrap's table classes work well on all screen sizes and are responsive by default.
Striped tables add alternating background colors to rows for easier reading.
Hover tables highlight the row under the mouse pointer for focus.
Combine table-striped and table-hover classes on a <table> to get both effects easily.
Practice
table-striped class do in a Bootstrap table?Solution
Step 1: Understand the purpose of
Thetable-stripedtable-stripedclass adds alternating background colors to rows, making it easier to read data across the table.Step 2: Differentiate from other classes
Thetable-hoverclass highlights rows on mouse hover, which is different fromtable-striped.Final Answer:
Adds alternating background colors to table rows for easier reading. -> Option AQuick Check:
Striped = alternating row colors [OK]
- Confusing striped with hover effect
- Thinking it changes font or borders
- Assuming it highlights on mouse hover
Solution
Step 1: Check Bootstrap class syntax
Bootstrap requires the basetableclass plus additional classes separated by spaces, liketable-stripedandtable-hover.Step 2: Validate correct class order and spelling
<table class='table table-striped table-hover'>correctly usesclass='table table-striped table-hover'. Order doesn't matter but all classes must be present and spelled correctly.Final Answer:
<table class='table table-striped table-hover'> -> Option DQuick Check:
Use basetableplus both classes [OK]
- Omitting the base 'table' class
- Combining classes without spaces
- Using incorrect class names
<table class='table table-striped table-hover'> <tr><td>Row 1</td></tr> <tr><td>Row 2</td></tr> <tr><td>Row 3</td></tr> </table>
Solution
Step 1: Identify classes used
The table usestable-stripedandtable-hoverclasses together.Step 2: Understand combined effects
table-stripedadds alternating row colors, andtable-hoverhighlights the row under the mouse pointer.Final Answer:
Rows alternate background colors and highlight on mouse hover. -> Option AQuick Check:
Striped + Hover = alternating colors + highlight [OK]
- Thinking only one effect applies
- Ignoring hover effect
- Confusing hover with striped effect
<table class='table table-striped hover'> <tr><td>Data</td></tr> </table>
Solution
Step 1: Check class names
The classhoveralone is not a valid Bootstrap class for hover effect.Step 2: Correct class for hover effect
The correct class istable-hover, which must be used with the basetableclass.Final Answer:
The class should betable-hover, not justhover. -> Option CQuick Check:
Hover effect needstable-hoverclass [OK]
- Using 'hover' instead of 'table-hover'
- Omitting 'table' base class
- Assuming hover needs JavaScript
Solution
Step 1: Combine striped and hover classes on table
Usetable-stripedandtable-hoverwith the basetableclass for row effects.Step 2: Use correct class for dark header
Bootstrap usestable-darkon the<thead>element to style the header with a dark background.Step 3: Verify other options
table-darkon the whole table changes entire table style, not just header.thead-darkis deprecated in Bootstrap 5+.table-header-darkis not a valid class.Final Answer:
<table class='table table-striped table-hover'> <thead class='table-dark'> ... </thead> </table> -> Option BQuick Check:
Usetable-darkontheadfor dark header [OK]
- Applying 'table-dark' to whole table instead of header
- Using deprecated 'thead-dark' class
- Inventing non-existent classes like 'table-header-dark'
Ready to prove it?
Pass the test and this pattern moves unknown
