Welcome to Day 13 of the 180 Days of Frontend Development Challenge. Today we'll dive deep into professional implementation of advanced form controls. For comprehensive form techniques, see the Learn Frontend Development in 180 Days ebook.
1. Checkboxes: Multiple Selections
Basic Implementation
<fieldset>
<legend>Select Your Interests</legend>
<div class="form-control">
<input type="checkbox" id="news" name="interests" value="news">
<label for="news">Newsletters</label>
</div>
<div class="form-control">
<input type="checkbox" id="updates" name="interests" value="updates" checked>
<label for="updates">Product Updates</label>
</div>
</fieldset>
Key Attributes:
-
checked
: Pre-selects the option -
value
: Data sent when form is submitted -
name
: Groups related checkboxes
Professional Pattern:
Wrap each checkbox in <div class="form-control">
for consistent styling
2. Radio Buttons: Single Selection
Proper Grouping
<fieldset>
<legend>Payment Method</legend>
<div class="form-control">
<input type="radio" id="credit" name="payment" value="credit" required>
<label for="credit">Credit Card</label>
</div>
<div class="form-control">
<input type="radio" id="paypal" name="payment" value="paypal">
<label for="paypal">PayPal</label>
</div>
</fieldset>
Critical Notes:
- All radios in a group must share the same
name
- Include
required
when selection is mandatory - Use
fieldset
andlegend
for accessibility
3. Select Dropdowns
Basic Select
<label for="country">Country:</label>
<select id="country" name="country" required>
<option value="">-- Select Country --</option>
<option value="us">United States</option>
<option value="ca">Canada</option>
<option value="uk">United Kingdom</option>
</select>
Advanced Select Features
<select id="skills" name="skills" multiple size="4">
<optgroup label="Frontend">
<option value="html">HTML</option>
<option value="css">CSS</option>
</optgroup>
<optgroup label="Backend">
<option value="node">Node.js</option>
</optgroup>
</select>
Attributes to Know:
-
multiple
: Allows multi-select -
size
: Visible rows -
optgroup
: Groups related options
4. Buttons: Beyond Basic Submission
Button Types
<!-- Submit Button -->
<button type="submit">Process Order</button>
<!-- Reset Button -->
<button type="reset">Clear Form</button>
<!-- Generic Button -->
<button type="button" id="calculate">Calculate</button>
Professional Button Patterns
<button type="submit" class="btn-primary">
<svg aria-hidden="true" width="16" height="16"><!-- icon --></svg>
<span>Place Order</span>
</button>
<button type="button" disabled aria-busy="true">
Processing...
</button>
Accessibility Features:
- Always specify
type
(submit/reset/button) - Use ARIA attributes when needed
- Include state indicators (disabled/loading)
Complete Example: Survey Form
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Customer Satisfaction Survey</title>
<style>
:root {
--primary: #0066cc;
--border: 1px solid #ddd;
}
form {
max-width: 600px;
margin: 2rem auto;
padding: 2rem;
border: var(--border);
border-radius: 8px;
}
fieldset {
border: var(--border);
border-radius: 4px;
padding: 1.5rem;
margin-bottom: 1.5rem;
}
legend {
padding: 0 0.5rem;
font-weight: bold;
}
.form-control {
margin: 1rem 0;
}
button {
background: var(--primary);
color: white;
padding: 0.75rem 1.5rem;
border: none;
border-radius: 4px;
cursor: pointer;
}
button:disabled {
opacity: 0.6;
}
</style>
</head>
<body>
<form id="survey">
<fieldset>
<legend>Customer Information</legend>
<div class="form-control">
<label for="email">Email*</label>
<input type="email" id="email" name="email" required>
</div>
<div class="form-control">
<label>Age Group*</label>
<div>
<input type="radio" id="age1" name="age" value="18-25" required>
<label for="age1">18-25</label>
</div>
<div>
<input type="radio" id="age2" name="age" value="26-35">
<label for="age2">26-35</label>
</div>
</div>
</fieldset>
<fieldset>
<legend>Survey Questions</legend>
<div class="form-control">
<label for="satisfaction">Overall Satisfaction*</label>
<select id="satisfaction" name="satisfaction" required>
<option value="">-- Select Rating --</option>
<option value="5">Very Satisfied</option>
<option value="4">Satisfied</option>
<option value="3">Neutral</option>
<option value="2">Dissatisfied</option>
<option value="1">Very Dissatisfied</option>
</select>
</div>
<div class="form-control">
<label>Which features do you use?*</label>
<div>
<input type="checkbox" id="feat1" name="features" value="dashboard" required>
<label for="feat1">Dashboard</label>
</div>
<div>
<input type="checkbox" id="feat2" name="features" value="reports">
<label for="feat2">Reports</label>
</div>
</div>
</fieldset>
<div class="form-control">
<button type="submit">Submit Survey</button>
<button type="reset">Start Over</button>
</div>
</form>
</body>
</html>
Professional Practices
-
Accessibility Must-Haves
- Always associate labels with inputs
- Use
fieldset
for related controls - Implement keyboard navigation
- Include ARIA attributes when needed
Validation Patterns
<!-- Require at least one checkbox -->
<input type="checkbox" name="terms" required>
<!-- Custom radio validation -->
<input type="radio" name="shipping" required
oninvalid="this.setCustomValidity('Please select shipping option')">
-
UX Considerations
- Group related options visually
- Order selections logically
- Provide clear selection feedback
- Style focus states for keyboard users
Exercises
-
Build a Pizza Order Form with:
- Radio buttons for size (S/M/L)
- Checkboxes for toppings
- Select dropdown for delivery time
- Custom styled submit button
-
Create a Multi-Step Registration with:
- Radio button for account type
- Checkbox for terms acceptance
- Disabled submit button until valid
Fix These Control Errors:
<div>
<p>Choose color:</p>
<input name="color" type="radio" value="red">
<input name="color" type="radio" value="blue">
</div>
What's Next?
Tomorrow (Day 14) covers Form Validation Techniques - client-side validation, error messaging, and accessibility patterns. For advanced form control techniques including custom dropdowns and toggle switches, see Chapter 9 in the Learn Frontend Development in 180 Days ebook.
Pro Tip: Test all form controls using only keyboard navigation to ensure full accessibility compliance.
Top comments (2)
Really appreciate how much you emphasized accessibility and real-world patterns here
Do you have any tips for handling custom-styled checkboxes or selects that keep accessibility intact?
Check my eBook