HTML <table>
Tag
Example
A simple HTML table, containing two columns and two rows:
<table border="1">
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tr>
<td>January</td>
<td>$100</td>
</tr>
<tr>
<td>February</td>
<td>$80</td>
</tr>
</table>
Browser Support
All major browsers support the <table>
tag.
Tag Definition and Usage
The <table>
tag defines an HTML table.
An HTML table consists of the <table>
element and one or more <tr>
, <th>
, and <td>
elements.
The <tr>
element defines a table row, the <th>
element defines a table header, and the <td>
element defines a table cell.
More complex HTML tables may also include <caption>
, <col>
, <colgroup>
, <thead>
, <tfoot>
, and <tbody>
elements.
Differences Between HTML 4.01 and HTML5
In HTML5, only the "border" attribute is supported, and it only allows the values "1" or "".
Attributes
Attribute | Values | Description |
---|---|---|
align | left <br>center <br>right | Not supported in HTML5. Deprecated in HTML 4.01. Specifies the alignment of the table relative to surrounding elements. |
bgcolor | rgb(x,x,x)<br>#xxxxxx<br>colorname | Not supported in HTML5. Deprecated in HTML 4.01. Specifies the background color of the table. |
border | 1 <br>"" | Not supported in HTML5. Specifies whether the table cells should have borders. |
cellpadding | pixels | Not supported in HTML5. Specifies the space between the cell edge and its content. |
cellspacing | pixels | Not supported in HTML5. Specifies the space between cells. |
frame | void <br>above <br>below <br>hsides <br>lhs <br>rhs <br>vsides <br>box <br>border | Not supported in HTML5. Specifies which parts of the outer borders are visible. |
rules | none <br>groups <br>rows <br>cols <br>all | Not supported in HTML5. Specifies which parts of the inner borders are visible. |
summary | text | Not supported in HTML5. Specifies a summary of the table. |
width | pixels<br>% | Not supported in HTML5. Specifies the width of the table. |
Global Attributes
The <table>
tag supports HTML's global attributes.
Event Attributes
The <table>
tag supports HTML's event attributes.
Try It Yourself - Examples
Table Cells Spanning Multiple Rows/Columns
Related Articles
HTML Tutorial: HTML Tables
HTML DOM Reference: Table Object HTML Table Generator: Online HTML Table Generator