Tables

Contents:

Summary of Table Tags
Introduction to Tables
Basic Table Structure
Affecting Table Appearance
Table Troubleshooting
Tips and Tricks
Standard Table Templates
Multipart Images in Tables

HTML tags for creating tables were originally developed for presenting rows and columns of tabular data, but designers quickly co-opted them as a valuable tool for controlling the layout of web pages. Tables allow you to create columns of text, hold white space between elements, and restrict the dimensions of the page's content in ways other HTML formatting tags can't.

The HTML 4.01 specification on tables is a great deal more complex than the previous 3.2 standard. It makes an effort to bring context and structure to table data as well as to provide systems for incremental display during download and display on nonvisual display agents (such as speech- and Braille-based browsers). To read what the HTML 4.01 specification has to say about tables, see the W3C's site at http://www.w3c.org/TR/html4/struct/tables.html.

Summary of Table Tags

In this section, browser support for each tag is noted to the right of the tag name. Browsers that do not support the tag are grayed out. Tag usage is indicated below the tag name. Start and end tags are required unless otherwise noted. "Deprecated" means that the tag or attribute is currently supported but is due to be phased out of the HTML specification and is discouraged from use (usually in favor of similar style sheet controls). The attributes listed for each tag reflect those in common use. A more thorough listing of attributes for each tag, according to the HTML 4.01 specification, appears in Appendix A, "HTML Elements".

<caption> NN 2, 3, 4, 6 MSIE 2, 3, 4, 5, 5.5, 6 HTML 4.01 WebTV Opera5

<caption>...</caption>

Provides a brief summary of the table's contents or purpose. The caption must immediately follow the <table> tag and precede all other tags. The width of the caption is determined by the width of the table. The caption's position as displayed in the browser can be controlled with the align attribute (or valign in MSIE).

Attributes

<col> NN 6 MSIE 3, 4, 5, 5.5, 6 HTML 4.01

<col> (no end tag)

Specifies properties for a column (or group of columns) within a column group (<colgroup>). Columns can share attributes (such as text alignment) without being part of a formal structural grouping.

Column groups and columns were introduced by Internet Explorer 3.0 and are now proposed by the HTML 4.01 specification as a standard way to label table structure. They may also be useful in speeding table display (i.e., the columns can be displayed incrementally without waiting for the entire contents of the table).

Attributes

<colgroup> NN 6 MSIE 3, 4, 5, 5.5, 6 HTML 4.01

<colgroup>...</colgroup> (end tag optional)

Creates a column group, a structural division within a table that can be appointed attributes with style sheets or HTML. A table may include more than one column group. The number of columns in a group is specified either by the value of the span attribute or by a tally of columns <col> within the group. Its end tag is optional.

Column groups and columns were introduced by Internet Explorer 3.0 and are now proposed by the HTML 4.0 specification as a standard way to label table structure. They may also be useful in speeding the table display (i.e., the columns can be displayed incrementally without waiting for the entire contents of the table).

Attributes

<table> NN 2, 3, 4, 6 MSIE 2, 3, 4, 5, 5.5, 6 HTML 4.01 WebTV Opera5

<table>...</table>

Defines the beginning and end of a table. The end tag is required, and its omission may cause the table not to render in some browsers.

Attributes

Internet Explorer only

<tbody> NN 6 MSIE 3, 4, 5, 5.5, 6 HTML 4.01

<tbody>...</tbody> (start and end tags optional)

Defines a row or group of rows as the "body" of the table. It must contain at least one row (<tr>).

"Row group" tags (tbody, thead , and tfoot) were introduced by Internet Explorer and are part of the HTML 4.01 specification. The attributes for <tbody> are currently not supported by any commercial browser. Row groups could speed table display and provide a mechanism for scrolling the body of a table independently of its head and foot. It could also be useful for printing long tables for which the head information could be printed on each page.

Attributes

<td> NN 2, 3, 4, 6 MSIE 2, 3, 4, 5, 5.5, 6 HTML 4.01 WebTV Opera5

<td>...</td> (end tag optional)

Defines a table data cell. The end tag is not required but may prevent unpredictable table display, particularly if the cell contains images. A table cell can contain any content, including another table.

Attributes

Internet Explorer only

New in HTML 4.01

These attributes are part of the HTML standard but are not supported by current browsers.

<tfoot> NN 6 MSIE 3, 4, 5, 5.5, 6 HTML 4.01

<tfoot>...</tfoot> (end tag optional)

Defines the foot of a table and should contain information about a table's columns. It is one of the "row group" tags introduced by Internet Explorer and proposed in the HTML 4.01 specification. A <tfoot> must contain at least one row (<tr>).

See <tbody> for more information and a list of supported attributes.

<th> NN 2, 3, 4, 6 MSIE 2, 3, 4, 5, 5.5, 6 HTML 4.01 WebTV Opera5

<th>...</th> (end tag optional)

Defines a table header cell. Table header cells function the same as table data cells (<td>). Browsers generally display the content of table header cells in bold text centered horizontally and vertically in the cell (although some browsers vary). The end tag is optional.

Attributes

The <th> tag uses the same attributes as the <td> tag. See listing under <td>.

<thead> NN 6 MSIE 3, 4, 5, 5.5, 6 HTML 4.01

<thead>...</thead> (end tag optional)

Defines the head of the table and should contain information about a table. It must contain at least one row (<tr>). <thead> is one of the "row group" tags introduced by Internet Explorer and proposed in the HTML 4.01 specification.

See <tbody> for more information and a list of supported attributes.

<tr> NN 2, 3, 4, 6 MSIE 2, 3, 4, 5, 5.5, 6 HTML 4.01 WebTV Opera5

<tr>...</tr> (end tag optional)

Defines a row of cells within a table. A table row as delimited by <tr> tags contains no content other than a collection of table cells (<td>). Settings made in the <tr> tag apply to all the cells in that row, but individual cell settings override those made at the row level.

Attributes

Internet Explorer only