CSS Properties
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.
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
Value | Description |
---|---|
top | Places the caption above the table. This is the default value. |
bottom | Places the caption below the table. |
inherit | Inherits the caption-side value from its parent element. |
📄 Example
In this example, we'll place the caption at the bottom of the table.
<!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:
Author
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
If you have any doubts regarding this article (CSS caption-side Property), please comment here. I will help you immediately.