Every time I develop a new form that includes a textarea
I have the following dilemma when I need to specify its dimensions:
Use CSS or use the textarea
's attributes cols
and rows
?
What are the pros and cons of each method?
What are the semantics of using these attributes?
How is it usually done?
The cols attribute specifies the visible width of a text area.
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).
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.
I recommend to use both. Rows and cols are required and useful if the client does not support CSS. But as a designer I overwrite them to get exactly the size I wish.
The recommended way to do it is via an external stylesheet e.g.
textarea { width: 300px; height: 150px; }
<textarea> </textarea>
textarea { height: auto; }
<textarea rows="10"></textarea>
This will trigger the browser to set the height of the textarea EXACTLY to the amount of rows plus the paddings around it. Setting the CSS height to an exact amount of pixels leaves arbitrary whitespaces.
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