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
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.
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.
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).
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.
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.
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).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.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With