Textarea cols attribute

Definition and Usage

cols 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 Use the attribute to set the width of the text area.

Tip:Use rows or style.height Use the attribute to change the height of the text area.

See also:

HTML Reference Manual:HTML <textarea> cols-Eigenschaft

Example

Example 1

Change the width of the text area:

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

Try it yourself

Example 2

Get the width of the text area in characters:

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

Try it yourself

Example 3

Change the width of the text area using the style.width attribute:

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

Try it yourself

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

Try it yourself

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

Try it yourself

Syntax

Return the cols attribute:

textareaObject.cols

Set the cols attribute:

textareaObject.cols = number

Eigenschaftswert

Wert Beschreibung
number Gibt die Breite des Textbereichs (in durchschnittlicher Zeichengröße) an. Standardwert ist 20.

Technische Details

Rückgabewert: Zahl, die die Breite des Textbereichs in Zeichen angibt.

Browserunterstützung

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Unterstützung Unterstützung Unterstützung Unterstützung Unterstützung