<!DOCTYPE html>
<htmllang="en-US">
<head>
<style>
div{
border: 1pxsolid#267326;
padding: 10px;
columns: 150px2;
-webkit-columns: 150px2; /* Chrome, Safari, Opera */-moz-columns: 150px2; /* Firefox */
}
</style>
</head>
<body>
<h1>CSS columns Property</h1>
<div>
Joanne Rowling was born on 31st July 1965 at Yate General Hospital near Bristol, and grew up in Gloucestershire in England and in Chepstow, Gwent, in south-east Wales.
</div>
</body>
</html>
In the following example, we will demonstrate how to change the CSS columns property of an element using JavaScript.
Example
HTML Online Editor
<!DOCTYPE html>
<htmllang="en-US">
<head>
<style>
div{
border: 1pxsolid#267326;
padding: 10px;
margin-bottom: 25px;
columns: 150px2;
-webkit-columns: 150px2; /* Chrome, Safari, Opera */-moz-columns: 150px2; /* Firefox */
}
</style>
</head>
<body>
<h1>CSS columns Property</h1>
<div>
Joanne Rowling was born on 31st July 1965 at Yate General Hospital near Bristol, and grew up in Gloucestershire in England and in Chepstow, Gwent, in south-east Wales.
</div>
<buttononclick="myFunction()">Click Me</button>
<script>
varx=document.getElementsByTagName("div")[0];
functionmyFunction(){
x.style.columns="3";
x.style.WebkitColumns="3";
x.style.MozColumns="3";
}
</script>
</body>
</html>