Easy Tutorial
❮ Jsref Log10E Dom Obj Time ❯

cols Attribute of Textarea

Textarea Object


Example

Modify the width of a textarea element:

document.getElementById("myTextarea").cols = "100";

Definition and Usage

The cols attribute is used to set or return the value of the cols attribute.

The cols attribute specifies the width of the text box in characters.

Tip: You can use the style.width property to set the width of the textarea element.

Tip: You can use the rows and style.height properties to set the width and height of the textarea element.


Browser Support

Attribute Chrome Firefox Safari Edge IE
cols Yes Yes Yes Yes Yes

Syntax

Set the cols attribute:

textareaObject.cols = number;

Return the cols attribute:

textareaObject.cols;

Attribute Values

Value Description
number Specifies the width of the text box. Default is 20.

Technical Details

| Return Value: | A number, representing the width of the text box in characters. |


More Examples

Example

Modify the width using the style.width property:

document.getElementById("myTextarea").style.width = "500px";

Example

Modify the height and width using the cols and rows attributes of the textarea element:

document.getElementById("myTextarea").cols = "100";
document.getElementById("myTextarea").rows = "10";

Example

Modify the width and height using the style.width and style.height properties:

document.getElementById("myTextarea").style.width = "500px";
document.getElementById("myTextarea").style.height = "100px";

Textarea Object

❮ Jsref Log10E Dom Obj Time ❯