Why not use the <textarea> tag?
<textarea id="txtArea" rows="10" cols="70"></textarea>
Answer from Vinod Vishwanath on Stack OverflowVideos
Why not use the <textarea> tag?
<textarea id="txtArea" rows="10" cols="70"></textarea>
Although <input> ignores the rows attribute, you can take advantage of the fact that <textarea> doesn't have to be inside <form> tags, but can still be a part of a form by referencing the form's id:
<form method="get" id="testformid">
<input type="submit" />
</form>
<textarea form ="testformid" name="taname" id="taid" cols="35" wrap="soft"></textarea>
Of course, <textarea> now appears below "submit" button, but maybe you'll find a way to reposition it.
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.
One line only. this.style.height = this.scrollHeight + "px" sets its true height, while this.style.height = "" allows the textarea to shrink as well as stretch.
<textarea name="text" oninput='this.style.height = "";this.style.height = this.scrollHeight + "px"'></textarea>
Not really. This is normally done using javascript.
there is a good discussion of ways of doing this here...
Autosizing textarea using Prototype