cols

The cols attribute in the <textarea> element determines its visible width by specifying the number of characters displayed per line, although CSS is typically used for more flexible and customizable styling.

cols attribute

The cols attribute in HTML is applied specifically to the <textarea> element. It defines the visible width of the text area by specifying how many characters can fit per line. The value is a positive integer, and it helps control the presentation and layout of the text input. Although cols sets the visual width, it does not limit the total number of characters that can be entered into the text area. For more precise control over the size and style of the text area, CSS is often used in modern web development.

Syntax

index.html
<textarea cols="number">

Example

Here’s an example of using the cols attribute in HTML:

index.html
<form>
  <label for="message">Message:</label>
  <textarea id="message" name="message" cols="40" rows="5"></textarea>
</form>
The dimensions of a <textarea> can also be adjusted using the CSS height and width properties.

Values

  • number
    • A value that defines the width of a textarea in terms of visible characters.

Applies To

The cols attribute can be applied to the following HTML elements.

ElementsAttribute
<textarea>cols

Example

index.html
<textarea cols="60" rows="10">
  This is a textarea element with a width of 60 characters.
</textarea>

Conclusion

The cols attribute sets the visible width of a <textarea> element by defining how many characters fit per line. While it controls presentation, CSS is preferred for more flexible and precise layout adjustments. For modern web design, combining cols with CSS properties like height and width provides greater styling control.