15

What's the difference between sizing a textarea with cols and rows and sizing a textarea with height and width?

<textarea id="TextArea1" cols="73" rows="12">with cols rows</textarea>
<textarea id="TextArea2" style="height:200px; width:600px";>with CSS</textarea>

jsFiddle

1

3 Answers 3

14

cols and rows are relative to font size. height and width aren't.

http://jsfiddle.net/rVUEE/1/

EDIT: Saying they are relative to "font size" is a bit too simplistic. They take into account things such as line-height and letter-spacing if explicitly set as well.

Sign up to request clarification or add additional context in comments.

2 Comments

cols is not relative to font size, and neither is rows, really (rows is relative to line height).
@JukkaK.Korpela What is cols relative to then? I guess it's a really a combination of font-size and letter-spacing?
5
  1. The cols and rows attributes were required by HTML specifications. W3C HTML5 (approved in 2014) made them optional, but with impractical default values (20 and 2).
  2. The attributes take effect even when CSS is disabled.
  3. On the other hand, the attributes “lose” if dimensions are also specified in CSS.
  4. The rows attribute specifies the height in terms of lines (effectively, with the line height as implied unit), and the cols attribute specifies the width in terms of “average” character width, a very vague concept, interpreted very differently by browsers. In CSS, any CSS units can be used and must be explicitly specified.

2 Comments

cols and rows are no longer required in the html5 spec.
-1 The rows and cols attributes are not required for the textarea element to pass HTML5 validation, nor are they listed as required by W3C.
0

CSS isn't that different. The result will be (almost) the same.

I'm using most of the time max-width, min-width and the same for height. In new browsers like Chrome you can resize the textarea.

1 Comment

Textarea resizing can be disabled both in CSS and HTML.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.