HTML <caption> Tag

This article discusses html Caption Tag. Hoping it will satisfy the requirements for learning.

The <caption> tag in HTML is used to add a caption or title to an HTML table. The <caption> tag is a child element of the <table> element, and it must come immediately after the opening <table> tag.

Here is a table with a caption:

Example

<!DOCTYPE html> <html> <body> <table> <caption>Wedding budget</caption> <tr> <th>car</th> <th>Food</th> </tr> <tr> <td>dresses</td> <td>$8000</td> </tr> </table> </body> </html>

Use CSS to position table captions:

Example

<!DOCTYPE html> <html> <body> <table> <caption style="text-align:center">Wedding Budget</caption><tr> <th>Wedding</th><th>Savings</th> </tr> <tr> <td>January</td> <td>$8000</td> </tr> </table> <table> <caption style="caption-side:bottom">My budget</caption> <tr> <th>Month</th> <th>Savings</th> </tr> <tr> <td>January</td> <td>$8000</td> </tr> </table> </body></html>


Uses and Definition

Html Caption Tag <caption> is used to specify the table’s caption.

To display a caption, insert the <caption> tag immediately after the <table> tag.

Advice: The caption of a table will be center-aligned above a table by default when placed above it. The CSS properties text-align and caption-side may be used for aligning and placing captions.


Global Attributes

HTML’s Global Attributes work with the caption tag <caption>.


Event Attributes

The HTML Event Attributes are likewise accessible by the <caption> tag.


CSS Settings By Default

In most browsers, the <caption> tag renders the following default values:

Example

<!DOCTYPE html> <html> <body> <p> caption { display: table-caption; text-align: center; } </p> </body> </html>

Browser Compatibility

Element
<caption>YesYesYesYesYes

HTML caption tags Benefits

The <caption> tag in HTML has several benefits:

  • The <caption> tag provides a way to add a title or description to an HTML table. This can help users understand the content of the table and its purpose.
  • Adding a <caption> tag to a table can improve accessibility for users who rely on screen readers or other assistive technologies to access web content. The <caption> tag provides a way to describe the content of the table in a more accessible way.
  • Including a <caption> tag in your HTML table can also help with search engine optimization (SEO). Search engines use the content of the <caption> tag to understand the content of the table and to index it appropriately.
  • You can use CSS to style the <caption> tag and make it visually stand out from the rest of the table. This allows you to customize the appearance of the caption to match the design of your website.
If you found this article informative, then do share this valuable information with your friends by clicking on the links below.
We value your feedback.
+1
0
+1
0
+1
0
+1
0
+1
0
+1
0
+1
0

Subscribe To Our Newsletter
Enter your email to receive a weekly round-up of our best posts. Learn more!
icon

Leave a Reply

Your email address will not be published. Required fields are marked *