What is the purpose of a <caption> element in an HTML table?
The <caption> element provides a title or description for the table, helping users understand its content. It improves accessibility and clarity.
Click to reveal answer
beginner
Where should the <caption> element be placed inside a table for correct HTML structure?
The <caption> element should be the first child inside the <table> element, before any <thead>, <tbody>, or <tfoot> sections.
Click to reveal answer
intermediate
How does Bootstrap style the <caption> element by default?
Bootstrap styles the <caption> with padding and a muted color, aligning it to the top-left by default to keep it visually distinct as a table title.
Click to reveal answer
intermediate
Can the <caption> element be placed below the table in HTML?
No, the <caption> element must be placed as the first child inside the <table>. Placing it below the table is invalid HTML and may cause accessibility issues.
Click to reveal answer
intermediate
Why is correct placement of <caption> important for screen readers?
Screen readers announce the <caption> first when reading a table, so placing it correctly ensures users hear the table's title or description before the data.
Click to reveal answer
Where should the <caption> element be placed inside a table?
AAs the first child inside the <table>
BAfter the last <tr> element
COutside the <table> element
DInside the <tbody> only
✗ Incorrect
The
must be the first child inside the
element for valid HTML and accessibility.
What does Bootstrap do to the <caption> element by default?
AAdds padding and a muted color
BCenters it horizontally
CHides it completely
DMakes it bold and large
✗ Incorrect
Bootstrap adds padding and a muted color to the
to visually separate it as a table title.
Why is the <caption> element important for accessibility?
AIt adds color to the table
BIt changes table layout
CIt controls table sorting
DIt provides a title announced by screen readers
✗ Incorrect
Screen readers use the
to announce the table's purpose before reading data.
Is it valid HTML to place <caption> below the table rows?
AOnly if inside <tfoot>
BYes, it is valid
CNo, it must be first child inside <table>
DOnly if styled with CSS
✗ Incorrect
The
must be the first child inside the
element according to HTML standards.
What happens if you omit the <caption> element in a table?
ATable will not display
BScreen readers may lack context for the table
CTable becomes unresponsive
DBootstrap adds a default caption
✗ Incorrect
Without a caption, screen readers may not provide users with the table's purpose or description.
Explain the correct placement of the
element in an HTML table and why it matters.
Think about how screen readers read tables.
You got /3 concepts.
Describe how Bootstrap styles the
element and the visual effect it creates.
Consider how a table title should look.
You got /3 concepts.
Practice
(1/5)
1. Where should the <caption> tag be placed in a Bootstrap table to add a descriptive title?
easy
A. Inside the <tbody> element
B. Outside the <table> element, above the table
C. Directly inside the <table> element, before any <thead> or <tbody>
D. After the closing </table> tag
Solution
Step 1: Understand the HTML structure for tables and correct placement
The <caption> tag must be inside the <table> element to be valid and recognized by browsers. It should come immediately after the opening <table> tag, before <thead> or <tbody>.
Final Answer:
Directly inside the <table> element, before any <thead> or <tbody> -> Option C
Quick Check:
Caption tag inside table = Directly inside the <table> element, before any <thead> or <tbody> [OK]
Hint: Caption must be inside table tag, right after opening [OK]
Common Mistakes:
Placing caption outside the table
Putting caption inside tbody
Adding caption after closing table tag
2. Which Bootstrap class correctly places a table caption below the table?
easy
A. .caption-top
B. .caption-bottom
C. .caption-right
D. .caption-left
Solution
Step 1: Recall Bootstrap caption placement classes and identify for bottom placement
Bootstrap provides .caption-top to place captions above and .caption-bottom to place captions below the table. The class .caption-bottom moves the caption below the table.
Final Answer:
.caption-bottom -> Option B
Quick Check:
Caption below table = .caption-bottom [OK]
Hint: Use .caption-bottom class to move caption below [OK]
Common Mistakes:
Using .caption-top for bottom placement
Using non-existent classes like .caption-right
Not adding any class for placement
3. What will be the visual position of the caption in this Bootstrap table code?
Step 1: Check the caption class and Bootstrap placement behavior
The caption has the class caption-top, which Bootstrap uses to place captions above the table. With caption-top, the caption text "Monthly Sales" will appear visually above the table rows and headers.
Final Answer:
Caption appears above the table -> Option D
Quick Check:
caption-top class = caption above table [OK]
Hint: caption-top means caption above table [OK]
Common Mistakes:
Confusing caption-top with caption-bottom
Thinking caption goes inside table cells
Assuming caption is hidden without class
4. Identify the error in this Bootstrap table caption code:
A. Caption tag is incorrectly placed inside the thead element
B. Missing Bootstrap class on caption
C. Table tag is missing a closing tag
D. Caption text should be inside tbody
Solution
Step 1: Check caption placement rules and identify error
The <caption> tag must be a direct child of the <table> element, not inside <thead> or <tbody>. The caption is placed inside <thead>, which is invalid HTML and will cause rendering issues.
Final Answer:
Caption tag is incorrectly placed inside the thead element -> Option A
Quick Check:
Caption must be direct child of table, not inside thead [OK]
Hint: Caption must be direct child of table, not inside thead [OK]
Common Mistakes:
Placing caption inside thead or tbody
Forgetting to close table tag
Assuming caption needs Bootstrap class
5. You want a Bootstrap table caption to appear below the table on small screens but above the table on larger screens. Which approach is best?
hard
A. Place two captions, one with .caption-top and one with .caption-bottom, then hide/show with responsive utilities
B. Use <caption class="caption-top caption-bottom"> and rely on Bootstrap to toggle automatically
C. Use only .caption-top and rely on CSS media queries to move it below
D. Place caption outside the table and use JavaScript to reposition it
Solution
Step 1: Understand Bootstrap limitations and best responsive approach
Bootstrap's .caption-top and .caption-bottom classes do not toggle automatically based on screen size. Place two captions with different classes and use Bootstrap's responsive display classes (like d-none d-sm-block) to show one above on large screens and below on small screens.
Final Answer:
Place two captions, one with .caption-top and one with .caption-bottom, then hide/show with responsive utilities -> Option A
Quick Check:
Use two captions + responsive classes for placement [OK]
Hint: Use two captions with responsive show/hide classes [OK]
Common Mistakes:
Using both classes on one caption expecting toggle
Trying to move caption with CSS only
Placing caption outside table and using JS unnecessarily
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.