Defines a container for two-dimensional data. | HTML 3.2, 4, 4.01, 5 |
HTML Syntax
<table align=alignment cellpadding=number cellspacing=number width=length>
... table definition elements ...
</table>
NOTE: Both start and end tags are required.
The <table
> element specifies a container for arranging content into rows and columns of cells.
<table
> elements are always used with the <tr> element to define the table rows, and the <th> or <td> elements to define the table cells.
<th
> elements define row or column headings, and <td
> elements define the cells for the table data.
A table can also contain a <caption> element, which provides a label of the table’s purpose.
A table can have a specified width, and browsers render the table to fit the specified dimensions when possible.
In cases where the specified sizes will not fit, as when the table may have cells that contain long non-wrapping lines, the browser adjusts the table size accordingly.
The cols attribute can be used to specify the number of equal-width columns in the table. Specifying this attribute can speed up the processing of a table.
To control spacing between and within cells, authors can use cellspacing to specify the distance between cells, and cellpadding to specify the distance between the border and content of each cell.
NOTE: The align, cellpadding, cellspacing and width attributes have been deprecated in HTML5 in favor of CSS style sheets.
The <table>
element supports the following attributes, in addition to global attributes common to all HTML elements.
align | left, center, right | Deprecated. Specifies the alignment of the table with respect to the document. |
bgcolor | color | Obsolete. Sets the background color of the table. |
border | 0, 1 | Deprecated. Specifies whether the table cells should have borders or not. |
cellpadding | length | Deprecated. Specifies the space between the edge of a cell and its content. |
cellspacing | length | Deprecated. Specifies the amount of space between individual cells. |
frame | above, below, border, box, hsides, lhs, rhs, void, vsides | Obsolete. Specifies which sides of the border frame surrounding a table will be visible. |
rules | all, cols, groups, none, rows | Obsolete. Specifies which parts of the inside borders will appear between cells within a table. |
sortable | sortable | Obsolete. Enables a sorting interface for the table. |
summary | text | Obsolete. Specifies a summary of the content of a table. |
width | length | Deprecated. Specifies the width of the entire table. |
The following example shows how the <table
> element may be used.
<table table align="center" border>
<thead>
<tr>
<th>Heading 1</th>
<th>Heading 2</th>
</tr>
<tbody>
<tr>
<td>Row 1, Column 1 text.</td>
<td>Row 1, Column 2 text.</td>
</tr>
<tr>
<td>Row 2, Column 1 text.</td>
<td>Row 2, Column 2 text.</td>
</tr>
</table>
which would render on a Web page as follows:
Heading 1 | Heading 2 |
Row 1, Column 1 text. | Row 1, Column 2 text. |
Row 2, Column 1 text. | Row 2, Column 2 text. |
TBODY TD TFOOT THEAD TH TR Using Tables