📖 Scenario: You are building a simple web form where users can pick their favorite fruit from a list.
🎯 Goal: Create a select dropdown menu with fruit options so users can choose one fruit.
📋 What You'll Learn
Use a <select> element with the id fruit-select.
Add exactly three <option> elements inside the select.
The options must be Apple, Banana, and Cherry with values apple, banana, and cherry respectively.
Include a label for the select with the text Choose a fruit: and link it properly using the for attribute.
Ensure the dropdown is accessible and uses semantic HTML.
💡 Why This Matters
🌍 Real World
Select dropdowns are common in web forms for choosing options like countries, fruits, or preferences.
💼 Career
Understanding how to build accessible and semantic form controls is essential for front-end web development jobs.
Progress0 / 4 steps
1
Create the HTML skeleton with a label
Write the basic HTML structure with a <label> element that has the text Choose a fruit: and the attribute for="fruit-select".
HTML
Hint
Use a <label> tag with the for attribute matching the select's id.
2
Add the select element with id
Add a <select> element with the id fruit-select right after the label.
HTML
Hint
The id attribute connects the select to the label.
3
Add three option elements inside the select
Inside the <select id="fruit-select">, add three <option> elements with these exact values and texts: value="apple" with text Apple, value="banana" with text Banana, and value="cherry" with text Cherry.
HTML
Hint
Each option needs a value attribute and visible text.
4
Wrap the label and select in a form element
Wrap the existing <label> and <select> elements inside a <form> element to complete the structure.
HTML
Hint
A form groups input elements and is good practice for accessibility.
Practice
(1/5)
1. What does the <select> tag do in HTML?
easy
A. Creates a dropdown list for users to choose from
B. Creates a text input box
C. Creates a button
D. Creates a paragraph
Solution
Step 1: Understand the purpose of the <select> tag
The <select> tag is designed to create a dropdown list where users can pick one option from many.
Step 2: Compare with other tags
Other tags like <input> create text boxes, <button> creates buttons, and <p> creates paragraphs, so they do not create dropdowns.
Final Answer:
Creates a dropdown list for users to choose from -> Option A
Quick Check:
<select> = dropdown list [OK]
Hint: Remember: <select> always means dropdown [OK]
Common Mistakes:
Confusing <select> with <input>
Thinking <select> creates buttons
Mixing <select> with paragraph tags
2. Which of the following is the correct way to add options inside a dropdown?
easy
A. <button>Choice 1</button>
B. <select>Choice 1</select>
C. <input>Choice 1</input>
D. <option>Choice 1</option>
Solution
Step 1: Identify the tag used for dropdown options
The <option> tag is used inside <select> to list choices.
Step 2: Check other tags
<select> is for the dropdown container, <input> and <button> are unrelated to dropdown options.
Final Answer:
<option>Choice 1</option> -> Option D
Quick Check:
Options inside dropdown = <option> [OK]
Hint: Options inside dropdown use <option> tags [OK]
Common Mistakes:
Putting options directly inside <select> without <option>
Using <input> or <button> instead of <option>
Closing with which is invalid
3. What will the following HTML render in the browser?
The last <option> for Blue is missing its closing </option> tag, which is required for valid HTML.
Step 2: Verify other parts
The name attribute is valid on <select>, options can have value attributes, and multiple options are allowed.
Final Answer:
Missing closing tag for the last <option> -> Option C
Quick Check:
All <option> tags must be closed [OK]
Hint: Always close each <option> tag properly [OK]
Common Mistakes:
Forgetting to close <option> tags
Thinking name attribute is invalid on <select>
Believing options can't have values
5. You want to create a dropdown for selecting a country with these requirements: - The dropdown must have a label for accessibility. - The default visible option should say 'Select a country' and not be selectable. - Options: USA, Canada, Mexico. Which code snippet meets all these requirements?
hard
A. <select name="country">
<option>Select a country</option>
<option value="usa">USA</option>
<option value="canada">Canada</option>
<option value="mexico">Mexico</option>
</select>
B. <label for="country">Country:</label>
<select id="country" name="country">
<option value="" disabled selected>Select a country</option>
<option value="usa">USA</option>
<option value="canada">Canada</option>
<option value="mexico">Mexico</option>
</select>
C. <label>Country</label>
<select id="country">
<option value="" selected>Select a country</option>
<option value="usa">USA</option>
<option value="canada">Canada</option>
<option value="mexico">Mexico</option>
</select>
D. <label for="country">Country:</label>
<select id="country" name="country">
<option value="">Select a country</option>
<option value="usa">USA</option>
<option value="canada">Canada</option>
<option value="mexico">Mexico</option>
</select>
Solution
Step 1: Check for label linked to select
<label for="country">Country:</label>
<select id="country" name="country">
<option value="" disabled selected>Select a country</option>
<option value="usa">USA</option>
<option value="canada">Canada</option>
<option value="mexico">Mexico</option>
</select> uses <label for="country"> and <select id="country">, linking label and dropdown for accessibility.
Step 2: Verify default option is disabled and selected
The first option in A has disabled selected attributes, so it shows as default but cannot be chosen.
Step 3: Confirm options list
Options USA, Canada, Mexico are correctly listed with values.
Final Answer:
This code snippet meets all requirements -> Option B