CSS caption-side

The caption-side property in CSS specifies the placement of a table caption.

There are four possible values for the caption-side property:

Let's see some examples of how the caption-side property works:

Result:
Caption at the top
Row 1, cell 1 Row 1, cell 2
Row 2, cell 1 Row 2, cell 2
<table>
  <caption style="caption-side: top;">Caption at the top</caption>
  <tr>
    <td>Row 1, cell 1</td>
    <td>Row 1, cell 2</td>
  </tr>
  <tr>
    <td>Row 2, cell 1</td>
    <td>Row 2, cell 2</td>
  </tr>
</table>

In this example, the caption is placed at the top of the table.

Result:
Caption at the bottom
Row 1, cell 1 Row 1, cell 2
Row 2, cell 1 Row 2, cell 2
<table>
  <caption style="caption-side: bottom;">Caption at the bottom</caption>
  <tr>
    <td>Row 1, cell 1</td>
    <td>Row 1, cell 2</td>
  </tr>
  <tr>
    <td>Row 2, cell 1</td>
    <td>Row 2, cell 2</td>
  </tr>
</table>

In this example, the caption is placed at the bottom of the table.

Result:
Caption to the left
Row 1, cell 1 Row 1, cell 2
Row 2, cell 1 Row 2, cell 2
<table>
  <caption style="caption-side: left;">Caption to the left</caption>
  <tr>
    <td>Row 1, cell 1</td>
    <td>Row 1, cell 2</td>
  </tr>
  <tr>
    <td>Row 2, cell 1</td>
    <td>Row 2, cell 2</td>
  </tr>
</table>

In this example, the caption is placed to the left of the table.

Result:
Caption to the right
Row 1, cell 1 Row 1, cell 2
Row 2, cell 1 Row 2, cell 2
<table>
  <caption style="caption-side: right;">Caption to the right</caption>
  <tr>
    <td>Row 1, cell 1</td>
    <td>Row 1, cell 2</td>
  </tr>
  <tr>
    <td>Row 2, cell 1</td>
    <td>Row 2, cell 2</td>
  </tr>
</table>

In this example, the caption is placed to the right of the table.

By using the caption-side property, you can control the placement of captions in your tables according to your design needs.