Controlling the Position of Table Caption using CSS

The CSS caption-side property is used to control the position of a table caption. It determines whether the caption appears at the top or bottom of the table. By default, table captions are placed at the top of the table.

Syntax

caption {
    caption-side: value;
}

Possible Values

Value Description
top Places the caption at the top of the table (default)
bottom Places the caption at the bottom of the table

Example 1: Caption at Bottom

The following example demonstrates placing the table caption at the bottom −

<!DOCTYPE html>
<html>
<head>
<style>
    table {
        margin: 20px auto;
        border-collapse: collapse;
        border: 2px solid #333;
    }
    th, td {
        border: 1px solid #ddd;
        padding: 10px;
        text-align: center;
    }
    th {
        background-color: #f2f2f2;
    }
    caption {
        caption-side: bottom;
        font-weight: bold;
        background-color: #e6f3ff;
        padding: 8px;
        margin-top: 5px;
    }
</style>
</head>
<body>
    <table>
        <caption>Sales Data - Q1 2024</caption>
        <tr>
            <th>Month</th>
            <th>Revenue</th>
        </tr>
        <tr>
            <td>January</td>
            <td>$50,000</td>
        </tr>
        <tr>
            <td>February</td>
            <td>$55,000</td>
        </tr>
        <tr>
            <td>March</td>
            <td>$60,000</td>
        </tr>
    </table>
</body>
</html>
A table with headers "Month" and "Revenue" displaying sales data for Q1 2024. The caption "Sales Data - Q1 2024" appears at the bottom of the table with light blue background styling.

Example 2: Caption at Top (Default)

The following example shows the default caption position at the top −

<!DOCTYPE html>
<html>
<head>
<style>
    table {
        margin: 20px auto;
        border-collapse: collapse;
        border: 2px solid #333;
    }
    th, td {
        border: 1px solid #ddd;
        padding: 10px;
        text-align: center;
    }
    th {
        background-color: #f9f9f9;
    }
    caption {
        caption-side: top;
        font-weight: bold;
        color: #333;
        background-color: #fffacd;
        padding: 8px;
        margin-bottom: 5px;
    }
</style>
</head>
<body>
    <table>
        <caption>Employee Information</caption>
        <tr>
            <th>Name</th>
            <th>Department</th>
        </tr>
        <tr>
            <td>John Smith</td>
            <td>Engineering</td>
        </tr>
        <tr>
            <td>Sarah Johnson</td>
            <td>Marketing</td>
        </tr>
    </table>
</body>
</html>
A table with headers "Name" and "Department" showing employee information. The caption "Employee Information" appears at the top of the table with light yellow background styling.

Conclusion

The caption-side property provides a simple way to control table caption positioning. Use top for traditional caption placement or bottom when you want the caption to serve as a summary or footnote for the table data.

Updated on: 2026-03-15T13:52:18+05:30

836 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements