Back to Content

caption-side

files/en-us/web/css/reference/properties/caption-side/index.md

latest3.1 KB
Original Source

The caption-side CSS property puts the content of a table's {{HTMLElement("caption")}} on the specified side. The values are relative to the {{cssxref("writing-mode")}} of the table.

{{InteractiveExample("CSS Demo: caption-side")}}

css
caption-side: top;
css
caption-side: bottom;
html
<section class="default-example" id="default-example">
  <table class="transition-all" id="example-element">
    <caption>
      Famous animals
    </caption>
    <tbody>
      <tr>
        <th>Name</th>
        <th>Location</th>
      </tr>
      <tr>
        <td>Giraffe</td>
        <td>Africa</td>
      </tr>
      <tr>
        <td>Penguin</td>
        <td>Antarctica</td>
      </tr>
      <tr>
        <td>Sloth</td>
        <td>South America</td>
      </tr>
      <tr>
        <td>Tiger</td>
        <td>Asia</td>
      </tr>
    </tbody>
  </table>
</section>
css
table {
  font-size: 1.2rem;
  text-align: left;
  color: black;
}

th,
td {
  padding: 0.2rem 1rem;
}

caption {
  background: #ffcc33;
  padding: 0.5rem 1rem;
}

tr {
  background: #eeeeee;
}

tr:nth-child(even) {
  background: #cccccc;
}

Syntax

css
/* Directional values */
caption-side: top;
caption-side: bottom;

/* Global values */
caption-side: inherit;
caption-side: initial;
caption-side: revert;
caption-side: revert-layer;
caption-side: unset;

The caption-side property is specified as one of the keyword values listed below.

Values

  • top
    • : The caption box should be positioned at the block start side of the table.
  • bottom
    • : The caption box should be positioned at the block end side of the table.

[!NOTE] The CSS logical properties and values module defines two logical values, inline-start and inline-end, to position the caption box at the inline start edge and inline end edge of the table, respectively. These values are not supported in any browsers.

Formal definition

{{cssinfo}}

Formal syntax

{{csssyntax}}

Examples

Setting captions above and below

HTML

html
<table class="top">
  <caption>
    Caption ABOVE the table
  </caption>
  <tbody>
    <tr>
      <td>Some data</td>
      <td>Some more data</td>
    </tr>
  </tbody>
</table>




<table class="bottom">
  <caption>
    Caption BELOW the table
  </caption>
  <tbody>
    <tr>
      <td>Some data</td>
      <td>Some more data</td>
    </tr>
  </tbody>
</table>

CSS

css
.top caption {
  caption-side: top;
}

.bottom caption {
  caption-side: bottom;
}

table {
  border: 1px solid red;
}

td {
  border: 1px solid blue;
}

Result

{{EmbedLiveSample('Setting_captions_above_and_below', 'auto', 160)}}

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}

See also