HTML Tables
<table> Tag is used to define Table in the Web Page. A table may contain one or multiple rows and a row may contain one or more columns. <tr> tag specifies the row and <td> tag specifies the column.
This is the basic format of a table -
<table border="1">
<th>
<td>1</td>
<td>John</td>
</th>
<tr>
<td>2</td>
<td>Smith</td>
</tr>
</table>
1 | 2 |
HTML | CSS |
Table Heading Tag <th> Tag
<th> tag is used to define heading in the table.
<table border="1">
<tr>
<th>S.No.</th>
<th>Name</th>
</th>
<tr>
<td>1</td>
<td>john</td>
</tr>
<tr>
<td>2</td>
<td>Smith</td>
</tr>
</table>
Attributes of Table
Align
With the help of align attribute, we can set the alignment of the Table.
<table align="center">
<th>
<td>1</td>
<td>2</td>
</th>
<tr>
<td>Smith</td>
<td>John</td>
</tr>
</table>
border
This attribute is used to set table border.
<table border="2">
<th>
<td>1</td>
<td>2</td>
</th>
<tr>
<td>Smith</td>
<td>John</td>
</tr>
</table>
cellpadding
cellpadding is used to provide space between cell content and cell borders.
<table border="1" cellpadding="6">
<th>
<td>1</td>
<td>2</td>
</th>
<tr>
<td>John</td>
<td>Smith</td>
</tr>
</table>
cellspacing
cellspacing provides the width of the table borders.
<table border="1" cellspacing="6">
<th>
<td>1</td>
<td>2</td>
</th>
<tr>
<td>John</td>
<td>Smith</td>
</tr>
</table>