Explain it simply
Explain it simply
<input type="text"> holds a single line. When the user has to write several lines, such as a message, a review or a full address, you use <textarea>: Enter starts a new line and the box can be resized.
<select> is a dropdown where the user picks from a menu. Nobody types anything; they simply choose one of the options you prepared. That keeps the data clean for questions with a fixed set of answers, like "which service?" or "which city?".
Problem → Why → Solution
The problem: a label-less textarea and a dropdown that answers for the user
This feedback form has two problems. The textarea only has a placeholder, so the instruction vanishes as soon as the user starts typing, and screen readers get no dependable name. The select fails more quietly: a user who skips it still submits the first option, Yangon, so the report shows nearly everyone living in Yangon.
<textarea name="comment" placeholder="Tell us what went wrong"></textarea>
<select name="city">
<option>Yangon</option>
<option>Mandalay</option>
<option>Naypyitaw</option>
</select>
<!-- Untouched form submits: comment=&city=Yangon -->Why does this happen?
A placeholder is only a hint that disappears once there is a value; it does not do a label's job. In a single select with no option marked selected, the browser selects the first option, so there is no "not answered yet" state at all. The fix is a visible label plus a value="" placeholder option combined with required.
Core concept: textarea content is its value, select sends an option's value
<textarea> has no value attribute. The text between the opening tag and </textarea> is its initial value. The parser removes only the first newline right after the start tag and keeps every other space and indent in the value, so write an empty textarea as <textarea></textarea> on one line. The closing tag is mandatory too: leave it out and all the HTML that follows ends up inside the box as text. rows and cols set the visible size, and maxlength caps the character count.
<select> submits the chosen <option>'s value attribute paired with the select's name. If an option has no value, its visible text is sent instead. Separating the two is useful: the screen shows readable text like "Web Design" while the server receives a stable code like web, and you can reword the label later without touching stored data.
If no option is marked selected, a single select starts on the first option. To require a deliberate choice, make the first option <option value="">Choose a city</option> and add required to the select. The browser treats that empty value as valueMissing and blocks the submit. With the multiple attribute, several options can be chosen, and each one sends its own name=value pair.
How many options you have decides which control fits. A dropdown saves space, but its options stay hidden until it is opened, so with only a few choices radio buttons are faster: the user compares everything at a glance and picks with one click. With dozens of options a select keeps the page tidy, and keyboard users can jump by typing the first letter of an option.
| Situation | Good choice |
|---|---|
| 2-5 options that should all be visible | Radio group |
| Many options (cities, countries) | <select> |
| Free-form answer | <textarea> or a text input |
- Textarea: content between tags
- Select: find the chosen option
- Use its value, else its text
- Send it as name=value
Always keep what the user sees (labels, option text) apart from what the server gets (name, value).
General pattern
<label for="text-id">Label</label>
<textarea id="text-id" name="field" rows="4" maxlength="500"></textarea>
<label for="choice-id">Label</label>
<select id="choice-id" name="choice" required>
<option value="">Choose one</option>
<option value="code">Readable text</option>
</select>Both controls link to a label through for/id and use name as the submitted key. A value="" option plus required creates a "not chosen yet" state.
Example: a message box and a service dropdown
Both controls here are tied to visible labels. Notice that the select has no placeholder option yet, so an untouched form sends service=web; you will fix that in the challenge. Try resizing the message box by dragging its corner as well.
<label for="message">Message</label>
<textarea id="message" name="message" rows="5" placeholder="Write your message..."></textarea>
<label for="service">Choose service</label>
<select id="service" name="service">
<option value="web">Web Design</option>
<option value="video">Video Editing</option>
<option value="ai">AI Automation</option>
</select>Code breakdown
- Textarea
<textarea id="message" name="message" rows="5" placeholder="Write your message..."></textarea>rows="5" makes the box five lines tall. The opening and closing tags touch, so the initial value is truly empty and the placeholder shows.
- Label link
<label for="message">Message</label>for="message" matches the textarea's id, so clicking the label puts the cursor in the box and screen readers announce "Message".
- Select
<select id="service" name="service">name="service" is the submitted key. No option is marked selected, so the browser starts on the first one.
- Option value
<option value="web">Web Design</option>The user sees "Web Design" while the server receives service=web: the value is the code, the text is for people.
A five-row text box with the grey placeholder "Write your message..." sits next to the "Message" label, followed by a "Choose service" label and a dropdown showing "Web Design". Opening the dropdown shows three options.optgroup and multiple
When the list grows, <optgroup label="..."> groups the options, and the group label itself cannot be chosen. multiple lets users pick several with Ctrl-click (Cmd-click on a Mac), but many people do not know that trick, so a checkbox group is clearer when there are only a few choices.
<label for="courses">Courses (hold Ctrl or Cmd to pick several)</label>
<select id="courses" name="courses" multiple size="5">
<optgroup label="Frontend">
<option value="html" selected>HTML</option>
<option value="css">CSS</option>
</optgroup>
<optgroup label="Backend">
<option value="py" selected>Python</option>
<option value="sql">SQL</option>
</optgroup>
</select>
<!-- Submits: courses=html&courses=py -->In real projects
Where this shows up in real projects
Every contact form, support ticket and product review uses a textarea. Teams match maxlength to the database column size and check the length again on the server, so an oversized text sent straight to the API cannot get in either. Testing with emoji, Myanmar script and blank lines is a routine QA step.
Selects keep analytics clean. Ask "how did you hear about us?" in a text box and you get "FB", "facebook" and "Face book"; ask with a select and you get the single value facebook. Without a placeholder option and required, reports show a suspicious spike for whichever option comes first, so reviewers look for exactly that.
Keeping option values as codes also matters on translated sites. The Myanmar page may show different option text from the English page, yet both submit the same value web, so one piece of server code handles both languages.
Common mistakes
Common mistakes
1. Pre-filling a textarea with a value attribute
<textarea value="Hello"></textarea> shows an empty box, because textarea ignores a value attribute. Put the initial text between the tags: <textarea>Hello</textarea>.
2. Writing a textarea as self-closing
In <textarea name="note" /> HTML ignores the slash, so the textarea never closes. Every label, button and paragraph after it shows up as text inside the box until a </textarea> appears.
3. A required select without a placeholder option
If the first option is a real value, it is always selected, so required never blocks anything. required only works once the first option is a value="" "Choose..." option.
4. Trusting maxlength as a security limit
maxlength only limits what a user can type. A script or a hand-made request can still send thousands of characters, so the server has to check the length again.
Best practices
Best practices
- State the character limit in the textarea's label or a hint below it, so users are not cut off mid-sentence.
- Keep option values as short lowercase codes and write the option text for humans.
- With fewer than about five options, consider a radio group before reaching for a dropdown.
Mini challenge
Mini challenge: a workshop feedback form
Write the feedback form sent after a workshop. Block the submit until a rating is chosen, and limit the comment length.
- A rating select whose first option is a value="" placeholder, with required on the select
- Rating option values 1-5, with visible text like "5 - Excellent"
- A topic select with two optgroups
- A labelled comment textarea with rows="6" and maxlength="300"
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Workshop feedback</title>
</head>
<body>
<form action="/feedback" method="post">
<!-- TODO: label + required rating select, first option value="" -->
<!-- TODO: label + topic select with two optgroups -->
<!-- TODO: label + comment textarea, 6 rows, at most 300 characters -->
<!-- TODO: submit button -->
</form>
</body>
</html>Expected: The rating dropdown shows "Choose a rating", and pressing Send without choosing makes the browser point at it and ask for a selection. Choosing "4 - Good" submits rating=4.
Show hint
required goes on the select, not on the placeholder option. Write the textarea as <textarea ...></textarea> with nothing between the tags.
Show solution
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Workshop feedback</title>
</head>
<body>
<form action="/feedback" method="post">
<p>
<label for="rating">Overall rating</label>
<select id="rating" name="rating" required>
<option value="">Choose a rating</option>
<option value="5">5 - Excellent</option>
<option value="4">4 - Good</option>
<option value="3">3 - Okay</option>
<option value="2">2 - Poor</option>
<option value="1">1 - Very poor</option>
</select>
</p>
<p>
<label for="topic">Favourite topic</label>
<select id="topic" name="topic">
<optgroup label="Morning">
<option value="forms">Forms</option>
<option value="tables">Tables</option>
</optgroup>
<optgroup label="Afternoon">
<option value="semantics">Semantic HTML</option>
<option value="a11y">Accessibility</option>
</optgroup>
</select>
</p>
<p>
<label for="comment">What should we improve?</label>
<textarea id="comment" name="comment" rows="6" maxlength="300"></textarea>
</p>
<button type="submit">Send</button>
</form>
</body>
</html>Quick quiz 1 / 3
Quick quiz 2 / 3
Quick quiz 3 / 3
What to remember
- A <textarea>'s initial value is the content between its tags, and the closing tag is required.
- A <select> sends the chosen option's value (or its text) under the select's name.
- A single select defaults to its first option, so pair a value="" placeholder option with required.
- Give both controls a visible label; a placeholder is not a label.
HTML Living Standard — Forms — WHATWG