Change the width of a text area:
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.
The cols property is supported in all major browsers.
Return the cols property:
Set the cols property:
Value | Description |
---|---|
number | Specifies the width of the text area (in average character width). Default is 20 |
Return Value: | A Number, representing the width of the text area, in characters |
---|
Get the width of the text area, in characters:
The result of x will be:
Change the width of a text area using the style.width property:
Change the width and height of a text area using the cols and rows properties:
Change the width and height of a text area using the style.width and style.height properties:
HTML reference: HTML <textarea> cols attribute