HTML-TABLE
HTML-TABLE
TABLES
• Tables are used to present data for scientific research, sales figure, class schedules, and sports
statistics, among others.
• A table is useful to summarize data from a database search or a set of choices. With HTML
tables, its not just text that can be placed inside but as well as pictures, links and even video and
sounds.
• The basic parts of a table are columns, rows and cells. When making a table, you must be able to
identify the exact number of columns and rows that you will need followed by defining the cells
one by one. A cell is a rectangular region at the intersection of a row and column. A row is a
single horizontal line of data. A column is a single vertical line of data.
TABLE TAGS
TABLE ATTRIBUTE
• To distinguish the heading from the rest of the data, use the <TH> tag to specify the header cell.
A closing tag is optional.
• The <TH> tag has four attributes:
Align
V-align
Colspan
Rowspan.
<body>
ADDRESS BOOK
<table border=“1”>
<tr>
<th>NAME</th>
<th>BIRTHDAY</th>
<th>ADDRESS</th></tr>
<tr>
<td>Archie Santos</td>
<td>February 29</td>
<td>125 New South Wales, Australia</td></tr>
<tr>
<td>Yvette Catubig</td>
<td>December 25</td>
<td>Ontario, Canada/td></tr></table>
ALIGNING CELLS
The align attribute specifies the alignment of the cell’s contents. You can align it at the center, left, right,
justify or decimal. If the alignment is not specified, the content of the cell will be displayed at the center.
<table border=“2”>
<tr><th>FOURTH YEAR</th></tr>
<tr align=“left”>
<td>2345</td></tr>
<tr align=“right”>
<td>1234</td></tr>
<tr align=“center”>
<td>5678</td></tr>
</table>
V-ALIGNING CELLS
• This attribute allows you to control the text inside the cells where it is aligned. You can display it
on the top, bottom, or vertically centered with in the cell.
• You can place V-align attribute inside a TR, TH, or TD.
<table border=“1”>
<tr>
<td rowspan=“3” valign=“top” align=“left”>ART</td>
</tr>
<tr>
<td rowspan=“3” valign=“bottom” align=“left”>MENDOZA</td>
</tr> >
<tr>
<td rowspan=“3” valign=“center” align=“left”>SANTOS</td></table>
A table heading oftentimes occupy more space than the rest. Spanning columns and rows enables you to
create interesting grids and to manage areas of space within a table more completely.
COLSPAN= To span a column
ROWSPAN = To span a row.
<body>
<center>
<table border=“3” color=“blue”
<tr>
<td colspan=“3” align=“center><font size=“6”>CLASS
SCHEDULE</font></td></tr>
<tr align=“center”>
<th>TIME</th><th>DAY</th><th>SUBJECT</th></tr>
</table>
</center>
<table border=“1”>
<tr>
<td rowspan=“2” valign=“top” align=“left”>4th Year Level</td>
<td valign=“top” align=“left”>1234</td>
<td valign=“top align=“left”>MALE</td>
</tr>
<td valign=“top” align=“left”>2345</td>
<td valign=“top align=“left”>FEMALE</td>
</table>
<!doctype html>
<html>
<head></head>
<title> Class Schedule</title>
<body bgcolor="pink">
<center>
<tr bordercolor="red">
<th align="center" width="250"><font face= "Arial Black" color="red">TIME</th>
<th align="center" width="250"><font face= "Arial Black" color="red">MONDAY</th>
<th align="center" width="250"><font face= "Arial Black" color="red">TUESDAY</th>
<th align="center" width="250"><font face= "Arial Black" color="red">WEDNESDAY</th>
<th align="center" width="250"><font face= "Arial Black" color="red">THURSDAY</th>
<th align="center" width="250"><font face= "Arial Black" color="red">FRIDAY</th>
</tr>
<tr bordercolor="red" >
<td align="center"><b>6:00-6:50</td>
<td align="center" width="350px" colspan="3"><b>TLE-ICT</b> <br/>
Mrs. C. Talisay</td>
<td align="center" width="350px" colspan="2"><b>Online Class</b> <br/>
Mrs. C. Talisay</td>
</tr>
<tr>
<td align="center"><b>9:20-9:45</td>
<td align="center" width="350px"colspan="5"><b>BREAKTIME</b> <br/>
</tr>
</table>
</body>
</html>
cellspacing cellpadding
table
Border
Bordercolor
colspan
CELLPADDING
• Cellpadding sets the amount of space (both horizontal and vertical between the cell wall and the
contents.
• The default value of cellpadding is 1.
• The text inside will look much better if you move it away from the border lines. It will look less
crowded.
<table border>
<table border=“value” cellpadding=“1”>default
<table border=“value” cellpadding=“value”>
<h2>COMPUTER COURSES</h2><br>
<table border=“2” cellpadding=“10”>
<tr><th>YEAR</th><th>COURSE</th></tr>
<tr><td>FIRST</td><td>Windows 98</td></tr>
<tr><td>SECOND</td><td>MS Word 98</td></tr>
<tr><td>THIRD</td><td>MS Excel</td></tr>
<tr><td>FOURTH</td><td>HTML</td></tr>
</table>
ADJUSTING CELL SPACE
• Cellspacing allows you to increase or decrease the amount of space between the cells of a table.
If the borders are visible, cellspacing controls the width of the internal borders.
• With cellspacing, you can further increase or decrease the width of the spaces.
<h2>COMPUTER COURSES</h2><br>
<table border=“2” cellpadding=“10” cellspacing=“10”>
<tr><th>YEAR</th><th>COURSE</th></tr>
<tr><td>FIRST</td><td>Windows 98</td></tr>
<tr><td>SECOND</td><td>MS Word 98</td></tr>
<tr><td>THIRD</td><td>MS Excel</td></tr>
<tr><td>FOURTH</td><td>HTML</td></tr>
</table>
WORKING WITH WIDTH
• Use the WIDTH attribute to determine the width of the table to be used.
• The width can be expressed either as an absolute value in pixels or as a percentage of the screen
width.
<html>
<head>
<title> Width </title>
</head>
<body bgcolor="pink">
Sample Output:
SETTING BGCOLOR
To use the BGCOLOR attribute, set the background color for a table row. Make sure that when you use
BGCOLOR it should not be the same color or shade with your font color.
<html>
<head>
<title> Sample Table </title>
</head>
<body bgcolor="salmon">
</tr>
</table>
</body
</html>
Sample Output:
BORDER COLOR
Syntax: <bordercolor=“color”>
Nesting Tables
Just like lists, tables can be nested. Web page developers use this technique to enhance even more the
layout and structure.
<!doctype html>
<html>
<head>
<title> Home </title>
</head>
<body>
<table border="2" height="80%" width="100%">
<tr>
<td width="30%" valign="top">
<h3><align="center"> LINKS </h3>
<ul>
<li><a href="homepage.html"> Home </a>
<li><a href="personal profile-list.html">Personal Profile </a>
<li><a href="favorite song.html">Favorite Song </a>
<li><a href="photo gallery.html">Photo Gallery </a>
<li><a href="school.html">My School </a>
<li><a href="contacts.html">Contacts </a>
</ul>
</td>
<td>
<table align="center" border="3" bordercolor="red" width ="600" cellpadding ="4" cellspacing="6">
<caption> <h3> Directory</h3></caption>
<tr bgcolor="yellow">
You can add image to a cell by using the tag pair <td> <img src=”image”>
<!doctype html>
<html>
<head>
<title> HOMEPAGE</title>
</head>
<body>
You can apply hyperlink to a cell by using the tag pair <td><a> <img src=”image”>
<!doctype html>
<html>
<head>
<title> HOMEPAGE</title>
</head>
<body bgcolor="pink">
</tr>
</table>
</body>
</html>
Sample output: