HTML TUTORIAL PART 9: EXPLANATION OF TABLES AND STYLES TAG
TABLES TAG
<table> </table>, <tr> </tr>, <th> </th> and <td> </td>
The HTML table tag inserts a table in the document. This tag is the container for all the parts of tables: captions (HTML caption tag), headers (HTML thead tag), header's cells (HTML th tag), footers (HTML tfoot tag), body (HTML tbody tag), rows (HTML tr tag), column attributes (HTML col tag), column groups (HTML colgroup tag), cells (HTML td tag).
USAGE EXAMPLE: - Code:
-
<table border="1">
<tr>
<th>Employee ID</th>
<th>Name</th>
</tr>
<tr>
<td>0001</td>
<td>Arvind</td>
</tr>
<td>0002</td>
<td>Mahesh</td>
</tr>
<td>0003</td>
<td>Shankar</td>
</tr>
</table>
The HTML th tag defines a table's cell (HTML table tag) containing header information for other regular cells (HTML td tag).
The HTML tr tag defines rows in a table (HTML table tag). These rows act as containers for cells (HTML td tag and HTML th tag).
The HTML td tag defines a regular cell in a table (HTML table tag).
<caption> </caption>
The HTML caption tag gives a title for the table where it's declared. It must be defined right after the starting HTML table tag and should declare the nature of the table.
USAGE EXAMPLE: - Code:
-
<table border="1">
<caption>EMPLOYEE INFORMATION</caption>
<tr>
<th>Employee ID</th>
<th>Name</th>
</tr>
<tr>
<td>0001</td>
<td>Arvind</td>
</tr>
<td>0002</td>
<td>Mahesh</td>
</tr>
<td>0003</td>
<td>Shankar</td>
</tr>
</table>
<thead> </thead>, <tbody> </tbody> and <tfoot> </tfoot>
The HTML thead tag defines the header of a table (HTML table tag). Headers, as well as footers (HTML tfoot tag), are used to define "titles" or captions for the columns of a table. They are very helpful when the table is shown in more than one page (e.g., when a table is printed). In those cases the headers and footers may appear in each page.
The HTML tbody tag defines a block that will represent a body in a table (HTML table tag). Tables may have multiple bodies, but when it only has one single body, the HTML tbody tag may be safely omitted. When this happens every row that doesn't belong to the headers (HTML thead tag) or the footers (HTML tfoot tag), belongs to the implicit HTML tbody tag.
The HTML tfoot tag defines a footer in a table (HTML table tag). Footers, as well as headers (HTML thead tag), are used to define "titles" or captions for the columns of a table. They are very helpful when the table is shown in more than one page (e.g., when a table is printed). In those cases the headers and footers may appear in each page. Note that authors should place the HTML tfoot tag before any HTML tbody tag. This will allow browser to render footers even when the body (or bodies) of a table hasn't been received yet (in some cases a large amount of information).
USAGE EXAMPLE: - Code:
-
<table border="1">
<thead>
<tr>
<th>Employee ID</th>
<th>Name</th>
</tr>
</thead>
<tbody>
<tr>
<td>0001</td>
<td>Arvind</td>
</tr>
<tr>
<td>0002</td>
<td>Mahesh</td>
</tr>
</tbody>
<tfoot>
<tr>
<td>0003</td>
<td>Shankar</td>
</tr>
</tfoot>
</table>
<col> </col>
The HTML col tag is used in tables to set default attributes for all the cells in a column or a group of columns. The HTML col tag is defined in an ordered way and can be part of a HTML colgroup tag or not. To define a set of attributes for multiple consecutive columns use the "span" attribute.
USAGE EXAMPLE: - Code:
-
<table width="100%" border="1">
<col align="left"></col>
<col align="left"></col>
<col align="right"></col>
<tr>
<th>EMPLOYEE ID</th>
<th>NAME</th>
<th>PAY SCALE</th>
</tr>
<tr>
<td>0001</td>
<td>Arvind</td>
<td>$20,000</td>
</tr>
<tr>
<td>0002</td>
<td>Mahesh</td>
<td>$15,000</td>
</tr>
<tr>
<td>0003</td>
<td>Shankar</td>
<td>$17,000</td>
</tr>
</table>
<colgroup> </colgroup>
The HTML colgroup tag is used in tables to group columns. This allow author to group columns, define default attributes for them as well as to set a visual format for the table (with "rules" attribute for the HTML table tag).
USAGE EXAMPLE: - Code:
-
<table width="100%" border="1">
<colgroup span="2" align="left"></colgroup>
<colgroup align="right" style="color:#0000FF;"></colgroup>
<tr>
<th>EMPLOYEE ID</th>
<th>NAME</th>
<th>PAY SCALE</th>
</tr>
<tr>
<td>0001</td>
<td>Arvind</td>
<td>$20,000</td>
</tr>
<tr>
<td>0002</td>
<td>Mahesh</td>
<td>$15,000</td>
</tr>
<tr>
<td>0003</td>
<td>Shankar</td>
<td>$17,000</td>
</tr>
-Arvind