XHTML » Tags » caption

Syntax:
<caption> ... </caption>

The caption tag allows you to place a comment (caption) with a table. The caption does not appear inside the table, but rather it appears outside the table on either the top (default) or bottom. By default, the caption will be centered on the table.

The caption tag must occur immediately after the table tag. You can only have one caption per table. The text that composes the caption can contain HTML tags and style sheet properties.

Note that the table tag has the summary attribute which is used with non-visual media such as braille and speech to provide information about a table.
 
The separate closing tag is mandatory.

Examples

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>DevGuru XHTML caption Tag Example</title>
</head>
<body>

<table width="80%" border="10" cellpadding="3" cellspacing="5" align="center">
<caption>
<b>How To Code A Table</b>
<br />
Use the caption tag to name the table and to provide useful information about the contents
</caption>
<tr>
<th colspan'"2">Use the <b>th</b> tag to create the header which will display in bold</th>
</tr>
<tr>
<td style="width:50%">The <b>tr</b> tag creates the row</td>
<td style="width:50%">The <b>td</b> tag creates individual cells for each row</td>
</tr>
<tr>
<td style="width:50%">You should always use the closing tags</td>
<td style="width:50%">You can use a variety of XHTML tags inside the cell</td>
</tr>
<tr>
<td style="width:50%">The three new table tags are <b>tbody, tfoot,</b> and <b>thead</b></td>
<td style="width:50%">The <b>colspan</b> attribute allows you span more than one cell</td>
</tr>
</table>

</body>
</html>
Output:
How To Code A Table
Use the caption tag to name the table and to provide useful information about the contents
Use the th tag to create the header which will display in bold
The tr tag creates the rowThe td tag creates individual cells for each row
You should always use the closing tagsYou can use a variety of XHTML tags inside the cell
The three new table tags are tbody, tfoot, and theadSetting colspan allows you span more than one cell
Explanation:

This example demonstrates the basic table tags.

Language(s): XHTML

Events

onclick

Syntax: onclick="action"

The onclick event is associated with the single click of a mouse on a selected HTML tag (element). Whenever you single click the element, the script code of the onclick is executed. This script can also call functions or subroutines which contain code that you want to run when the single click occurs.

ondblclick

Syntax: ondblclick="action"

The ondblclick event is associated with the double click of a mouse on a selected HTML element. Whenever you double click the element, the script code of the ondblclick is executed. This script can also call functions or subroutines which contain code that you want to run when the double click occurs.

onkeydown

Syntax: onkeydown="action"

The onkeydown event is associated with pressing down a key on the keyboard while the mouse is inside a selected HTML tag (element). In other words, the key down event occurred while the HTML element was in focus. Whenever you press down the key, the script code of the onkeydown is executed.

onkeypress

Syntax: onkeypress="action"

The onkeypress event is associated with press of a key on the keyboard while the mouse is inside a selected HTML element. In other words, the key press event occurred while the HTML element was in focus. Whenever you press the key, the script code of the onkeypress is executed.

onkeyup

Syntax: onkeyup="action"

The onkeyup event is associated with releasing up a key on the keyboard while the mouse is inside a selected HTML tag (element). In other words, the key up event occurred while the HTML element was in focus. Whenever you release the key, the script code of the onkeyup is executed.

onmousedown

Syntax: onmousedown="action"

The onmousedown event is associated with clicking down the mouse button while the mouse is inside a selected HTML tag (element). In other words, the mouse down event occurred while the HTML element was in focus. Every time you click down the mouse, while inside the element, the script code of the onmousedown is executed. This script can also call functions or subroutines which contain code that you want to run when this event occurs.

onmousemove

Syntax: onmousemove="action"

The onmousemove event is associated with moving the mouse around while inside a selected HTML tag (element). In other words, the mouse move event occurred while the HTML element was in focus. Every time you move the mouse around the element, the script code of the onmousemove is executed. This script can also call functions or subroutines that contain code that you want to run when this event occurs.

onmouseout

Syntax: onmouseout="action"

The onmouseout event is associated with moving the mouse out of a selected HTML tag (element). In other words, the mouse out event occurred while the HTML element was in focus. Every time you move the mouse out of the element, the script code of the onmouseout is executed. This script can also call functions or subroutines which contain code that you want to run when this event occurs.

onmouseover

Syntax: onmouseover="action"

The onmouseover event is associated with moving the mouse over a selected HTML tag (element). In other words, the mouse over event occurred while the HTML element was in focus. Every time you move the mouse over the element, the script code of the onmouseover is executed. This script can also call functions or subroutines which contain code that you want to run when this event occurs.

onmouseup

Syntax: onmouseup="action"

The onmouseup event is associated with the releasing up portion of a click of the mouse while inside a selected HTML tag (element). In other words, the mouse up event occurred while the HTML element was in focus. Every time you release the mouse up, while in the element, the script code of the onmouseup is executed. This script can also call functions or subroutines which contain code that you want to run when this event occurs.

See Also: