HTML table tag
Note: If you don't know what a tag is and/or how you must use it we recommend you to read our HTML tags and attributes tutorial that you can find in our HTML tutorials section.
Description
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).
Attributes
The "id" attribute assigns an identifier to the associated element. This identifier must be unique in the document and can be used to refer to that element.
Example:
Code begin
<p id="paragraph1">This is the first paragraph named as paragraph1. To dynamically change its properties use this identifier.</p>Code end
The "class" attribute assigns a class name (or a list of class names separated by spaces) to the container element. It's used with style sheets and tells the browser the class to which the element is associated with. A class gives visual attributes to elements.
Example:
Code begin
<p class="references">This article is based on the book "Wind in the trees" by Jhon L. Brooks</p>
<p class="references important">This article is based on the book "Wind in the trees" by Jhon L. Brooks... and is more important than the one before.</p>Code end
Defines a visual style of this element. Is a better practice to define styles attributes in external style sheets grouping them in classes. Attributes in the "style" parameter must preserve this order "name : value" and be separated by a semi-colon.
If you're writing
XHTML code it's recommended not to use this attribute and try style sheet classes (with the "class" attribute).
Example:
Code begin
<p style="color: #0000FF; font-size: 12pt">This is a paragraph with a defined style</p>
<p>And this is another text without style.</p>Code end
Indicates a title for the element. Used to give a short description about the element that is usually shown as a "tool tip" when the user put the mouse pointer over the element.
Example:
Code |
View |
<a title="HTMLQuick.com" href="http://www.htmlquick.com">HTML code</a> |
HTML code |
Specifies the language of an element's content. The default value in "unknown".
When writing
XHTML code the syntax "xml:lang" represents a preferred alternative in XHTML 1.0 and a replacement in XHTML 1.1 (e.g., xml:lang="en").
Example:
Code begin
<p lang="en">This is a paragraph in english.</p>
<p lang="es">Este es un párrafo en español.</p>Code end
dir
Specifies the text direction of the element's contents and attribute values, as well as tables directionality. It has two possible values that are case insensitive:
- RTL: Right to left.
- LTR: Left to right.
Example:
Code begin
<q lang="he" dir="rtl">...a Hebrew quotation...</q>Code end
summary (text)
Provides a summary of the table purpose and structure.
align
Sets the alignment of the table. Possible values are (case-insensitive):
- left: The table is aligned to the left of the available space.
- center: The table is aligned to the center of the available space.
- right: The table is aligned to the right of the available space.
Specifies the desired width of the entire table.
frames
Specifies which sides of the frame surrounding the table will be visible. Possible values are (case-insensitive):
- void: No sides. This is the default value.
- above: The top side only.
- below: The bottom side only.
- hsides: The top and bottom sides only.
- vsides: The right and left sides only.
- lhs: The left-hand side only.
- rhs: The right-hand side only.
- box: All four sides.
- border: All four sides.
rules
Decides which rules will appear between cells within a table. Possible values (case-insensitive):
Specifies the width in pixels of the border of the frame around a table.
Example:
Code |
View |
<table border="5" summary="Example table showing the use of the border attribute."> <tr> <td>Cell 1</td> <td>Cell 2</td> <td>Cell 3</td> </tr> <tr> <td>Cell 4</td> <td>Cell 5</td> <td>Cell 6</td> </tr> </table> |
Cell 1 |
Cell 2 |
Cell 3 |
Cell 4 |
Cell 5 |
Cell 6 |
|
cellspacing (length)
Defines the space to be left between cells and between the table border and the cell border that's closer to it.
Example:
Code |
View |
<table cellspacing="10" border="1" summary="Example table showing the use of the cellspacing attribute."> <tr> <td>...Content...</td> <td>...Content...</td> </tr> </table> |
...Content... |
...Content... |
|
cellpadding (length)
Defines the space to be left between the border of a cell and it's content. It works as cells' margins.
Example:
Code |
View |
<table cellpadding="10" border="1" summary="Example table showing the use of the cellpadding attribute."> <tr> <td>...Content...</td> <td>...Content...</td> </tr> </table> |
...Content... |
...Content... |
|
Events
- onclick
- ondblclick
- onmousedown
- onmouseup
- onmouseover
- onmousemove
- onmouseout
- onkeypress
- onkeydown
- onkeyup
See complete list and information about
events in HTML
Examples
In this example we define a table with grouped columns, grouped rows and many attributes for each tag that will define a visual style.
Code |
View |
<table border="1" frame="border" rules="groups" summary="Functionality of HTML files in different versions of Internet Explorer"> <caption>Representation of how HTML files works in different versions of Internet Explorer</caption> <colgroup align="center"></colgroup> <colgroup></colgroup> <colgroup align="center" span="2"></colgroup> <thead> <tr> <th>File</th> <th>Name</th> <th>4.0</th> <th>5.0</th> </tr> </thead> <tfoot> <tr> <th>File</th> <th>Name</th> <th>4.0</th> <th>5.0</th> </tr> </tfoot> <tbody> <tr> <td>1</td> <td>index.html</td> <td>Ok</td> <td>Ok</td> </tr> <tr> <td>2</td> <td>links.html</td> <td>Ok</td> <td>Ok</td> </tr> <tr> <td>3</td> <td>fullfunc.html</td> <td>-</td> <td>Ok</td> </tr> <tr> <td>4</td> <td>nofunc.html</td> <td>Ok</td> <td>Ok</td> </tr> <tr> <td>5</td> <td>panel.html</td> <td>-</td> <td>Ok</td> </tr> </tbody> <tbody> <tr> <td>6</td> <td>search.php</td> <td>Ok</td> <td>Ok</td> </tr> <tr> <td>7</td> <td>send.php</td> <td>Ok</td> <td>Ok</td> </tr> </tbody> </table> |
Representation of how HTML files works in different versions of Internet Explorer
File |
Name |
4.0 |
5.0 |
File |
Name |
4.0 |
5.0 |
1 |
index.html |
Ok |
Ok |
2 |
links.html |
Ok |
Ok |
3 |
fullfunc.html |
- |
Ok |
4 |
nofunc.html |
Ok |
Ok |
5 |
panel.html |
- |
Ok |
6 |
search.php |
Ok |
Ok |
7 |
send.php |
Ok |
Ok |
|