<table> Tag Syntax
<body>
...
... flow content expected ...
<table>
<tr>
<td>...</td>
...
</tr>
</table>
...
</body>
Rules for coding the HTML table element
Make sure you understand the difference between a tag and element and are familiar with the definitions of namespace and other HTML terms.
- Code the table element where flow content is expected.
- Begin the table element with a starting <table> tag. The element name uses lower case letters and should be in the HTML namespace, which it will pick up automatically from the
xmlnsattribute on the <html> tag. - Inside the table element, code the appropriate child elements described below.
- End the table element with a matching
</table>closing tag.
Child Elements of the <table> tag
The HTML specifications require that the child elements be coded in the order shown by this ordered list:
- 1. an optional <caption> tag
- to add a caption above the table
- 2. optional <colgroup> tags and/or <col/> tags
- which define the table columns
- 3. an optional <thead> tag
- for the table header, which is displayed at the top of the table and, when printed, may appear on each page containing any part of the table body
- 4. an optional <tfoot> tag
- The single tfoot element, described below, can be coded either before or after the table body.
- 5. one or more <tr> tags either directly under the table element or inside a tbody element
- for the rows in the body of the table
- 6. an optional <tfoot> tag
- for the table footer, which is displayed at the bottom of the table and, when printed, may appear on each page containing any part of the table body