How to Caption an HTML table using the caption tag
In this tutorial, we will learn “how to Caption an HTML table” using the Caption tag. We will also provide you with an example so that you can have its practical knowledge.
What is Caption tag?
It is an HTML tag using which a Caption is added to an HTML table. By default, unlike the td tag text alignment, the caption tag adds a center-aligned caption above the table. However, if you want to align it to the left or right, text-align property of CSS can be used.
Rules to use the Caption tag
The Caption tag should conform to the below rules:
- It is always used along with the tag in HTML
- It must always be used as the first tag after the tag
- Only one caption per table can be specified
Attributes of the Caption tag
Every HTML tag has some attributes that give it more power for functioning as per the user’s requirements. The caption tag supports following attributes:
- Element-specific attribute: It does not have its own attributes.
- Global attributes: It supports all Global attributes in HTML. Some of the examples of Global attributes are class, hidden, id, title, lang, and style.
- Event Handler Content attributes: It supports all Event Handler Content attributes in HTML. With the help of an even handler content attribute you can call a script within HTML. Some of the examples of Even Handler Content attributes are onclick, oncancel, onselect, onshow, onerror, and onfocus.
Browser Support for the Caption Tag
The Caption tag is supported by all major browsers, such as Google Chrome, Mozilla Firefox, Internet Explorer, Opera, and Safari.
Here is an example showing “how to Caption an HTML table using the caption tag.” It has four rows with two columns.