HTML 4 table Tag

Also see HTML5 <table> Tag.

This page contains information about the HTML 4 version of this element. For a more up to date version, see HTML5 <table> Tag.


The HTML <table> tag is used for defining a table. The table tag contains other tags that define the structure of the table.

Table Elements

Tables consist of the <table> element as well as other table-related elements. These other elements are nested inside the <table> tags to determine how the table is constructed.

The children of a <table> element must be, in order:

  1. Zero or one <caption> elements
  2. Zero or one <colgroup> elements
  3. Zero or one<thead> elements
  4. Zero or one <tfoot> elements (but only if the last element in the table is not a <tfoot> element)
  5. Either:
    • Zero or more <tbody> elements, or
    • One or more <tr> elements (these represent the table rows)
  6. Zero or one <tfoot> elements (but only if there are no other <tfoot> elements in the document)

Each <tr> element represents a row in the table. A row can have one or more <td> or <th> elements, which determine the columns in the table. Specifically, <td> represents table data and <th> represents a table header.

Example

Attributes

Attributes specific to this tag:
summaryProvides a summary of the table's structure and purpose for non-visual user agents.
alignVisual alignment of the table (i.e. left, center, right). This attribute is deprecated, use CSS instead.
widthWidth of the table.
Other Attributes:
AttributeDescription
dirSpecifies the direction of the text
classDocument wide identifier.
idDocument wide identifier
langLanguage code
titleSpecifies a title to associate with the element. Many browsers will display this when the cursor hovers over the element (similar to a "tool tip").
styleInline style (CSS)
bgcolorBackground color of the table.

Note: This attribute is deprecated, use the CSS background-color property instead.

frameUsed in conjunction with the border attribute, specifies which side of the frame that makes up the border surrounding the table is displayed. Possible values:
  • void: None are displayed. This value is the default
  • above: Top side of the frame
  • below: Bottom side of the frame
  • hsides: Top and bottom sides
  • vsides: Right and left sides
  • lhs: Left side
  • rhs: Right side
  • box: All sides
  • border: All sides
rulesUsed in conjunction with the border attribute, specifies which rules appear between the cells of the table. Possible values:
  • None: None are displayed. This value is the default
  • groups: Rules appear between row groups and column groups
  • rows: Between rows
  • cols: Between columns
  • all: Between all rows and columns
borderSpecifies the width of the border around the table. For no border, use 0 (zero).
cellspacingSpecifies the space between cells.
cellpaddingSpecifies the space between the cell borders and their contents
onclickIntrinsic event (see event handlers)
ondbclickIntrinsic event (see event handlers)
onmousedownIntrinsic event (see event handlers)
onmouseupIntrinsic event (see event handlers)
onmouseoverIntrinsic event (see event handlers)
onmousemoveIntrinsic event (see event handlers)
onmouseoutIntrinsic event (see event handlers)
onkeypressIntrinsic event (see event handlers)
onkeydownIntrinsic event (see event handlers)
onkeyupIntrinsic event (see event handlers)

Try it Yourself!

Modify the code below, then click Update. See below for attributes.

HTML5 Tags

The information on this page is based on HTML version 4.01. Most modern browsers now support HTML5, which is the next version of HTML after HTML 4.01.

See HTML5 <table> Tag for the HTML5 version of the above element.

Also see this list of HTML 5 tags for the latest version of HTML.