ADS

header ads

What is rowspan and colspan in HTML?

What is rowspan?

The rowspan attribute specifies the number of rows a cell should span.

Syntax

<td rowspan="number">

 

Attribute Value

 Value        Description                                                                                                              
 number Specifies the number of rows a cell should span. Note: rowspan="0" tells the browser to span the cell to the last row of the table section (thead, tbody, or tfoot). Chrome, Firefox, and Opera 12 (and earlier versions) support rowspan="0".


Example:

<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
  border: 1px solid black;
}
</style>
</head>
<body>
<h1>The td rowspan attribute</h1>
<table>
  <tr>
    <th>Month</th>
    <th>Savings</th>
    <th>Savings for holiday!</th>
  </tr>
  <tr>
    <td>January</td>
    <td>$100</td>
    <td rowspan="2">$50</td>
  </tr>
  <tr>
    <td>February</td>
    <td>$80</td>
  </tr>
</table>
</body>
</html>
 

Output:-





What is colspan?

The colspan attribute defines the number of columns a cell should span.

Syntax

<td colspan="number">
 

Attribute Value

 Value        Description                                                                                                              
 numberSpecifies the number of columns a cell should span. Note: colspan="0" tells the browser to span the cell to the last column of the column group (colgroup)


Example:

<!DOCTYPE html> 
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
}
</style>
</head>
<body> <h1>The td colspan attribute</h1> <table>
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tr>
<td>January</td>
<td>$100</td>
</tr>
<tr>
<td>February</td>
<td>$80</td>
</tr>
<tr>
<td colspan="2">Sum: $180</td>
</tr>
</table>
</body>
</html>
 

Output:-








Post a Comment

0 Comments