asp.net.ph

Skip Navigation LinksHome > Abakada: Back to Basics > Language References > HTML Elements > TABLE Element

<table> Element


Defines a container for two-dimensional data.HTML 3.2, 4, 4.01, 5

HTML Syntax

NOTE: Both start and end tags are required.

Remarks

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.

Attributes

The <table> element supports the following attributes, in addition to global attributes common to all HTML elements.

AttributeValueDescription
alignleft, center, rightDeprecated. Specifies the alignment of the table with respect to the document.
bgcolorcolorObsolete. Sets the background color of the table.
border0, 1Deprecated. Specifies whether the table cells should have borders or not.
cellpaddinglengthDeprecated. Specifies the space between the edge of a cell and its content.
cellspacinglengthDeprecated. Specifies the amount of space between individual cells.
frameabove, below, border, box, hsides, lhs, rhs, void, vsidesObsolete. Specifies which sides of the border frame surrounding a table will be visible.
rulesall, cols, groups, none, rowsObsolete. Specifies which parts of the inside borders will appear between cells within a table.
sortablesortableObsolete. Enables a sorting interface for the table.
summarytextObsolete. Specifies a summary of the content of a table.
widthlengthDeprecated. Specifies the width of the entire table.

Example

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 1Heading 2
Row 1, Column 1 text.Row 1, Column 2 text.
Row 2, Column 1 text.Row 2, Column 2 text.

External References

See Also

TBODY   TD   TFOOT   THEAD   TH   TR   Using Tables


Need a break ?
Suggested Reading

Check out related books at Amazon

© 2025 Reynald Nuñez and asp.net.ph.

If you have any question, comment or suggestion,
please send us a note