Example
A simple HTML table, containing two columns and two rows:
<table>
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tr>
<td>January</td>
<td>$100</td>
</tr>
</table>
More “Try it Yourself” examples below.
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.
A more complex HTML table may also include <caption>, <col>, <colgroup>, <thead>, <tfoot>, and <tbody> elements.
Note: Tables should not be used for page layout! Historically, some Web authors have misused tables in HTML as a way to control their page layout. However, there are a variety of alternatives to using HTML tables for layout, primarily using CSS.
Browser Support
| Element | |||||
|---|---|---|---|---|---|
| <table> | Yes | Yes | Yes | Yes | Yes |
Differences Between HTML 4.01 and HTML5
The “align”, “bgcolor”, “border”, “cellpadding”, “cellspacing”, “frame”, “rules”, “summary”, and “width” attributes are not supported in HTML5.
Attributes
| Attribute | Value | Description | HTML Code |
|---|---|---|---|
| align | left center right |
Not supported in HTML5. Specifies the alignment of a table according to surrounding text |
<table align=”right”> |
| bgcolor | rgb(x,x,x) #xxxxxx colorname |
Not supported in HTML5. Specifies the background color for a table |
<table bgcolor=”#00FF00″> |
| border | 1 0 |
Not supported in HTML5. Specifies whether or not the table is being used for layout purposes |
<table border=”1″> |
| cellpadding | pixels | Not supported in HTML5. Specifies the space between the cell wall and the cell content |
<table cellpadding=”10″> |
| cellspacing | pixels | Not supported in HTML5. Specifies the space between cells |
<table cellspacing=”10″> |
| frame | void above below hsides lhs rhs vsides box border |
Not supported in HTML5. Specifies which parts of the outside borders that should be visible |
<table frame=”box”> |
| rules | none groups rows cols all |
Not supported in HTML5. Specifies which parts of the inside borders that should be visible |
<table rules=”rows”> |
| summary | text | Not supported in HTML5. Specifies a summary of the content of a table |
<table summary=”Monthly savings for the Flintstones family”> |
| width | pixels % |
Not supported in HTML5. Specifies the width of a table |
<table width=”400″> |
Global Attributes
The <main> tag also supports the Global Attributes in HTML.
Event Attributes
The <main> tag also supports the Event Attributes in HTML.
Related Page
HTML DOM reference: Table Object
