Introducing Tables
Last update on: 05-08-2008In order to work with tables, you need to start thinking in grids. Tables, just like spreadsheets, are made up of rows and columns. Here you can see a grid of rectangles. Each rectangle is known as a coll. A row is made up of a set of cells on the same line from left to right, while a column is made up of a line of cells going from top to bottom.
To create a table we use the <table> element.
Inside the <table> element the table is written out row by row. A row is contained inside a <tr> element—which stands for table row. And each cell is then written inside the row element using a <td> element—which stands for table data.
Here is an example of a very basic table:
Table headings have their own element, <th>, which is used in place of the table data or <td> element. The <th> element can be used for either column or row headers.
Here you can see a slightly more complex example of a table, which includes headings
In this example, the table shows a financial summary for a small company. Along the top in the first row you can see that there are headings for incomings, outgoings, and profit. The first cell is actually empty, but you must still add either a <td> or <th> element for it in the code; otherwise the first row would have less cells than all the others and the alignment of the columns would not match up as intended.
In each row, the first table cell is also a table heading cell (<th>) that indicates which quarter the results are for. Then the remaining three cells of each row contain table data, and are therefore contained inside the <td> elements. By default, most browsers render the content of a <th> element in bold text.
| Outgoings ($) | Receipts ($) | Profit ($) | |
|---|---|---|---|
| Quarter 1 (Jan-Mar) | 11200.00 | 21800.00 | 10600.00 |
| Quarter 2 (Apr-Jun) | 11700.00 | 22500.00 | 10800.00 |
| Quarter 3 (Jul - Sep) | 11650.00 | 22100.00 | 10450.00 |
| Quarter 4 (Oct - Dec) | 11850.00 | 22900.00 | 11050.00 |
Creating Tables's lessons:
Introducing TablesBasic Table Elements And Attributes
Splitting Up Tables Using A Head Body And Foot
Spanning Columns Using The Colspan Attribute
Spanning Rows Using The Rowspan Attribute

