HTML Table Tag


Tables are defined with the <table> tag. The <tr> element defines a table row,the <td> element defines a table cell and the <th> element defines a table heading.By default, table headings are bold and centered.

Example
<table>
 <tr>
   <th>Roll No</th>
   <th>Name</th>
   <th>Mark</th>
 </tr> 
 <tr>
   <td>101</td>
   <td>Ram</td>
   <td>50</td>
 </tr>
</table> 
Try it Yourself

Output:

Roll No Name Mark
101 Ram 50
102 Sara 94

HTML Table - Border Attribute

Border attribute is used to specify the border around the table cells.

Example
<table border="1">
 <tr>
   <th>Roll No</th>
   <th>Name</th>
   <th>Mark</th>
 </tr> 
 <tr>
   <td>101</td>
   <td>Ram</td>
   <td>50</td>
 </tr>
</table> 
Try it Yourself

Output:

Roll No Name Mark
101 Ram 50
102 Sara 94

HTML Table - Colspan

Colspan attribute is used to merge two or more table cells in a column.

Example
<table border="1">
 <tr>
    <th colspan="3">Student Mark</th>
 </tr>
 <tr>
    <th>Roll No</th>
    <th>Name</th>
    <th>Mark</th>
  </tr> 
 <tr>
    <td>101</td>
    <td>Ram</td>
    <td>50</td>
  </tr>
</table>
Try it Yourself

Output:

Student Mark
Roll No Name Mark
101 Ram 50
102 Sara 94

HTML Table - Rowspan

Rowspan attribute is used to merge two more rows in a table.

Example
<table>
  <tr>
    <th>Name</th>
    <th>Mark</th>
    <th>Total</th>
  </tr> 
  <tr>
    <td rowspan="2">Ram</td>
    <td>50</td>
    <td rowspan="2">144</td>
  </tr>
  <tr>
    <td>94</td>
  </tr>
</table>
Try it Yourself

Output:

Student Mark
Name Mark Total
Ram 50 144
94
Sara 90 184
94

HTML Table - Cellpadding

Cellpadding means padding of text or content inside table cell from the table border.

Example
<table border="1" cellpadding="10">
 <tr>
   <th>Roll No</th>
   <th>Name</th>
   <th>Mark</th>
 </tr> 
 <tr>
   <td>101</td>
   <td>Ram</td>
   <td>50</td>
 </tr>
</table> 
Try it Yourself

Output:

Roll No Name Mark
101 Ram 50
102 Sara 94

HTML Table - Cellspacing

cellspacing attribute in table is used to set margin between table cells and table border.

Example
<table border="1" cellspacing="10">
 <tr>
   <th>Roll No</th>
   <th>Name</th>
   <th>Mark</th>
 </tr> 
 <tr>
   <td>101</td>
   <td>Ram</td>
   <td>50</td>
 </tr>
</table>
Try it Yourself

Output:

Roll No Name Mark
101 Ram 50
102 Sara 94