Latest web development tutorials
 

Textarea cols Property

< Textarea Object

Example

Change the width of a text area:

document.getElementById("myTextarea").cols = "100";
Try it Yourself »

Definition and Usage

The cols property sets or returns the value of the cols attribute of a text area.

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

Tip: You can also use the style.width property to set the width of a text area.

Tip: Use the rows property, or the style.height property to change the height of a text area.


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The cols property is supported in all major browsers.


Syntax

Return the cols property:

textareaObject.cols

Set the cols property:

textareaObject.cols=number

Property Values

Value Description
number Specifies the width of the text area (in average character width). Default is 20

Technical Details

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

More Examples

Example

Get the width of the text area, in characters:

var x = document.getElementById("myTextarea").cols;

The result of x will be:

50
Try it Yourself »

Example

Change the width of a text area using the style.width property:

document.getElementById("myTextarea").style.width = "500px";
Try it Yourself »

Example

Change the width and height of a text area using the cols and rows properties:

document.getElementById("myTextarea").cols = "100";
document.getElementById("myTextarea").rows = "10";
Try it Yourself »

Example

Change the width and height of a text area using the style.width and style.height properties:

document.getElementById("myTextarea").style.width = "500px";
document.getElementById("myTextarea").style.height = "100px";
Try it Yourself »

Related Pages

HTML reference: HTML <textarea> cols attribute


< Textarea Object