Part 13: HTML Forms Advanced Controls
Senior Full-Stack Developer
The <textarea> element creates a multi-line text input field.
rows, cols, placeholderrows - Number of visible text linescols - Visible width in character columnsplaceholder - Hint text that disappears on focusmaxlength - Maximum number of characters allowedreadonly - Makes textarea non-editabledisabled - Disables the textarea<textarea
name="message"
rows="4"
cols="50"
placeholder="Enter your message here..."
maxlength="500">
Default text goes here
</textarea>
The <select> element creates a dropdown list.
<option> elementsmultiple attribute for multi-selectsize attribute controls visible rowsThe <option> element defines an option in the dropdown.
value - The value sent when form is submittedselected - Makes option selected by defaultdisabled - Makes option non-selectableThe <optgroup> groups related options.
label attribute for group name<select name="country">
<optgroup label="North America">
<option value="us">United States</option>
<option value="ca">Canada</option>
</optgroup>
<optgroup label="Europe">
<option value="uk">United Kingdom</option>
<option value="fr">France</option>
</optgroup>
</select>
name attributechecked attribute for default selection<input type="radio" name="gender" value="male"> Male
<input type="radio" name="gender" value="female" checked> Female
<input type="radio" name="gender" value="other"> Other
name or share nameschecked attribute for default selection<input type="checkbox" name="interests" value="sports"> Sports
<input type="checkbox" name="interests" value="music" checked> Music
<input type="checkbox" name="interests" value="books"> Books
Associate labels with both radio buttons and checkboxes for accessibility
Use fieldset and legend to group related controls
Use checked attribute for most likely selections
Makes form controls non-interactive and excludes them from form submission.
<input type="text" name="username" disabled>
Pre-selects radio buttons or checkboxes.
<input type="checkbox" name="newsletter" checked>
Allows multiple selections in <select> elements.
size attribute to control visible rows<select name="skills" multiple size="4">
Makes input fields non-editable but included in form submission.
<input type="text" name="user_id" readonly>
| Attribute | Appearance | Focusable | Submitted | Use Case |
|---|---|---|---|---|
disabled |
Grayed out | No | No | Conditional fields |
readonly |
Normal | Yes | Yes | Display-only data |
<!DOCTYPE html>
<html>
<head>
<title>Customer Survey</title>
</head>
<body>
<h2>Customer Satisfaction Survey</h2>
<form action="/submit-survey" method="POST">
<fieldset>
<legend>Personal Information</legend>
<label for="name">Full Name:</label>
<input type="text" id="name" name="name" required>
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
</fieldset>
<fieldset>
<legend>Product Feedback</legend>
<label>How satisfied are you?</label>
<input type="radio" name="satisfaction" value="very" required> Very Satisfied
<input type="radio" name="satisfaction" value="satisfied"> Satisfied
<input type="radio" name="satisfaction" value="neutral"> Neutral
<input type="radio" name="satisfaction" value="unsatisfied"> Unsatisfied
<label>Which features do you use? (Select all that apply)</label>
<input type="checkbox" name="features" value="dashboard"> Dashboard
<input type="checkbox" name="features" value="reports" checked> Reports
<input type="checkbox" name="features" value="analytics"> Analytics
</fieldset>
<fieldset>
<legend>Additional Feedback</legend>
<label for="comments">Comments:</label>
<textarea id="comments" name="comments"
rows="4" cols="50"
placeholder="Please share any additional feedback..."></textarea>
<label for="referral">How did you hear about us?</label>
<select id="referral" name="referral">
<option value="">Please select...</option>
<option value="search">Search Engine</option>
<option value="social">Social Media</option>
<option value="friend">Friend Referral</option>
<option value="ad">Advertisement</option>
</select>
</fieldset>
<button type="submit">Submit Survey</button>
</form>
</body>
</html>
Groups related form controls with descriptive labels
Mutually exclusive selection for satisfaction rating
Multiple selection for feature usage
Multi-line input for detailed comments
Single selection from predefined options
Always use <label> elements associated with form controls using for and id
Group related form controls with <fieldset> and provide context with <legend>
Ensure form elements follow a logical sequence for keyboard navigation
Provide helpful placeholder text and instructions for complex inputs
Use checked and selected attributes for common choices
Ensure forms work well on touch devices with appropriate input types
Use built-in validation attributes like required, pattern, min, max
Provide specific, helpful error messages near the problematic field
Ensure forms work without JavaScript, then enhance with it
You've mastered Advanced HTML Form Controls
Multi-line text input fields
Dropdown menus and lists
Single selection controls
Multiple selection controls
Disabled, checked, multiple
Practical implementation
Build a comprehensive job application form with:
Next: Learn about HTML5 input types, validation, and new form attributes