Textarea colsProperty

Textarea 对象参考手册Textarea Object


Examples

Modify the width of the textarea element:

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

Try it Yourself »

Definition and Usage

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

The cols attribute specifies the width of the text area, in characters.

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

Tip:You can use therowsandstyle.heightproperties to set the width and height of the textarea element.



Browser Support

Property
cols Yes Yes Yes Yes Yes

Syntax

Set the cols property:

textareaObject.cols = number

Return the cols property:

textareaObject.cols


Property Values

Value Description
number

Specifies the width of the text area. Default is 20.



Technical Details

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

More Examples

Example

Modify the width using the style.width property:

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

Try it Yourself »

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";

Try it Yourself »

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";

Try it Yourself »


Textarea 对象参考手册Textarea Object

Other Extensions