Front-end Tutorials

Front-end Tutorials

HTMLCSSSassJavaScriptReactJS
CMS Tutorials

CMS Tutorials

WordPress
Tutorials expand

CSS Topics

CSS caption-side Property

Posted in CSS Tutorial
Updated on Oct 02, 2024
By Mari Selvan
👁️ 26 - Views
⏳ 4 mins
💬 1 Comment
CSS caption-side Property

Photo Credit to CodeToFun

🙋 Introduction

The caption-side property in CSS is used to control the placement of table captions. It allows you to specify whether the caption should appear at the top or the bottom of a table.

This property is particularly useful for enhancing the readability and accessibility of table data by clearly labeling the table's purpose or contents.

💡 Syntax

The syntax for the caption-side property is simple. It can be applied to the <caption> element of a table.

Syntax
Copied
Copy To Clipboard
caption {
  caption-side: value;
}

Here, value can be one of the predefined keywords described below.

🎛️ Default Value

The default value of the caption-side property is top, meaning that the caption will appear above the table by default.

🏠 Property Values

ValueDescription
topPlaces the caption above the table. This is the default value.
bottomPlaces the caption below the table.
inheritInherits the caption-side value from its parent element.

📄 Example

In this example, we'll place the caption at the bottom of the table.

index.html
Copied
Copy To Clipboard
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>CSS caption-side Example</title>
  <style>
    caption {
      caption-side: bottom;
    }
  </style>
</head>
<body>
  <h1>Table with Caption at the Bottom</h1>
  <table border="1">
    <caption>This is a table caption</caption>
    <tr>
      <th>Header 1</th>
      <th>Header 2</th>
    </tr>
    <tr>
      <td>Data 1</td>
      <td>Data 2</td>
    </tr>
  </table>
</body>
</html>

🖥️ Browser Compatibility

The caption-side property is widely supported across all modern browsers, including the latest versions of Chrome, Firefox, Safari, Edge, and Opera. However, as always, it is a good practice to test your website across different browsers to ensure compatibility.

🎉 Conclusion

The caption-side property is a useful tool for web developers looking to control the placement of table captions.

By specifying whether the caption should appear at the top or the bottom of the table, you can enhance the readability and organization of your table data. Experiment with this property to see how it can improve the presentation of your tables.

👨‍💻 Join our Community:

To get interesting news and instant updates on Front-End, Back-End, CMS and other Frameworks. Please Join the Telegram Channel:

Author

author
👋 Hey, I'm Mari Selvan

For over eight years, I worked as a full-stack web developer. Now, I have chosen my profession as a full-time blogger at codetofun.com.

Buy me a coffee to make codetofun.com free for everyone.

Buy me a Coffee

Share Your Findings to All

Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
We make use of cookies to improve our user experience. By using this website, you agree with our Cookies Policy
AgreeCookie Policy