Last updated 2015 January 6

To see the HTML tagging, use the view page source menu item in your browser. In Firefox, use the right button bring up the pop-up menu that contains the menu item — but the page cannot be in a frame, you need to use the right button to view the page in a new tab or a new window.

Tables

Tables are are web page equivalents of spreadsheets. Every table is a sequence of table rows, TR element and within each row is a sequence of tab data cells, TD element.

The following is an example with four rows, three columns and a 1-pixel border around the table and each cell.

Last Name First name Age
Smith John 25
Doe Joan 53
Solzenitsyn Alexander 19
Teslya Leila 25

Table captions

The Caption element can be used to give a name to a table. It can appear only as the beginning of the table specification.

Members ages
Last Name First name Age
Smith John 25
Doe Joan 53
Solzenitsyn Alexander 19
Teslya Leila 25

Table header element

In place of the TD element, you can use the TH element to specify the items in the row of table header cells. They are rendered in bold. Note the use of the scope=col attribute-value to indicate the TH element is for a column header.

Members ages
Last Name First name Age
Smith John 25
Doe Joan 53
Solzenitsyn Alexander 19
Teslya Leila 25

You can use the TH element as the first cell in each row, thereby having row labels. Note the use of the scope=row attribute-value to indicate the TH element is for a row header.

Members ages
Last Name First name Age
1 Smith John 25
2 Doe Joan 53
3 Solzenitsyn Alexander 19
4 Teslya Leila 25

Table element atributes

Table element attributes are handled with CSS specification.

TD and TR element attributes

The following shows the attributes that TR and TD elements still have. Other attributes are now handled with CSS specification.

Column span attribute

A cell can be specified to span across multiple columns. The attribute-value in the example is colspan=2

TH element spans two columns
Column 1 Column 2
TD element spans two columns

Row span attribute

A cell can be specified to span across multiple rows. The attribute-value in the example is rowspan=2

TH element spans two rows Row 1 column 2 TD element spans two rows
Row 2 column 2

Nested tables

The data in a cell can itself be a table.

subtable 1,1 subtable 1,2
subtable 2,1 subtable 2,2
Cell 1,2
Cell 2,1 Cell 2,2