table

FilterElements

<table> ... </table>

Indicates a table used for displaying rows and columns of data or information. The minimum elements for defining a table are table for establishing the table itself, tr for declaring a table row, and td for creating table cells within the row. The complete table model is shown below.

Start/End Tags

Required/Required

Specifications

  • HTML 4.01
  • HTML5

align=

Values: left | right | center
Deprecated. Not in HTML5. Aligns the table within the text flow (same as align in the img element). The default alignment is left. The center value is not universally supported.

bgcolor=

Values: #rrggbb or color name
Deprecated. Not in HTML5. Specifies a background color for the entire table. The color is specified in hexadecimal RGB values or by color name. Style sheets are the proper way to specify colors.

border=

Values: number
Not in HTML5. Specifies the width (in pixels) of the border around the table and its cells. Setting its value to 0 (zero) turns the borders off completely. The default value is 1. Adding the word border without a value results in a 1-pixel border, although this is not valid in XHTML.

cellpadding=

Values: number
Not in HTML5. Sets the amount of space, in number of pixels, between the cell border and its contents. The default value is 1.

cellspacing=

Values: number
Not in HTML5. Sets the amount of space (in number of pixels) between table cells. The default value is 2.

frame=

Values: void | above | below | hsides | lhs | rhs | vsides | box | border
Not in HTML5. Tells the browser where to draw borders around the table. The values are:
void
The frame does not appear (default).
above
Top side only.
below
Bottom side only.
hsides
Top and bottom sides only.
vsides
Left and right sides only.
lhs
Left side only.
rhs
Right side only.
box
All four sides.
border
All four sides.

rules=

Values: all | cols | groups | none | rows
Not in HTML5. Tells the browser where to draw rules within the table. When the border attribute is set to a value greater than zero, rules defaults to all unless otherwise specified. This attribute is not universally supported. Its values are:
all
Rules appear between all rows and columns.
cols
Rules appear between columns only.
groups
Rules appear between row groups (thead, tfoot, and tbody ) and column groups.
none
No rules (default).
rows
Rules appear between rows only.

summary=

Values: text
Provides a summary of the table contents for use with nonvisual browsers. In HTML5, authors are urged to use the caption element instead.

width=

Values: number or percentage
Not in HTML5. Specifies the width of the entire table. It can be specified by number of pixels or by percentage of the parent element.

A simple table with two rows and two columns.

<table>
<tr>
  <td>cell 1</td><td>cell 2</td>
</tr>
<tr>
  <td>cell 3</td><td>cell 4</td>
</tr>
</table>

Rendered Example

     
cell 1cell 2
cell 3cell 4

The proper element order in the full table model (shown in HTML syntax). For details, see the caption, tbody, thead, tfoot, colgroup, and col element entries.

<table>
<caption>Employee salaries and start dates</caption>

<colgroup id="employeeinfo">
<col span="2" width="300">
<col span="1" width="100" class="date">
</colgroup>

<thead>
<tr>
<th>Employee</th><th>Salary</th><th>Start date</th>
</tr>
</thead>

<tfoot>
<tr><td colspan="3">Compiled by Betty D. Boss</td></tr>
</tfoot>

<tbody>
<tr>
<td>Wilma</td><td>50,000</td><td>April 6</td>
</tr>
<tr>...more data cells...</tr>
<tr>...more data cells...</tr>
</tbody>

</table>

Rendered Example

Employee salaries and start dates
EmployeeSalaryStart date
Compiled by Betty D. Boss
Wilma50,000April 6
Betty45,000May 8