HTML Table Tags and Attributes
HTML provides several tags to create and manage tables in a webpage. Tables are used to
organize data in rows and columns.
Main HTML Table Tags
Tag Function
<table> Defines the table
<tr> Defines a table row
<th> Defines a table heading cell
<td> Defines a table data cell
<caption> Gives a title to the table
Important Attributes of Table Tags
Attributes of <table>
Attribute Function
border Specifies thickness of table border
cellpadding Space between cell content and border
cellspacing Space between table cells
width Sets width of the table
align Aligns the table (left, center, right)
bgcolor Sets background color
bordercolor Sets border color
Attributes of <tr>
Attribute Function
align Aligns text horizontally
valign Aligns text vertically
bgcolor Sets row background color
Attributes of <th> and <td>
Attribute Function
colspan Merges two or more columns
rowspan Merges two or more rows
align Aligns content horizontally
valign Aligns content vertically
width Sets width of cell
height Sets height of cell
bgcolor Sets background color
<html> </table>
<head>
<title>Table</title> </body>
</head> </html>
<body bgcolor="lightyellow">
<h2 align="center">Student Exam Marks</h2>
<table border="2" cellpadding="8" cellspacing="5"
width="70%" align="center">
<tr bgcolor="lightgreen">
<th rowspan="2">S.N</th>
<th rowspan="2">Name</th>
<th colspan="3">Marks</th>
<th rowspan="2">Total</th>
</tr>
<tr bgcolor="lightgreen">
<th>Math</th>
<th>Science</th>
<th>English</th>
</tr>
<tr align="center">
<td>1</td>
<td>Ram</td>
<td>85</td>
<td>80</td>
<td>90</td>
<td>255</td>
</tr>
<tr align="center">
<td>2</td>
<td>Sita</td>
<td>90</td>
<td>88</td>
<td>92</td>
<td>270</td>
</tr>
<tr align="center">
<td>3</td>
<td>Hari</td>
<td>Math</td>
<td>70</td>
<td>75</td>
<td>150</td>
</tr>