Menu
Coddy logo textTech

Adding Captions

Part of the Fundamentals section of Coddy's HTML journey — lesson 49 of 60.

In HTML tables, a caption is a title or explanation for the table. It provides a brief description of the table's content, making it easier for users to understand the purpose of the table. Captions are created using the <caption> tag, which should be placed immediately after the <table> tag.

Here's the basic syntax for adding a caption to a table in HTML:

<table>
	<caption>Table Caption</caption>
	<tr>
		<th>Header 1</th>
		<th>Header 2</th>
	</tr>
	<tr>
		<td>Row 1, Cell 1</td>
		<td>Row 1, Cell 2</td>
	</tr>
</table>
challenge icon

Challenge

Easy

Create an HTML document that includes a table with a caption. The table should have the following structure:

  1. A <table> tag to define the table.
  2. A <caption> tag with the text "Product Inventory" to describe the table.
  3. A table row (<tr>) for the header with two header cells (<th>). The header cells should say "Product Name" and "Quantity".
  4. A table row (<tr>) with two data cells (<td>). The cells should say "Laptop" and "5".
  5. Another table row (<tr>) with two data cells (<td>). The cells should say "Mouse" and "10".

Cheat sheet

The <caption> tag provides a title or explanation for an HTML table. It should be placed immediately after the <table> tag.

<table>
	<caption>Table Caption</caption>
	<tr>
		<th>Header 1</th>
		<th>Header 2</th>
	</tr>
	<tr>
		<td>Row 1, Cell 1</td>
		<td>Row 1, Cell 2</td>
	</tr>
</table>

Try it yourself

<!DOCTYPE html>
<html>
    <body>
        <!-- Write code here -->
    </body>
</html>
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals