HTML Form Elements: Types, Uses, and Examples
What is HTML Form Elements: Types, Uses, and Examples? Beyond standard tags, HTML provides specialized form elements: (multi-line text editing), and (dropdown select menus), (grouped dropdown options), (intera...
What are the non-input form elements (<textarea>, <select>, <button>, <fieldset>, <datalist>)?
Explanation & In-Depth Details
- Used for comments, message bodies, and reviews.
- Defined with <textarea name="comment" rows="4" cols="50"></textarea>.
- Unlike <input>, default text is placed between the opening and closing tags, not in a value attribute.
2) Dropdown Menus with <select> & <option>:
- <select>: The dropdown wrapper element.
- <option>: Individual selectable choices inside the dropdown.
- <optgroup>: Groups related options under non-selectable category labels (e.g. Asian Countries, European Countries).
3) Autocomplete with <datalist>:
- Couples with an <input list="browsers"> to provide autocomplete search suggestions as the user types, while still allowing custom text entries.
4) Grouping Controls with <fieldset> & <legend>:
- <fieldset>: Draws a visual and semantic border around related controls (e.g. Shipping Address vs Billing Address).
- <legend>: Serves as the caption for the fieldset, which screen readers announce when focusing any input inside.
5) The <button> Element:
- Superior to <input type="button"> because it can contain HTML tags, SVG icons, and images inside its label.
Code Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Specialized Form Controls</title>
</head>
<body>
<h2>Advanced Form Elements Showcase</h2>
<form>
<!-- Fieldset with Legend -->
<fieldset style="border-radius: 8px; margin-bottom: 20px;">
<legend><strong>Shipping Preferences</strong></legend>
<!-- Select Dropdown with Optgroups -->
<label for="shippingSpeed">Delivery Speed:</label>
<select id="shippingSpeed" name="speed">
<optgroup label="Standard Options">
<option value="ground">Ground Courier (3-5 Days)</option>
<option value="postal">Postal Mail (5-7 Days)</option>
</optgroup>
<optgroup label="Express Options">
<option value="next_day">Next Day Air ($19.99)</option>
<option value="saturday">Saturday Delivery ($29.99)</option>
</optgroup>
</select>
</fieldset>
<!-- Datalist Autocomplete -->
<label for="citySearch">Destination City:</label>
<input list="cities" id="citySearch" name="city" placeholder="Type city name...">
<datalist id="cities">
<option value="New York">
<option value="London">
<option value="San Francisco">
<option value="Tokyo">
</datalist>
<!-- Multi-Line Textarea -->
<p>
<label for="specialNotes">Delivery Instructions:</label><br>
<textarea id="specialNotes" name="notes" rows="4" style="width: 100%; max-width: 400px;"></textarea>
</p>
<!-- Rich Button with Icon -->
<button type="submit" style="padding: 10px 18px; cursor: pointer;">
Confirm & Proceed →
</button>
</form>
</body>
</html>Interview Question & Tips
A1: The <button> tag has closing tags, allowing developers to embed complex child elements (SVG icons, badges, spinners) inside the button. <input> is a void element and only supports plain text via its 'value' attribute.
Q2: Why should you always specify type="button" on non-submitting buttons?
A2: By W3C specification, the default type of a <button> inside a form is 'type="submit"'. If you omit the type attribute, clicking the button will inadvertently submit the form and refresh the page.
Q3: How does <datalist> differ from a <select> element?
A3: A <select> dropdown forces the user to choose exclusively from predefined options. A <datalist> provides helpful autocomplete suggestions while still allowing users to type any custom free-form text.
Best Practices
This study reference for HTML Form Elements: Types, Uses, and Examples is curated and verified against recognized curriculum benchmarks, peer-reviewed textbooks, and official technical documentation: