Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sizing a textarea with CSS vs with cols and rows

Tags:

html

textarea

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

like image 550
frenchie Avatar asked May 17 '13 15:05

frenchie


People also ask

What does textarea element do what do rows and COLS attributes do?

rows and cols attributes to allow you to specify an exact size for the <textarea> to take. Setting these is a good idea for consistency, as browser defaults can differ. Default content entered between the opening and closing tags. <textarea> does not support the value attribute.

How make textarea responsive CSS?

Try textarea {max-width:95%;} - it will always fit your display. Show activity on this post. I set the number of columns to slightly greater that the width of the div on a large screen and as the screen gets smaller it acts responsive to the screen size.

What is rows and columns in textarea?

Definition and Usage The <textarea> element is often used in a form, to collect user inputs like comments or reviews. A text area can hold an unlimited number of characters, and the text renders in a fixed-width font (usually Courier). The size of a text area is specified by the cols and rows attributes (or with CSS).

How can you change the size of a textarea element?

We can set the size for the text area by using rows and columns. rows*columns will be the size of the text area. For columns, we have to use the cols keyword.


2 Answers

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.

like image 200
James Montagne Avatar answered Sep 19 '22 16:09

James Montagne


  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.
like image 26
Jukka K. Korpela Avatar answered Sep 16 '22 16:09

Jukka K. Korpela