HTML Textarea
Previously, form="id" and button form* attributes answered ownership and submit routing. Textarea is a different job: a multi-line text control for comments, messages, and notes. Single-line <input type="text"> wraps poorly for paragraphs. Use <textarea> when the user needs room to write more than one line.
Why textarea exists
Contact forms, support tickets, bios, and review boxes need scrolling height and soft line breaks. A textarea keeps that text as one named field on submit. It still wants a visible label, a name for the payload, and optional size or limit hints — but its content model differs from input: text lives between the tags.
Direct answer
1) Write <textarea id="msg" name="msg" rows="5"></textarea> (add cols or CSS as you like).
2) Connect a <label for="msg">…</label> (or wrap the control).
3) Put any default text between the opening and closing tags — not in a value attribute.
4) Optional helpers: placeholder, maxlength, readonly, disabled, required, wrap.
5) This is multi-line entry — not the previous lesson’s form= association or formaction overrides.
📊 Textarea attributes beginners use
| Attribute | Role | Beginner tip |
|---|---|---|
| name | Submit key | Required if the text should post with the form |
| id | Label hook | Match label for= for accessible naming |
| rows | Visible height hint | Lines of height before scrolling |
| cols | Visible width hint | Prefer CSS width for responsive layouts |
| placeholder | Soft hint | Disappears when the user types |
| maxlength | Character cap | Browser-enforced upper bound |
| readonly / disabled | Lock vs mute | readonly still submits; disabled usually does not |
| wrap | Soft/hard wrap | Affects how line breaks are submitted (soft vs hard) |
Feedback form: labeled message box
A short feedback form keeps email as a single-line input and the message as a textarea. Default starter text sits between the tags so the user can edit or replace it.
<form action="/feedback" method="post">
<label for="email">Email</label>
<input id="email" name="email" type="email" required>
<label for="msg">Message</label>
<textarea id="msg" name="msg" rows="6" cols="40"
placeholder="What went well? What can improve?">Thanks for reading —</textarea>
<button type="submit">Send feedback</button>
</form>
Reading the feedback demo
textarea(notinput) is the multi-line controlid="msg"pairs withlabel for="msg"name="msg"keys the submitted paragraphrows="6"hints visible height;cols="40"hints width (CSS can override)- Default text
Thanks for reading —sits between the tags placeholdershows only when the field is empty of user/default content depending on browser rules — prefer clear labels either way- Previous-lesson
form=is unused here — both fields nest inside the form
Sizing, limits, and wrap
A second demo shows a bio field with maxlength, wrap="soft", and a note that CSS often replaces cols for fluid layouts. readonly appears on a summary box the user can copy but not edit.
<label for="bio">Short bio</label>
<textarea id="bio" name="bio" rows="4" maxlength="280"
wrap="soft"
style="width:100%; max-width:28rem; resize:vertical;"
placeholder="Up to 280 characters"></textarea>
<label for="summary">Auto summary (read-only)</label>
<textarea id="summary" name="summary" rows="3" readonly>Generated preview — edit the bio above.</textarea>
Reading the sizing demo
maxlength="280"caps typed length in supporting browserswrap="soft"keeps visual wraps without forcing CR/LF into the submitted value the wayhardcan- Inline CSS
width+resize:verticalrefines size beyondcols readonlylets users see/select text; they should not edit it- Both fields still need
nameif they should submit - Next lesson covers
<select>for choosing from a list — not free-form paragraphs
Choosing textarea vs input
- One short line (name, email, title): prefer
<input type="text|email|…"> - Paragraphs / comments / messages:
<textarea> - Size with
rows(and CSS); treatcolsas a legacy width hint - Default content → between tags; do not use
value="…"like input - Still wire
label+namelike other controls - Nested inside
<form>when layout allows;form="id"still works if you must detach (previous lesson) - Do not confuse this control with
formaction/ ownership attributes
Practice — build and resize
- Copy the feedback demo; remove the default text between tags and add a short starter sentence of your own.
- Change
rowsfrom 6 to 3 and notice the visible height. - Add
maxlength="500"on the message and try pasting a long paragraph. - Replace
colswith a CSSwidth(keeprows) for a fluid layout. - Temporarily put
value="Hello"on the textarea and confirm it does not replace between-tag content the way input does — then removevalue. - Write one sentence: textarea holds multi-line text between its tags; input uses
value. - Peek ahead: list choices belong in
<select>next — not a textarea of options.
Easy mistakes
- Putting default text in
value="…"instead of between the tags - Forgetting
nameso the message never submits - Skipping a
label(placeholder is not a full accessible name) - Using
<input type="text">when the user needs several lines - Confusing this lesson with previous
form=/formactionownership routing - Relying only on
colsfor responsive width - Setting
disabledwhen you meantreadonly(disabled fields often omit from submit)
Summary
<textarea>= multi-line text entry- Label it; give it a
namefor submit - Default text sits between the opening and closing tags
- Hint size with
rows/ CSS; optionalmaxlength,placeholder,readonly - Not the previous lesson’s form-association attributes
- Next:
<select>for picking from a list
🧠 Test Your Knowledge
Test Your Knowledge
Challenge yourself with this interactive quiz and see how well you understand the topic
📝 Instructions
- Read each question carefully
- Select the best answer for each question
- You can retake the quiz as many times as you want
- Your progress will be shown at the top