Loading...
Loading...
Add dropdown menus and multi-line text inputs to your forms
Beyond , HTML offers two more essential form elements: creates a dropdown menu, and creates a multi-line text box. These handle cases where a simple text field isn't enough.
<!-- Dropdown menu -->
<label for="country">Country:</label>
<select id="country" name="country">
<option value="">Choose...</option>
<option value="us">United States</option>
<option value="ca">Canada</option>
<option value="uk">United Kingdom</option>
</select>
<!-- Multi-line text area -->
<label for="message">Message:</label>
<textarea id="message" name="message" rows="5" cols="40"
placeholder="Write your message here..."></textarea><select name="size">
<option value="small">Small ($5)</option>
<option value="medium" selected>Medium ($7)</option>
<option value="large">Large ($9)</option>
</select><textarea id="bio" name="bio" rows="4" placeholder="Tell us about yourself..."></textarea><select name="car">
<optgroup label="American">
<option value="ford">Ford</option>
<option value="gm">General Motors</option>
</optgroup>
<optgroup label="Japanese">
<option value="toyota">Toyota</option>
<option value="honda">Honda</option>
</optgroup>
</select> adds category labels to group related options in long dropdowns.
| ❌ Wrong | Why | ✅ Right |
|---|---|---|
| ` | Self-closing textarea is invalid HTML | ` |
| Matching `value` to display text on ` | Value should be a short identifier, display text can be longer | `` |
| Forgetting a default ` | First option is auto-selected — may confuse users | Add `` |
Create a form with:
<label for="color">Favorite Color:</label> <select id="color" name="color"> <option value="">Choose a color...</option> <option value="red">Red</option> <option value="blue">Blue</option> <option value="green">Green</option> </select> <label for="comments">Comments:</label> <textarea id="comments" name="comments" rows="4" placeholder="Enter your comments here..."></textarea> <button type="submit">Submit</button>