1. css
  2. /properties
  3. /caption-side

caption-side

Definition

caption-side is a CSS property that is used to specify the position of a table caption. It is used to control where the caption is placed in relation to the table.

Examples

To position the caption above the table:

caption {
    caption-side: top;
}

To position the caption below the table:

caption {
    caption-side: bottom;
}

To position the caption above the table and style the caption text with a different color:

caption {
    caption-side: top;
    color: blue;
}

To position the caption below the table and give the caption a background color:

caption {
    caption-side: bottom;
    background-color: #f9f9f9;
}

Values

ValueDescription
topPositions the caption above the table. This is the default value.
bottomPositions the caption below the table.

Best Practices

  • Use a meaningful caption: The caption should provide a brief summary of the table's content and its purpose. A good caption will make it easier for users to understand the table's content.
  • Position the caption correctly: Use the caption-side property to position the caption in the best location for the table. If the table is relatively short, placing the caption above the table is probably the best option. If the table is long, placing the caption below the table might be more appropriate.
  • Use a consistent caption position: If you have multiple tables on a single page, use the same position for all captions. This will make it easier for users to quickly understand the table's content.
  • Use CSS to style the caption: Use CSS to style the caption text and background color, if desired. This will make the caption stand out and be more noticeable to users.
  • Test in different browsers: Test the table in different browsers to ensure that the caption is positioned correctly and is easily readable. Some browsers might have different defaults or display the caption slightly differently.
  • Accessibility Considerations: Keep in mind that this property only affects the visual layout of the caption and doesn't affect the accessibility of the table. Make sure that the caption is clear, meaningful, and can be easily read by screen readers.

Browser Comaptibility

ChromeFirefoxSafariInternet ExplorerMicrosoft EdgeOpera
YesYesYesYesYesYes