HTML Select, Textarea, Checkbox, and Radio
> Build dropdown menus, multi-line text fields, checkboxes, and radio groups with accessible labels.
**Cyber Code Academy · HTML Tutorial · Lesson 14 · Beginner**
## 1. Select dropdown
The select element creates a drop-down list. Each option represents one selectable value.
“`html
Select a course
HTML
CSS
JavaScript
“`
The visible text and submitted value can differ. For example, the option text JavaScript is submitted as the value javascript.
## 2. Disabled and selected options
“`html
Choose a course
HTML
CSS
“`
The empty first option acts as a prompt. Because it has an empty value, required validation will not accept it as a valid selection.
## 3. Group options with optgroup
“`html
HTML
CSS
Node.js
Python
“`
optgroup organizes related choices under a label.
## 4. Multiple selection
“`html
HTML
CSS
JavaScript
Accessibility
“`
multiple allows more than one option to be selected. The interaction varies between platforms. Explain how users can select multiple items if the interface may not be obvious.
## 5. Textarea
The textarea element provides a multi-line text control:
“`html
“`
– rows suggests the visible number of text lines.
– cols suggests the visible width in character columns.
– placeholder provides a hint.
– maxlength can limit the number of characters.
– required makes a non-empty value necessary.
Unlike input, textarea has opening and closing tags. Initial text, if needed, goes between those tags.
## 6. Radio buttons
Radio buttons allow one choice from a group:
“`html
“`
All options share the same name. Different values identify the selected choice. Use fieldset and legend to provide a group label.
## 7. Checkboxes
Checkboxes represent separate yes/no or on/off selections:
“`html
“`
The user can select several checkboxes. Unchecked checkboxes are not normally included in submitted form data.
## 8. Difference between checkbox and radio
| Checkbox | Radio |
|—|—|
| Independent choices | One choice in a group |
| Multiple may be checked | One option per same-name group |
| Each option can be toggled independently | Selecting another option replaces the previous selection |
Use checkboxes when the user can choose several interests. Use radio buttons when the user must choose one mode or option.
## 9. Datalist suggestions
The datalist element can provide suggestions for a text input:
“`html
“`
Datalist is a suggestion list, not a strict dropdown restriction. Users may enter values that are not in the suggestions.
## 10. Complete course enquiry form
“`html
Course enquiry
Choose a course
HTML
CSS
“`
## 11. Common mistakes
– Forgetting the id/for relationship.
– Giving radio options different names.
– Omitting option values when submitted values need to be predictable.
– Using a placeholder instead of a label.
– Using checkboxes when only one choice is allowed.
– Forgetting to group controls with fieldset and legend when appropriate.
– Expecting datalist to restrict user input.
## 12. Practice exercises
1. Create a dropdown with HTML, CSS, JavaScript, and Python.
2. Group options into Frontend and Backend using optgroup.
3. Create a textarea for a student’s question.
4. Create a radio group for batch timing.
5. Create checkboxes for multiple technologies.
6. Add a datalist with suggested cities.
7. Test every field with the keyboard.
## 13. Knowledge check
1. What is the role of option?
2. What does optgroup do?
3. How is textarea different from input?
4. Why do radio buttons share a name?
5. How are checkbox and radio different?
6. Is datalist a strict list of allowed values?
7. What does fieldset and legend provide?
**Next lesson:** HTML Form Validation.
Want to learn this professionally?
Explore practical IT training at Cyber Code Academy.
View Academy Courses