The Wayback Machine - https://web.archive.org/web/20250316084126/https://www.geeksforgeeks.org/css-caption-side-property/
Open In App

CSS caption-side Property

Last Updated : 26 Aug, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Share
Report
News Follow

This property is used to specify the position where the table caption is placed. It is used in HTML Tables. This property can be used with any element whose display property is set to caption-side.

Syntax: 

caption-side: top|bottom|block-start|block-end|inline-start|inline-end|initial|inherit;

Properties:   

  • top: It specifies that the table caption is placed at the top of the table. It is the default value.
  • bottom: This property specifies that the table caption is placed at the bottom of the table.
  • initial: It sets the property to its default value.

Example: In this example, we are using caption-side:top; property.

HTML
<!DOCTYPE html>
<html>

<head>
    <title>caption-side property</title>
    <style>
        .geeks {
            caption-side: top;
        }
    </style>
</head>

<body>
    <center>
        <h1 style="color:green;">
            GeeksForGeeks
        </h1>
        <h2>
            caption-side: top:
        </h2>
        <table class="geeks" border="1">
            <caption>
                Table 4.1 Student Details
            </caption>
            <tr>
                <th>Student Name</th>
                <th>Enroll_no.</th>
                <th>Address</th>
            </tr>
            <tr>
                <td>Hritik Bhatnagar</td>
                <td>234</td>
                <td>Delhi</td>
            </tr>
            <tr>
                <td>Govind madan</td>
                <td>235</td>
                <td>kolkata</td>
            </tr>
            <tr>
                <td>Suraj Roy</td>
                <td>236</td>
                <td>Mumbai</td>
            </tr>
            <tr>
                <td> Dhruv Mishra</td>
                <td>237</td>
                <td>Dehadun</td>
            </tr>
        </table>
    </center>
</body>

</html>

Output: 

Example:  In this example, we are using caption-side:bottom; property.

HTML
<!DOCTYPE html>
<html>

<head>
    <title>caption-side property</title>
    <style>
        .geeks {
            caption-side: bottom;
        }
    </style>
</head>

<body>
    <center>
        <h1 style="color:green;">
            GeeksForGeeks
        </h1>
        <h2>
            caption-side: bottom:
        </h2>
        <table class="geeks" border="1">
            <caption>
                Table 4.1 Student Details
            </caption>
            <tr>
                <th>Student Name</th>
                <th>Enroll_no.</th>
                <th>Address</th>
            </tr>
            <tr>
                <td>Hritik Bhatnagar</td>
                <td>234</td>
                <td>Delhi</td>
            </tr>
            <tr>
                <td>Govind madan</td>
                <td>235</td>
                <td>kolkata</td>
            </tr>
            <tr>
                <td>Suraj Roy</td>
                <td>236</td>
                <td>Mumbai</td>
            </tr>
            <tr>
                <td> Dhruv Mishra</td>
                <td>237</td>
                <td>Dehadun</td>
            </tr>
        </table>
    </center>
</body>

</html>

Output: 

Example:   In this example, we are using caption-side: initial; property.

HTML
<!DOCTYPE html>
<html>
<head>
    <style>
        .geeks {
            caption-side: initial;
        }
    </style>
</head>

<body>
    <center>
        <h1 style="color:green;">
              GeeksForGeeks
          </h1>

        <h2>caption-side:initial:</h2>
        <table class="geeks" border="1">
            <caption>Table 4.1 Student Details</caption>
            <tr>
                <th>Student Name</th>
                <th>Enroll_no.</th>
                <th>Address</th>
            </tr>
            <tr>
                <td>Hritik Bhatnagar</td>
                <td>234</td>
                <td>Delhi</td>
            </tr>
            <tr>
                <td>Govind madan</td>
                <td>235</td>
                <td>kolkata</td>
            </tr>
            <tr>
                <td>Suraj Roy</td>
                <td>236</td>
                <td>Mumbai</td>
            </tr>
            <tr>
                <td> Dhruv Mishra</td>
                <td>237</td>
                <td>Dehadun</td>
            </tr>
        </table>
    </center>
</body>
</html>

Output: 

Supported Browsers: The browsers supported by CSS caption-side Property are listed below:  

  • Google Chrome 1.0
  • Edge 12.0
  • Internet Explorer 8.0
  • Firefox 1.0
  • Opera 4.0
  • Safari 1.0

CSS caption-side Property – FAQs

What does the caption-side property do in CSS?

The caption-side property in CSS specifies the placement of a table caption. It determines whether the caption appears above or below the table.

What values can be used with caption-side?

The caption-side property accepts values like top, bottom, and their block-flow equivalents start and end, which depend on the table’s writing mode.

Can I position a caption on the left or right of a table?

No, caption-side only controls the placement at the top or bottom of the table. Horizontal placement (left or right) is not supported directly by caption-side.

Does caption-side affect the table layout?

Yes, changing the caption position can affect the overall table layout, especially when using margin or padding to style the caption.

What is the default value for caption-side?

The default value for caption-side is top, meaning the caption appears above the table unless otherwise specified.



Next Article

Similar Reads

three90RightbarBannerImg