×

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 Links

It consist of anchor element which is used to create a link between a source anchor and destination anchor. The anchor tag can be embedded between text, image, video or...

2 minutes read.

HTML5 Tags

HTML5 Tags A list of newly included tags is provided in HTML5. These HTML 5 tags (elements) provide a better structure for the document. This list shows description of all HTML...

3 minutes read.

HTML &lt;blink> Tag

In HTML, the blink tag is used to create the text which flashes. The blink tag is an inline element in HTML. It is observed that the blink tag used...

2 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 Anchor

HTML Anchor The HTML anchor tags define a hyperlink that links to other pages on one page. It can create hyperlinks to any web page and files, locations or any other...

3 minutes read.

Design a tribute page using HTML and CSS

A tribute page is a webpage based on a person who inspired us in our life. In this article, we will create a webpage of Mahatma Gandhi. We are going...

5 minutes read.

HTML <video> Tag

The Video tag in HTML is used to play video on a media player on the web page. We can also insert an audio by the video tag, but audio...

6 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 References

BASIC HTML TAGS TAGS DESCRIPTION <!DOCTYPE> Defines Document Type <html> Defines Html document <head> Defines Header of document <title> Defines Title of document <body> Describe all the content of document <h1> to <h6> Defines Html Heading <p> Write Paragraph in this tag <br> Line break <!--...--> Comment in Html FORMATTING TAGS TAGS DESCRIPTION <abbr> Defines...

3 minutes read.

HTML Charsets

In this tutorial, we are going to discuss about the charsets in the HTML. The letters, numbers, and several other symbols are shown correctly by the web browser. All of this...

2 minutes read.

Html &lt;Col> Tag

You can write the col tag inside the table tag after the thead, tbody, foot, and tr tags. You can also apply it after the caption tag (in which the...

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

Font tag in HTML

HTML stands for Hypertext Mark-up Language and is used to create web pages and other information that can be later displayed in a web browser. It also consists of a...

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

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 Font Color

The HTML <font> tag has an attribute called color, which defines the color of the text. We use the color attribute inside the <font> tag to specify the color of...

6 minutes read.

HTML <span> tag

The span tag in HTML is used as an inline container element to mark up a specific or special chunk of a text or a section of a page. If you...

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

How to insert image in HTML

An image (technically digital image) in HTML or even in general technical aspects is a binary representation of visual information. By visual information we mean, in the form of drawings/pictures,...

5 minutes read.