Tables
Tables are a convenient way of aligning data.
- <TABLE> Marks the beginning of the table.
- <TR> Stands for Table Row
- <TH> Stands for Table Header.
- <TD> Stands for Table Data and defines the contents of a single cell.
<TABLE>, <TR>, <TD> Tags
Try out this table, and save it as ‘Table1.html’. It has 3 columns and 3 rows.
Exercise
HTML
<HTML>
<HEAD>
<TITLE>Tables</TITLE>
</HEAD>
<BODY>
<TABLE>
<TR>
<TD>Cell 1.1 </TD>
<TD>Cell 1.2 </TD>
<TD>Cell 1.3</TD>
</TR>
<TR>
<TD>Cell 2.1</TD>
<TD>Cell 2.2</TD>
<TD>Cell 2.3</TD>
</TR>
<TR>
<TD>Cell 3.1</TD>
<TD>Cell 3.2</TD>
<TD>Cell 3.3</TD>
</TR>
</TABLE>
</BODY>
</HTML>
XHTML
<html>
<head>
<title>Tables</title>
</head>
<body>
<table>
<tr>
<td>Cell 1.1 </td>
<td>Cell 1.2 </td>
<td>Cell 1.3 </td>
</tr>
<tr>
<td>Cell 2.1 </td>
<td>Cell 2.2 </td>
<td>Cell 2.3 </td>
</tr>
<tr>
<td>Cell 3.1 </td>
<td>Cell 3.2 </td>
<td>Cell 3.3 </td>
</tr>
</table>
</body>
</html>
Table Attributes
There are various attributes attached to <TABLE>:
- Border - border of the table
- Cellspacing - space between cells, in pixels
- Cellpadding - space within cells, between text and edge of cell, in pixels
Exercise
HTML
<HTML>
<HEAD>
<TITLE>Tables</TITLE>
</HEAD>
<BODY>
<TABLE border=3 cellspacing=3 cellpadding=3>
<TR>
<TD>Cell 1.1 </TD>
<TD>Cell 1.2 </TD>
<TD>Cell 1.3</TD>
</TR>
<TR>
<TD>Cell 2.1</TD>
<TD>Cell 2.2</TD>
<TD>Cell 2.3</TD>
</TR>
<TR>
<TD>Cell 3.1</TD>
<TD>Cell 3.2</TD>
<TD>Cell 3.3</TD>
</TR>
</TABLE>
</BODY>
</HTML>
XHTML
<html>
<head>
<title>Tables</title>
</head>
<body>
<table border="3" cellspacing="3" cellpadding="3">
<tr>
<td>Cell 1.1 </td>
<td>Cell 1.2 </td>
<td>Cell 1.3 </td>
</tr>
<tr>
<td>Cell 2.1 </td>
<td>Cell 2.2 </td>
<td>Cell 2.3 </td>
</tr>
<tr>
<td>Cell 3.1 </td>
<td>Cell 3.2 </td>
<td>Cell 3.3 </td>
</tr>
</table>
</body>
</html>
Note that in XHTML the attribute contents must be surrounded by quotation marks
Table Headers - <TH>
Headers are used when the data table has named columns.
Exercise
Type in the following table code.
HTML
<TABLE border=1>
<TR>
<TH>Module Name</TH>
<TH>Software</TH>
<TH>Hours per week</TH>
<TH>Tutor</TH>
</TR>
<TR>
<TD>Multimedia Principles </TD>
<TD>Macromedia Director</TD>
<TD>2</TD>
<TD>Vivienne Trulock</TD>
</TR>
<TR>
<TD>Professional Team Brief </TD>
<TD>Various</TD>
<TD>4</TD>
<TD>To be decided</TD>
</TR>
</TABLE>
XHTML
<table border="1">
<tr>
<th>Module Name</th>
<th>Software</th>
<th>Hours per week</th>
<th>Tutor</th>
</tr>
<tr>
<td>Multimedia Principles </td>
<td>Macromedia Director</td>
<td>2</td>
<td>Vivienne Trulock</td>
</tr>
<tr>
<td>Professional Team Brief </td>
<td>Various</td>
<td>4</td>
<td>To be decided</td>
</tr>
</table>
Exercise
Modify the example above to add in a column for Year. Multimedia Principles is in year 1, Professional Team Brief is in year 2.
Table Areas
There are 2 main table areas. The table header and the main body of table information. These are defined by <THEAD> and <TBODY> tags and simply surround the headers and data areas respectively. This is particularly useful for long tables, where the header information is displayed on every page.
Exercise
Add in <THEAD> and <TBODY> information.
HTML
<TABLE border=1>
<THEAD>
<TR>
<TH>Module Name</TH>
<TH>Software</TH>
<TH>Hours per week</TH>
<TH>Tutor</TH>
</TR>
</THEAD>
<TBODY>
<TR>
<TD>Multimedia Principles </TD>
<TD>Macromedia Director</TD>
<TD>2</TD>
<TD>Vivienne Trulock</TD>
</TR>
<TR>
<TD>Professional Team Brief </TD>
<TD>Various</TD>
<TD>4</TD>
<TD>To be decided</TD>
</TR>
</TBODY>
</TABLE>
XHTML
<table border="1">
<thead>
<tr>
<th>Module Name</th>
<th>Software</th>
<th>Hours per week</th>
<th>Tutor</th>
</tr>
</thead>
<tbody>
<tr>
<td>Multimedia Principles </td>
<td>Macromedia Director</td>
<td>2</td>
<td>Vivienne Trulock</td>
</tr>
<tr>
<td>Professional Team Brief </td>
<td>Various</td>
<td>4</td>
<td>To be decided</td>
</tr>
</tbody>
</table>
Table Summaries
Table summaries are used to provide information about the structure of the table. This is particularly useful for screenreader users who cannot see the visual layout of the table. Summaries are attributtes of the Table tag.
Exercise
Add in a table summary.
HTML
<TABLE border=1 summary="This table charts
the software required by MMHND modules, the hours available for the module
per week, and the tutor name.">
<THEAD>
<TR>
<TH>Module Name</TH>
<TH>Software</TH>
<TH>Hours per week</TH>
<TH>Tutor</TH>
</TR>
</THEAD>
<TBODY>
<TR>
<TD>Multimedia Principles </TD>
<TD>Macromedia Director</TD>
<TD>2</TD>
<TD>Vivienne Trulock</TD>
</TR>
<TR>
<TD>Professional Team Brief </TD>
<TD>Various</TD>
<TD>4</TD>
<TD>To be decided</TD>
</TR>
</TBODY>
</TABLE>
XHTML
<table border="1" summary="This table charts
the software required by MMHND modules, the hours available for the module
per week, and the tutor name.">
<thead>
<tr>
<th>Module Name</th>
<th>Software</th>
<th>Hours per week</th>
<th>Tutor</th>
</tr>
</thead>
<tbody>
<tr>
<td>Multimedia Principles </td>
<td>Macromedia Director</td>
<td>2</td>
<td>Vivienne Trulock</td>
</tr>
<tr>
<td>Professional Team Brief </td>
<td>Various</td>
<td>4</td>
<td>To be decided</td>
</tr>
</tbody>
</table>
Exercise
Modify the summary above to reflect the extra 'Year' column.
Table Captions
Captions should provide enough information to allow a screenreader to decide whether to read the table or not. Caption is a tag.
Exercise
Add in a Caption tag.
HTML
<TABLE border=1 summary="This table charts the software required
by MMHND modules, the hours available for the module per week, and the tutor
name.">
<CAPTION>MMHND Module Information</CAPTION>
<THEAD>
<TR>
<TH>Module Name</TH>
<TH>Software</TH>
<TH>Hours per week</TH>
<TH>Tutor</TH>
</TR>
</THEAD>
<TBODY>
<TR>
<TD>Multimedia Principles </TD>
<TD>Macromedia Director</TD>
<TD>2</TD>
<TD>Vivienne Trulock</TD>
</TR>
<TR>
<TD>Professional Team Brief </TD>
<TD>Various</TD>
<TD>4</TD>
<TD>To be decided</TD>
</TR>
</TBODY>
</TABLE>
XHTML
<table border="1" summary="This table charts the software required
by MMHND modules, the hours available for the module per week, and the tutor
name.">
<caption>MMHND Module Information</caption>
<thead>
<tr>
<TH>Module Name</TH>
<TH>Software</TH>
<TH>Hours per week</TH>
<TH>Tutor</TH>
</tr>
</thead>
<tbody>
<tr>
<td>Multimedia Principles </td>
<td>Macromedia Director</td>
<td>2</td>
<td>Vivienne Trulock</td>
</tr>
<tr>
<td>Professional Team Brief </td>
<td>Various</td>
<td>4</td>
<td>To be decided</td>
</tr>
</tbody>
</table>
The next thing to learn is how to make your pages look pretty by adding colour.
created & designed by Vivienne Trulock for ilikecake.net
.