The HTML DOM Textarea cols return and modify the value of cols attribute of a text area element in an HTML document.
Syntax
Following is the syntax −
1. Returning cols
object.cols
2. Adding cols
object.cols = “number”
Let us see an example of HTML DOM Textarea cols Property:
Example
<!DOCTYPE html> <html> <style> body { color: #000; background: lightseagreen; height: 100vh; } .btn { background: #db133a; border: none; height: 2rem; border-radius: 2px; width: 40%; display: block; color: #fff; outline: none; cursor: pointer; } </style> <body> <h1>DOM Textarea cols Property Demo</h1> <textarea>Hi! I'm a textarea element in an HTML document with some dummy text.</textarea> <button onclick="set()" class="btn">Set Cols = 50</button> <script> function set() { document.querySelector("textarea").cols = '50'; } </script> </body> </html>
Output
Click on “Set Cols = 50” button to set the value of cols attribute to 50.