Lesson 3 of 9
Advanced Form Elements
Explore advanced form elements - datalist for auto-suggestions, output for calculated values, meter and progress for visual indicators, and building multi-step forms with fieldsets.
Specialized Form Elements
- <datalist> - Provides auto-complete suggestions for an input. Attach via list='id'. Users can still type custom values
- <output> - Displays calculated results. Semantically marks a value computed from other inputs. Use with oninput event
- <meter> - Displays a scalar value within a range (disk usage, grades). Not for progress - use <progress> instead
- <progress> - Shows task completion. value/max attributes. Indeterminate without value attribute (loading spinner)
- <optgroup> - Groups options in a <select> dropdown. label attribute names the group. Cannot be nested
- contenteditable - Makes any HTML element editable. Useful for rich text editors. Not a form element but often used in forms
Pro Tip
Use the HTML5 Constraint Validation API before building custom validation from scratch. Methods like input.checkValidity(), input.setCustomValidity('Error message'), and CSS pseudo-classes :valid/:invalid/:user-invalid give you powerful validation with zero JavaScript libraries.
Using the right input type displays tailored keyboards on touch devices
Advanced Elements Code
<!-- Datalist auto-complete -->
<label for="framework">Favorite Framework</label>
<input type="text" id="framework" list="frameworks" placeholder="Start typing...">
<datalist id="frameworks">
<option value="React">
<option value="Vue">
<option value="Angular">
<option value="Svelte">
<option value="Next.js">
</datalist>
<!-- Output for calculations -->
<form oninput="result.value = parseInt(a.value) + parseInt(b.value)">
<input type="number" id="a" value="10"> +
<input type="number" id="b" value="20"> =
<output name="result" for="a b">30</output>
</form>
<!-- Progress bar -->
<label for="upload">Upload Progress:</label>
<progress id="upload" value="65" max="100">65%</progress>
<!-- Meter gauge -->
<label for="disk">Disk Usage:</label>
<meter id="disk" value="0.7" min="0" max="1"
low="0.3" high="0.7" optimum="0.5">70%</meter>Quick Quiz: Advanced Form Elements
Key Takeaways
- Explore advanced form elements - datalist for auto-suggestions, output for calculated values, meter and progress for visual indicators, and building multi-step forms with fieldsets.
- <datalist> - Provides auto-complete suggestions for an input. Attach via list='id'. Users can still type custom values
- <output> - Displays calculated results. Semantically marks a value computed from other inputs. Use with oninput event
- <meter> - Displays a scalar value within a range (disk usage, grades). Not for progress - use <progress> instead
Finished this lesson?