The HTML DOM columnSpan property is used for specifying how an element spans across columns.
Following is the syntax for −
Setting the columnSpan property −
object.style.columnSpan = "1|all|initial|inherit"
The above property values are explained as follows −
| Value | Description |
|---|---|
| 1 | Thismakes the element span exactly across one column and this is thedefault value. |
| All | Theelement should span across all columns |
| Initial | Forsetting this property to initial value. |
| Inherit | Toinherit the parent property value |
Let us look at an example for the columnSpan property −
Example
<!DOCTYPE html>
<html>
<head>
<style>
#DIV1{
column-count: 3;
background-color: papayawhip;
}
#P1{
background-color: lightcyan;
font-size: 1.4em;
}
</style>
<script>
function changeColumnSpan(){
document.getElementById("P1").style.columnSpan="all";
document.getElementById("Sample").innerHTML="The column span is now set to 1";
}
</script>
</head>
<body>
<div id="DIV1">
<p id="P1">This is a sample paragraph heading</p>
This is just some random text inside a div. This is going to turn gibberish soon.adkasfdlajfkfask . The text has turned normal now .
</div>
<p>Change the above div column span property by clicking the below button</p>
<button onclick="changeColumnSpan()">Change Column Span</button>
<p id="Sample"></p>
</body>
</html>Output

On clicking the “Change Column Span” button −
