View video tutorial

HTML cols Attribute

HTML

The HTML cols attribute is used to specify the visible width of a <textarea> element, based on the average character width.

Definition and Usage


➔ The cols attribute determines how many characters should fit on a line of the text area.

➔ The cols attribute on the textarea element takes a positive integer value.

➔ The cols attribute default value is 20 characters if not specified.

Syntax
//In HTML
<textarea rows="5" cols="25" id="sample">
    This text area will display 5 visible lines with 25 characters.
</textarea>

//In Javascript
let element=document.querySelector("#sample");
element.cols = 30;
//or
element.setAttribute("cols", "30");

Applies to

This attribute can be used on the following element.

Attribute Element
cols <textarea>