cols (HTML attribute)

Spec
Depr. Version
No HTML 2
Browser support (more…)
IE5.5+ FF1+ SA1.3+ OP9.2+ CH2+
Full Full Full Full Full

Syntax

cols="number"

Description

The cols attribute defines the width of the textarea, the value of which reflects the number of characters that can be entered (although how well this actually matches up to the actual number of characters displayed width-wise is debatable, as the font style for characters may change with the style specified for this element in the CSS). If cols isn’t specified at all (even though it’s a required attribute), the textarea will render with a width of 20 characters. Applying a value of "40" to the cols attribute doubles the available width, as Figure 1 shows.

Figure 1. Two textareas, the first without a cols attribute, the second with cols set to "40" Two textareas, the first wthout cols attribute, the second with cols set to 40

Note that cols is a required attribute, as is rows, so you shouldn’t replace it with CSS styling. Instead, the CSS should override the size defined in this attribute. Without this attribute, your page can’t possibly validate (and besides, it’s helpful for users who are browsing with CSS switched off).

Example

The cols attribute for this textarea is set to "40" characters:

<form>
  <label for="perfectday">Describe your perfect day:</label>
  <textarea id="perfectday" accesskey="d" cols="40"></textarea>
  <input type="submit" value="Tell us"/>
</form>

Value

This attribute takes as its value a number only—it can’t take percentages or other values.

Compatibility

Internet Explorer Firefox Safari Opera Chrome
5.5 6.0 7.0 8.0 1.0 1.5 2.0 3.0 3.5 1.3 2.0 3.1 4.0 9.2 9.5 10.0 2.0
Full Full Full Full Full Full Full Full Full Full Full Full Full Full Full Full Full

It causes no compatibility issues, and has excellent support across all tested browsers.

User-contributed notes

There are no comments yet.

Related Products