Table Cells (TH and TD)
Permitted Context: TR
Content Model: %body.content
The TH and TD elements are used for table cells. TH is used for table
header cells while TD is used for table data cells. This distinction
gives user agents a means to render such cells distinctly, for instance
by using a larger or heavier font for header cells. It is also needed when
rendering to speech. The CLASS attribute can be used to further
differentiate cells, for instance into heads and subheads. This can be
used together with style sheets to control the cell border style, and
fill color etc.
The horizontal and vertical alignment of cell contents are determined
by the ALIGN and VALIGN attributes respectively. In their absence, the
alignment will be inherited from the TR element for the row. The COLSPEC
attribute of the enclosing TABLE element provides a convenient way of
specifying the default horizontal alignment for columns.
The AXIS and AXES attributes can be used when rendering to speech to
provide abbreviated names for each cell's headers. Another application is
when you want to be able to later process table contents to enter them
into a database. Theses attributes are then used to give database field
names. The table's class attribute should be used to let the software
recognise which tables can be treated in this way.
Note: Disabling word wrap and using the <BR> element in
order to control cell widths is discouraged in favor of using the table
COLSPEC and WIDTH attributes.
Permitted Attributes for the TH/TD Element
- ID
- An SGML identifier used as the target for hypertext
links or for naming particular elements in associated style sheets.
Identifiers are NAME tokens and must be unique within the scope of
the current document.
- LANG
- This is one of the ISO standard language abbreviations,
e.g. "en.uk" for the variation of English spoken in the United Kingdom.
It can be used by parsers to select language specific choices for
quotation marks, ligatures and hypenation rules etc. The language
attribute is composed from the two letter language code from ISO 639,
optionally followed by a period and a two letter country code from ISO
3166.
- CLASS
- This a space separated list of SGML NAME tokens and is
used to subclass tag names. By convention, the class names are
interpreted hierarchically, with the most general class on the left
and the most specific on the right, where classes are separated by a
period. The CLASS attribute is most commonly used to attach a
different style to some element, but it is recommended that where
practical class names should be picked on the basis of the element's
semantics, as this will permit other uses, such as restricting search
through documents by matching on element class names. The conventions
for choosing class names are outside the scope of this specification.
- COLSPAN
- The number of columns spanned by this cell. This allows
you to merge cells across columns. It defaults to 1 (one).
- ROWSPAN
- The number of rows spanned by this cell. This allows
you to merge cells across rows. It defaults to 1 (one).
- ALIGN
- The ALIGN attribute can be used to explicitly specify
the horizontal alignment of paragraphs within a table row:
- align=left
- Paragraphs are rendered flush left. This is the
default for data cells (TD).
- align=center
- Paragraphs are centered. This is the default for
header cells (TH).
- align=right
- Paragraphs are rendered flush right.
- align=justify
- Text lines are justified where practical,
otherwise this gives the same effect as the align=left
setting.
- align=decimal
- Text lines are indented such that the first
occurrence of a decimal point on each line are aligned vertically. If a
line doesn't contain a decimal point, the line is rendered flush left
for data cells and centered for header cells.
Note: In the absence of the ALIGN attribute, the default is
overridden by the presence of an ALIGN attribute on the parent TR element,
or by the COLSPEC attribute on the TABLE element. The COLSPEC attribute
takes precedence over the TR element though!
- DP
- This specifies the character to be used for the decimal
point with the ALIGN attribute, e.g. dp="." (the default) or dp=",".
The default may be altered by the language context, as set by the LANG
attribute on enclosing elements.
- VALIGN
- The VALIGN attribute can be used to explicitly specify
the vertical alignment of material within a table cell:
- valign=top
- The cell contents appear at the top of each cell
(the default).
- valign=middle
- Cell contents are centered vertically in each cell.
- valign=bottom
- The cell contents appear at the bottom of each
cell.
- valign=baseline
- This is used when you want to ensure that all
cells in the row with valign=baseline share the same baseline.
This constraint only applies to the first text line for each cell.
Note: In the absence of the VALIGN attribute, the default can
be overridden by the presence of a VALIGN attribute on the parent TR
element.
- NOWRAP
- The NOWRAP attribute is used when you don't want the
browser to automatically wrap lines. You can then explicitly specify
line breaks in paragraphs using the BR element.
- AXIS
- This defines an abbreviated name for a header cell, which
can be used when rendering to speech. It defaults to the cell's content.
- AXES
- This is a comma separated list of axis names which together
identify the row and column headers that pertain to this cell. It is used
when rendering to speech to identify the cell's position in the table. If
missing the user agent can try to follow up columns and left along rows
(right for some languages) to find the corresponding header cells.
Note: a subheader cell may include both attributes - using
AXIS to name itself and AXES to name the parent header cell. When data
cells refer to header cells with both attributes, the parent header cells
are found by following back the head-subhead relationships.