Textarea cols attribute
Definition and Usage
cols
attribute to set or return the value of the text area's cols attribute.
The HTML cols attribute specifies the visible width of the text area in characters.
Tip:You can also use style.width attribute to set the width of the text area.
Tip:Please use rows or style.height Use the attribute to change the height of the text area.
See also:
HTML Reference Manual:HTML <textarea> cols Attribute
Example
Example 1
Change the width of the text area:
document.getElementById("myTextarea").cols = "100";
Example 2
Get the width of the text area in characters:
var x = document.getElementById("myTextarea").cols;
Example 3
Use the style.width attribute to change the width of the text area:
document.getElementById("myTextarea").style.width = "500px";
Example 4
Use the cols and rows attributes to change the width and height of the text area:
document.getElementById("myTextarea").cols = "100"; document.getElementById("myTextarea").rows = "10";
Example 5
Use the style.width and style.height properties to change the width and height of the text area:
document.getElementById("myTextarea").style.width = "500px"; document.getElementById("myTextarea").style.height = "100px";
Syntax
Return the cols attribute:
textareaObject.cols
Set the cols attribute:
textareaObject.cols = number
Attribute Value
Value | Description |
---|---|
number | Specifies the width of the text area (in terms of average character width). The default value is 20. |
Technical Details
Return Value: | Number, representing the width of the text area in characters. |
---|
Browser Support
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Support | Support | Support | Support | Support |