References

Beginner-friendly references for web development, with live, editable examples.

The HTML cols attribute

Attribute All modern browsers Updated
Quick answer

The HTML cols attribute sets the visible width of the textarea in average character widths. It is used on the <textarea> element.

Overview

The cols attribute sets the visible width of a textarea. It is used on the <textarea> element.

It configures a <textarea> multi-line text field — its visible size and how line breaks are handled on submission.

Syntax

<textarea cols="40" rows="4"></textarea>

Values

Value
A positive integer (default 20).

Example

Live example
<textarea cols="30" rows="3">Resize me</textarea>

Best practices

  • Set the visible size with rows (and cols), or with CSS height.
  • Pair the textarea with a <label>.
  • Use the CSS resize property if the drag-to-resize handle does not suit your layout.
  • Limit length with the maxlength attribute.

Frequently asked questions

What does the cols attribute do?
Sets the visible width of a textarea.
How do I set the size of a textarea?
Use the rows and cols attributes, or set its width and height with CSS.
What does the wrap attribute do?
It controls whether line breaks the user sees are included in the submitted value (soft) or not (hard adds them).
Which elements use the cols attribute?
It is an element-specific attribute, used on the <textarea> element.