HTML Textarea: Multiline Text and Initial Values
Multiline text
Unlike a single-line input, textarea allows line breaks. Put the starting text between its opening and closing tags. A line break immediately after the opening tag is ignored by the HTML parser.
<label>Notes <textarea name="notes">First lineSecond line</textarea></label>The editable initial value contains two lines.
Display dimensions
rows suggests the number of visible text lines; cols suggests a width based on characters. These do not cap how much a user can enter. CSS and the browser can affect the final dimensions.
<label>Feedback <textarea name="feedback" rows="4" cols="30" maxlength="200"></textarea></label>The field requests four lines of display and a 200-code-unit input limit.
Default text and current text
The initial content becomes the default value. Editing changes the current value sent by the form, not the original markup. A reset operation restores the default. The placeholder is still only a hint.
<form> <label>Comment <textarea name="comment">Draft</textarea></label> <button type="reset">Restore</button></form>Edit Draft, then click Restore to recover it.
Common mistakes and practice
Do not use a value attribute to initialize textarea; put the initial text between the tags. Escape literal ampersands and less-than signs when embedding text in markup. Rows and cols are display hints, not limits. Treat submitted text as untrusted on the server.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
HTML Textarea: Multiline Text and Initial Values — Knowledge Check
Apply the form-control concepts from this lesson.
Where does the initial text of a textarea belong?
Which attribute restricts user-entered length?
What does a form reset do to an edited textarea?
Which attributes describe the approximate visible dimensions of a textarea?
A textarea contains a line break between two sentences. What is true about its value?