×

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

How to change text color in HTML

Changing the text colour of a web page is essential because it enhances readability. There are several ways to change the colour of the text in HTML, which are as follows: Text...

7 minutes read.

HTML Basic Tags

Heading Tags: This tag represents the document header. It is said to be a good practice if every document starts with Heading. Heading tags ranges from H1 to H6 i.e....

3 minutes read.

HTML Data Tag

HTML Data Tag: The HTML < data > tag is used to transmit its content to a machine-readable version. The data are presented in a particular format. It is useful...

3 minutes read.

HTML Search Box

The HTML search box is also known as the search bar. It is an input text field that is used to search the content. If the users want to explore...

7 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 <section> tag

The section element in HTML is used to define sections in a document. Syntax of Section Tag: <body> <h1>……….</h1> <section> <h2>……….</h2> <p> …………………………</p> </section> <section> <h2>………..</h2> <p>…………………………. <p> </section> </body> Examples of Section Tag Example 1: In this example, we use the HTML "section" element...

3 minutes read.

HTML <select> tag

This tag helps in making the drop-down list on the web page. This is highly used in HTML forms for taking the input from user. You can use the id attribute...

3 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 Headings

The titles and subtitles of our webpages are known as HTML headings. Let’s not talk about webpages but giving heading to almost everything like normal paragraphs, articles or let it...

2 minutes read.

HTML <samp> tag

The Samp tag in HTML is used for defining the sample output from the computer program. This tag is a phrase type tag and a container tag that means the...

2 minutes read.

HTML <br> tag

HTML is referred to as Hyper Text Markup Language, which is the most popular language for creating Web pages. HTML explains the construction of a Web page. It contains a...

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 City tag

HTML <City> tag HTML < cite > tag specifies a citation, a reference or title to a creative work, quoted content, books, websites, a research paper, a blog post, a painting,...

3 minutes read.

HTML <source> tag

For media attributes, such as <video> tag, <audio> tag, and <picture> tag, we use the <source> tag in html for adding such type of multiple media html elements in our...

4 minutes read.

HTML Forms

Forms are required when we want to collect data from the user. Html forms consists of different fields to take user inputs such as: input, text area, checkbox, password, radio...

4 minutes read.

Html &lt;center> Tag

The term HTML refers to Hyper Text Markup Language. The most widely used markup language for making web pages is HTML. A structure of web page is described in HTML....

3 minutes read.

HTML Reset Button

The HTML reset button is used to reset all values in the form. It clears all input fields. Reset is the value of the type attribute of the button element. The...

6 minutes read.

Html <colgroup> Tag

A HTML table's column group is specified by the "colgroup" tag. If you want to apply various properties to one or more <col> elements in an HTML table, then you...

4 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.

How to add JavaScript to HTML

JavaScript is one of the most important languages today. It is a high-level, interpreted, lightweight programming language that makes web pages more interactive. It is a language of the web....

5 minutes read.