In this section, we will learn what the cols attribute is and how to use it.
What is cols Attribute in HTML <textarea> Tag?
The cols attribute is used to set the visible width of a textarea field. If the value of this attribute is set to 20, for example, that means the width of the field should be wide enough that users be able to see at least 20 characters in a single line without any need to scroll left or right.
Note: there’s another attribute called rows that is in charge of controlling the height of the target textarea. You can check the rows attribute section if you want to learn more about this attribute.
HTML cols Attribute in <textarea> Tag Syntax:
<textarea cols = “number of visible characters”> </textarea>
<textarea> Tag cols Attribute Values
The value of the cols attribute is a number that declares the number of visible characters in a single line of a textarea.
Example: using cols attribute in HTML <textarea> tag
See the Pen using cols attribute in HTML <textarea> tag by Omid Dehghan (@odehghan) on CodePen.
In this example, the textarea is wide enough that you can type and see at least 50 characters in a single line without any line break or using a scroll.