Bird
Raised Fist0
Bootsrapmarkup~5 mins

Table caption placement in Bootsrap

Choose your learning style10 modes available
Introduction

Table captions help describe what the table is about. Placing captions correctly makes tables easier to understand and more accessible.

When you want to give a clear title or description to a table on a webpage.
When you want screen readers to announce the table's purpose to users with visual impairments.
When you want to improve the overall accessibility and clarity of your data presentation.
When you want to follow good HTML and Bootstrap practices for tables.
When you want to style captions differently using Bootstrap classes.
Syntax
Bootsrap
<table class="table">
  <caption>Caption text here</caption>
  <!-- table rows and cells -->
</table>

The <caption> tag must be the first child inside the <table> element.

Bootstrap styles the caption by default to appear above the table with some spacing.

Examples
This example shows a simple table with a caption placed above it.
Bootsrap
<table class="table">
  <caption>Monthly Sales Report</caption>
  <thead>
    <tr><th>Month</th><th>Sales</th></tr>
  </thead>
  <tbody>
    <tr><td>January</td><td>$1000</td></tr>
  </tbody>
</table>
Using Bootstrap's caption-top class places the caption above the table.
Bootsrap
<table class="table caption-top">
  <caption>Top 5 Products</caption>
  <tbody>
    <tr><td>Product A</td></tr>
  </tbody>
</table>
Using Bootstrap's caption-bottom class places the caption below the table.
Bootsrap
<table class="table caption-bottom">
  <caption>Summary Data</caption>
  <tbody>
    <tr><td>Data 1</td></tr>
  </tbody>
</table>
Sample Program

This page shows three tables with captions placed in different positions using Bootstrap classes. The first table uses the default caption placement above the table. The second uses caption-top to explicitly place the caption above. The third uses caption-bottom to place the caption below the table.

Bootsrap
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <title>Bootstrap Table Caption Placement</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>Table Caption Placement Example</h1>

    <section>
      <h2>Caption Above (default)</h2>
      <table class="table">
        <caption>Fruits and Prices</caption>
        <thead>
          <tr><th>Fruit</th><th>Price</th></tr>
        </thead>
        <tbody>
          <tr><td>Apple</td><td>$1.00</td></tr>
          <tr><td>Banana</td><td>$0.50</td></tr>
        </tbody>
      </table>
    </section>

    <section>
      <h2>Caption Above with <code>caption-top</code></h2>
      <table class="table caption-top">
        <caption>Vegetables and Prices</caption>
        <thead>
          <tr><th>Vegetable</th><th>Price</th></tr>
        </thead>
        <tbody>
          <tr><td>Carrot</td><td>$0.80</td></tr>
          <tr><td>Broccoli</td><td>$1.20</td></tr>
        </tbody>
      </table>
    </section>

    <section>
      <h2>Caption Below with <code>caption-bottom</code></h2>
      <table class="table caption-bottom">
        <caption>Drinks and Prices</caption>
        <thead>
          <tr><th>Drink</th><th>Price</th></tr>
        </thead>
        <tbody>
          <tr><td>Water</td><td>$0.30</td></tr>
          <tr><td>Juice</td><td>$1.50</td></tr>
        </tbody>
      </table>
    </section>
  </main>
</body>
</html>
OutputSuccess
Important Notes

Always put the <caption> tag as the first child inside the <table> for proper HTML structure.

Bootstrap provides caption-top and caption-bottom classes to control caption placement easily.

Captions improve accessibility by giving screen readers a clear description of the table.

Summary

Use the <caption> tag inside tables to add descriptive titles.

Bootstrap styles captions and lets you place them above or below with classes.

Proper caption placement helps all users understand your tables better.

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

  1. 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>.
  2. Final Answer:

    Directly inside the <table> element, before any <thead> or <tbody> -> Option C
  3. 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

  1. 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.
  2. Final Answer:

    .caption-bottom -> Option B
  3. 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?
<table class="table">
  <caption class="caption-top">Monthly Sales</caption>
  <thead>
    <tr><th>Product</th><th>Sales</th></tr>
  </thead>
  <tbody>
    <tr><td>Apples</td><td>100</td></tr>
  </tbody>
</table>
medium
A. Caption is hidden and not visible
B. Caption appears below the table
C. Caption appears inside the first cell
D. Caption appears above the table

Solution

  1. 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.
  2. Final Answer:

    Caption appears above the table -> Option D
  3. 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:
<table class="table">
  <thead>
    <caption>User Data</caption>
    <tr><th>Name</th><th>Age</th></tr>
  </thead>
  <tbody>
    <tr><td>Alice</td><td>30</td></tr>
  </tbody>
</table>
medium
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

  1. 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.
  2. Final Answer:

    Caption tag is incorrectly placed inside the thead element -> Option A
  3. 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

  1. 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.
  2. Final Answer:

    Place two captions, one with .caption-top and one with .caption-bottom, then hide/show with responsive utilities -> Option A
  3. 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 unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard