×

Caption Tag in HTML

Caption Tag in HTML: The < caption > tag in HTML describes the heading of a table in the HTML text. Browsers typically make the text found above the table in the < caption > tag, but with the CSS caption-side property, we can adjust this behavior. It is also commonly known as the item < caption>.

Syntax

In HTML the < caption > tag syntax is as follows:

<body>
<table>
<caption>Price of Vegetable</caption>
<tr>
<th>Item</th>
<th>Amount</th>
</tr>
<tr>
<td>Tomato</td>
<td>$2</td>
</tr>
<tr>
<td>Potato</td>
<td>$19</td>
</tr>
<tr>
<td>Cauliflower</td>
<td>$9</td>
</tr>
<tr>
<td>Carrot</td>
<td>$11</td>
</tr>
</table>
</body>

Output:

Attributes

AttributeDescriptionHtml Compatibility
        AlignThe Listed attribute showing how the caption aligns in the table. One of the following values may be:   Left-means the caption appears at the left- hand side of the table. Top-indicates the caption above the table shows. Right-means the caption appears at the right- hand side of the table. Upper-means the caption appears in the table below.        HTML 4.01 outdated, HTML5 obsolete (Instead, using CSS properties like text-align and caption-side)
  • The item HTML < caption > is located inside the tag < body>.
  • The tag < caption > is the first tag to come up after the tag < table>.
  • The tag <th> describes the header cells that are shown in the table as bold, center-aligned text.

  • The tag < td > specifies the table's normal cells, which are shown as normal-weight, left-aligned text.
  • The class < table > is composed of the tags <tr>, < th >, and < td>.
  • The tag < tr > describes the rows of a line. The table must have a minimum of one row.
  • Many browsers make the < caption > tag above the line, but with the CSS caption-side property, you can adjust that conduct.

Example

Definitions on the use of < caption > tags Transitional in HTML5, HTML 4.01, XHTML 1.0 Transitional, XHTML 1.0 Strict and XHTML 1.1 will be addressed in the tags below.

HTML5

If you have built a new HTML5 webpage, the < caption > tag may look like:

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>HTML5 Example by www.tutorialandexample.com</title>
</head>
<body>
<table>
<caption>This is the caption for the table</caption>
<tr>
<th>Column 1 Heading</th>
<th>Column 2 Heading</th>
<th>Column 3 Heading</th>
</tr>
<tr>
<td>Data 1, Row 2</td>
<td>Data 2, Row 2</td>
<td>Data  3, Row 2</td>
</tr>
<tr>
<td>Data 1, Row 3</td>
<td>Data 2, Row 3</td>
<td>Data 3, Row 3</td>
</tr>
<tr>
<td>Data 1, Row 4</td>
<td>Data 2, Row 4</td>
<td>Data 3, Row 4</td>
</tr>
</table>
</body>
</html>

Output:

In this example of the HTML5 Document, we built a table using the tag < table>. The < caption > is the first descendent of the < table > tag. The table would have three columns and four rows.  Table Row 1 is identified using the first tag <tr>. It has three cells in the table heading identified with <th> tag. Table rows 2-4 use the tag < td > to describe normal table cells.

Example 2

<!DOCTYPE html>
<html>
<head>
<title>Caption Tag</title>
<style>
table, td, th { 
border: 3px solid gray; 
border-collapse: collapse;} 
</style>
</head>
<body>
<h2>Example of Caption tag</h2>
<table width="800">
<caption>College Students Details</caption>
<thead>
<tr>
<th>Sr. No.</th>
<th>Name</th>
<th>Mob No.</th>
</tr>
</thead>
<tbody>
<tr>
<td>1.</td>
<td>Himanshu Agrawal</td>
<td>9822546658</td>
</tr>
<tr>
<td>2.</td>
<td>Shivam Singh</td>
<td>7581135665</td>
</tr>
<tr>
<td>3.</td>
<td>Akriti Sharma</td>
<td>9154454581</td>
</tr>
</tbody>
</table>
</body>
</html>

Output:


Related Topics

HTML Attributes

HTML Attributes provide the additional information about HTML elements. Attributes are always specified in the start tag. Attributes usually comes in pairs. lang Attribute This attribute helps in declaring the language...

2 minutes read.

HTML <script> Tag

For embedding a client -side script, we use script tag in html tag. This <script> tag can be used for containing scripting statements. It can also point another external script file...

2 minutes read.

HTML <table> tag

The Table element If we want to show the data and information in a two-dimensional table with rows and columns, then we can achieve this by using the HTML element <table>. Syntax: <body> <table> <thead> <tr> <thcolspan="#">………….</th> </tr> </thead> <tbody> <tr> <td>……….</td> <td>……….</td> </tr> </tbody> </table> </body> Example: <!DOCTYPE...

9 minutes read.

HTML Form Input Types

HTML Form Input Types An important element of the HTML form is < input type= "> in HTML. The type attribute of the input element can be of different types, which...

8 minutes read.

HTML Unordered List

In HTML, we have <ul> tag which defines the unordered list. And it is also known as bulleted list, because as we know it is not ordered list therefore it...

2 minutes read.

HTML Code Tag

The code tag in HTML is a phrase tag used to insert a piece of computer programming code. In HTML there is a separate tag named as <code> tag. Sometimes,...

3 minutes read.

HTML Button Disabled

The HTML <button> element has many attributes, one of them is the disabled attribute. The button on which you apply the disabled attribute will not work, or we can say...

4 minutes read.

How to create a link with no underline in HTML

In HTML, an anchor tag (<a>) is a Styled Container tag, which means when a hyperlink is created using this, browsers, by default, display the link by applying some styles...

5 minutes read.

HTML Canvas

HTML Canvas: Using JavaScript, the < canvas > tag in HTML is used for drawing graphics on web page. It can be used to draw routes, boxes, text, gradient, and...

3 minutes read.

Html &lt;datalist >Tag

The autocomplete feature in HTML files is provided by the <datalist> tag. It can be used in conjunction with an input tag to enable users to quickly fill out form...

4 minutes read.

HTML Images

HTML has <img> tag to display image on the web pages or web application. This tag is an empty tag i.e. we don't have to close this tag while using. SYNTAX: <img src="source address" attributes="alt, height, width"> Example: <html>   <body>   <center>Image tag Example</center>   <img src="https://www.tutorialandexample.com/resources/images/favicon.png"    alt="tutorialandexample"/>   </body>   </html> Output: Image...

1 minute read.

How to append HTML code to a div using JavaScript?

In HTML, we have a div tag which is used to create a box where we can put a lot of other tags. So it works like a container. So,...

4 minutes read.

HTML Id Attribute

The HTML id attribute represents the unique identifier for an element of the HTML document. Each element has its unique identifier. The id attribute is a global attribute that can be...

12 minutes read.

HTML &lt;body> alink Attribute

HTML <body> alink Attribute What is HTML? The HTML or HyperText Markup Language is used to design web pages. The file extension name for HTML file is ".html". It was released in...

2 minutes read.

HTML Layouts

HTML Layouts HTML templates provide a way for well-managed, well-structured responsive web pages to be organized. We could say that the HTML layout specifies how web pages can be set up....

4 minutes read.

What does HTML stand for?

HTML stands for Hyper Text Markup Language. We use this markup language to design a web page. Web browsers use this language to showcase text, videos, images, audio and other...

6 minutes read.

HTML Nested Table

HTML nested table refers to a table that is created inside another table. The table is in the form of rows and columns. From left to right are called horizontal rows,...

5 minutes read.

Responsive HTML5 and CSS3 Tutorial

Introduction to HTML5 Tutorial HTML5 is the latest and upgraded version of HTML. HTML is a hypertext markup language. Technically, it is not a programming language. It is a markup language. HTML...

17 minutes read.

HTML Hide Element

The HTML hide element is used to hide the element. We place the hidden attribute inside those elements which we want to hide. The hidden attribute is a Boolean attribute. The...

3 minutes read.

HTML Font Size

The HTML <font> tag uses the size attribute to specify the size of the text. We can set the size attribute’s value from 1 to 7. The default size of...

4 minutes read.