HTML TABLES
Introduction
HTML Table Tags
Tag | Meaning |
<table>----</table> | To create table Or To represent entire table |
<tr>-------</tr> | Represent table row |
<td>----------</td> | Represent a cell in a row |
<th>----------</th> | Column header |
<caption>--------</caption> | Title of the table |
|
<table>-----------</table>
<tr>------</tr>
<tr>------</tr>
Table or row can not contain data…to add data cells should be created within each row.
<tr> <td>--</td> <td>--</td> <td>--</td> </tr>
<tr> <td>--</td> <td>--</td> <td>--</td> </tr>
<tr> <td>--</td> <td>--</td> <td>--</td> </tr>
Example
<!DCOCTYPE html>
<html>
<head>
<title> HTML Table Tag Example</title
</head>
<body>
<table>
<tr> <td>82</td> <td>80</td> </tr>
<tr> <td>80</td> <td>75</td> </tr>
</table>
</body>
</html>
Border tag
!DCOCTYPE html>
<html>
<head>
<title> HTML Table Tag Example</title
</head>
<body>
<table border="1">
<tr> <td>82</td> <td>80</td> </tr>
<tr> <td>80</td> <td>75</td> </tr>
</table>
</body>
</html>
Adding a table border also adds boundaries of 1 pixel thick to all the cells individually.
Note: Thickness of individual boundaries can not change.
Row & Column Header
<!DCOCTYPE html>
<html>
<head>
<title> HTML Table Tag Example</title
</head>
<body>
<table border="1">
<tr> <th> Student Name </th><th>OS</th> <th>OOPS</th> </tr>
<tr> <td>sujay</td> <td>82</td> <td>80</td> </tr>
<tr> <td>Tulasi</td><td>80</td> <td>75</td> </tr>
</table>
</body>
</html>
Contd..
<!DCOCTYPE html>
<html>
<head>
<title> HTML Table Tag Example</title
</head>
<body>
<table border="1">
<tr> <td> </td><th>OS</th> <th>OOPS</th> </tr>
<tr> <th>sujay</th> <td>82</td> <td>80</td> </tr>
<tr> <th>Tulasi</th><td>80</td> <td>75</td> </tr>
</table>
</body>
</html>
<th> tag is also used to add a row header
<caption> tag
<!DCOCTYPE html>
<html>
<head>
<title> HTML Table Tag Example</title
</head>
<body>
<table border="1">
<caption> Marks </caption>
<tr> <th>Name</th><th>OS</th> <th>OOPS</th> </tr>
<tr> <th>sujay</th> <td>82</td> <td>80</td> </tr>
<tr> <th>Tulasi</th><td>80</td> <td>75</td> </tr>
</table>
</body>
</html>
Rowspan and colspan
<!DOCTYPE html>
<html>
<head>
<title> HTML Table Tag Example</title
</head>
<body>
<table border="1">
<caption> Marks </caption>
<tr>
<th rowspan=2>Name</th>
<th colspan=2>Marks</th>
</tr>
<tr>
<th>OS</th> <th>OOPS</th> </tr>
<tr> <th>sujay</th> <td>82</td> <td>80</td> </tr>
<tr> <th>Tulasi</th><td>80</td> <td>75</td> </tr>
</table>
</body>
</html>
Cellspacing and cellpadding
<!DOCTYPE html>
<html>
<head>
<title> HTML Table Tag Example</title
</head>
<body>
<table border cellspacing="6" cellpadding="3" width=300>
<caption> Marks </caption>
<tr>
<th rowspan=2>Name</th>
<th colspan=2>Marks</th>
</tr>
<tr>
<th>OS</th> <th>OOPS</th> </tr>
<tr> <th>sujay</th> <td>82</td> <td>80</td> </tr>
<tr> <th>Tulasi</th><td>80</td> <td>75</td> </tr>
</table>
</body>
</html>
These attributes are used to adjust white spaces in your table.
“cellspacing”space between adjacent cells.
“Cellpadding”space between the cell border and its content.
cellspacing
cellpadding
Attributes in <table> tag
Attributes in tr tag