td/th colSpanProperty
td/th Object
Definition and Usage
The colSpan property sets or returns the number of columns a table cell spans.
Syntax
Set the colSpan property:
tdObject.colSpan="number"
or
thObject.colSpan="number"
or
thObject.colSpan="number"
Return the colSpan property:
tdObject.colSpan
or
thObject.colSpan
or
thObject.colSpan
Tip: There is no default value for the colSpan property.
| Value | Description |
|---|---|
| number | Defines the number of columns to span. |
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the colSpan property.
Example
Example
The following example changes the number of columns a table cell spans.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Example Tutorial(example.com)</title>
<script>
function displayResult(){
document.getElementById("myHeader1").colSpan="2";
}
</script>
</head>
<body>
<table border="1">
<tr>
<th id="myHeader1">Month</th>
<th id="myHeader2">Deposits</th>
</tr>
<tr>
<td>January</td>
<td>$100.00</td>
</tr>
<tr>
<td>February</td>
<td>$10.00</td>
</tr>
<tr>
<td>March</td>
<td>$80.00</td>
</tr>
</table>
<br>
<button type="button" onclick="displayResult()">Change the number of columns spanned by the first cell</button>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>Example Tutorial(example.com)</title>
<script>
function displayResult(){
document.getElementById("myHeader1").colSpan="2";
}
</script>
</head>
<body>
<table border="1">
<tr>
<th id="myHeader1">Month</th>
<th id="myHeader2">Deposits</th>
</tr>
<tr>
<td>January</td>
<td>$100.00</td>
</tr>
<tr>
<td>February</td>
<td>$10.00</td>
</tr>
<tr>
<td>March</td>
<td>$80.00</td>
</tr>
</table>
<br>
<button type="button" onclick="displayResult()">Change the number of columns spanned by the first cell</button>
</body>
</html>
Try it Yourself »
td/th Object Other Extensions