Tag Description:


<TABLE> Tables

Definition: The HTML table model is high in flexibility and simplicity. It is automatically sized by default according to the current window size and the cell contents. If you want to exert control over column widths, you can use the COLSPEC to specify relative widths or set explicit widths. It is also possible to specify the table width as a fraction of the current margins or explicitly.

HTML tables begin with an optional caption which is followed by one or more rows. One or more cells form each row, and the cells are differentiated into datacells and header cells. It is possible to merge cells across columns and rows, as well to include attributes that facilitate the rendering to speech and Braille. Since issues of appearance (such as border styles and margins) can be handled with associated style sheets and subclassing, the model gives little direct support for control over appearance.

Lists, paragraphs, headers, forms, preformatted text, nested tables, and figures are examples of the content that tables can contain. Subsequent elements will be flowed around a table that is flush left or right if there is enough room (although this behavior is disabled when the table align attribute is center (the default) or justify, or when the noflow attribute is present).

Standard Attributes: CLASS, CLEAR, ID, LANG



When NOFLOW is present, it disables text flow around the table. Using it also eliminates the need to employ NEEDS or CLEAR attributes on the following element.


ALIGN specifies a figure's horizontal alignment.

* BLEEDLEFT: Flush left with the left (window) border.

* LEFT: Flush left with the left text margin.

* CENTER: The default setting for ALIGN. It makes the table centered between the text margins and disables flow around the table.

* RIGHT: Flush right with the right text margin.

* BLEEDRIGHT: Flush right with the right (window) border

* JUSTIFY: Indicates that, when applicable, the table should be reduced or magnified to fill the space between the left and right margins. Align=justify disables text flow around the table.


Specifies the COLSPEC attribute's choice of units:

* units=en: The default setting, this specifies en units (a typographical unit equal to half the point size). It allows user agents to render the table one row at a time without having to wait until all the table's data has been received.

* units=relative: Sets the relative width of columns. In order to determine the proportional width of each column, the user agent sums the values.

* units=pixels: This may be the least useful.

The handling of cell contents that fail to fit into specified column widths is a design issue for user agents. It is possible to clip the cell contents to the given column width. The columns can also be resized so that they fit the contents regardless of what the COLSPEC attribute may be. It is advisable not to resize until all of the table's data has been processed.


COLSPEC is a list of alignment specifications and column widths. The columns list from left to right, and contain a capital letter that's followed by a number. It looks something like this: "L20 C8 L40". They all indicate the alignment of the cell contents: L stands for left, C stands for center, R stands for right, D stands for decimal, and J stands for justification (when this is not viable, it's treated just like L).

It's necessary to use capital letters in COLSPEC since a lower case L becomes easily confused with a one. One or more space characters delimit column entries.

The number in the column listings specifies what the width is in pixels, ens, or as a fractional value of the table width. This approach significantly simplifies hand entry and is of a more compact nature than most SGML table models. By using the width attribute, you can specify the width of the table in em units, pixels, or as a percentage of the space between the left and right margins.


DP indicates what character is to be used for the COLSPEC attribute's decimal point @md for example, dp="," or dp="." (this is the default). It is possible to change the default by the language context, as set by the LANG attribute on enclosing elements.


WIDTH specifies what the desired width of the table is in pixels or in units (according to what the value of the UNITS attribute is). If units=relative, then the width is taken as a percentage of the width that is between the left and right margins. If this attribute would make columns less than half their minimum widths, then it should be ignored by the user agent.


BORDER tells the user agent to create borders around tables (<TABLE BORDER>, for example). The precise appearance of these borders as well as the size of the margins around the cells can be controlled with either information in the STYLE element in the document head or by associated style sheets. It may be particularly useful to subclass tables, cells, and rows in this regard.


You can prevent the browser from automatically wrapping lines by using NOWRAP. If you would like to specify explicit line breaks, you can then do it by using the BR element.

Context: <TABLE> is legal within

<BANNER>, <BODY>, <BODYTEXT>, <DD>, <DIV>, <FIGTEXT>, <FN>, <FORM>, <LI>, <NOTE>, <TD>, <TH>

The following markup can be used within <TABLE>


Suggested style/usage: Close Tag: REQUIRED

Keep several things in mind:

* Cells may be empty.

* Cells spanning rows will contribute to the column count on each of the spanned rows, but will only appear once in the markup (in the first row spanned).

* Header cells are centered by default while data cells are flush left. The ALIGN attribute for the cell can override this; the COLSPEC attribute for the TABLE element; or the ALIGN attribute on the enclosing row's TR element (from most specific to the least).

* When the table's column count is greater than the number of cells for a given row (including cells for spanned rows), the missing cells are treated as occurring on the table's right hand side and are rendered as empty cells.

* Any rows implied by cells spanning rows beyond this should be ignored - the TR elements determine the row count.

* Since the TH and TC elements can only occur within the TR element, the user agent should be able to recover from a missing <TR> tag prior to the first row.

* It is invalid to have cells overlap. When they do, the rendering is implementation dependent.


<CAPTION>A nice table</CAPTION>


E-Mail: HTML for Dummies at html4dum@lanw.com
URL: http://www.lanw.com/html4dum/h4d2e/t0083.htm
Text - Copyright © 1995, 1996 Ed Tittel & Steve James.
For Dummies, the Dummies Man logo and Dummies Press are trademarks or registered trademarks of Wiley Publishing, Inc. Used with Permission.
Web Layout - Copyright © 1996, LANWrights
Revised -- May, 2002 [MCB]