Dropdowns
Part of the Fundamentals section of Coddy's HTML journey — lesson 43 of 60.
In HTML, a dropdown menu is a list of items that appears when a user clicks on or hovers over an element. Dropdowns are commonly used to present a list of choices in a compact way. To create a dropdown, you use the <select> tag along with <option> tags for the individual items.
Here's the basic syntax for creating a dropdown in HTML:
<select name="dropdown">
<option value="value1">Option 1</option>
<option value="value2">Option 2</option>
<option value="value3">Option 3</option>
</select><select>: The tag that defines the dropdown menu.
name: An attribute that gives the dropdown a name, which is used to identify the selected value when the form is submitted.
<option>: A tag that defines an item in the dropdown list.
value: An attribute that specifies the value associated with the option. This value is sent to the server when the form is submitted.
Option text: The visible text that appears in the dropdown list for each option.
Here's an example of how to create a dropdown with three options:
<select name="colors">
<option value="red">Red</option>
<option value="green">Green</option>
<option value="blue">Blue</option>
</select>In this example, we have a dropdown with the name "colors" and three options: Red, Green, and Blue.
Challenge
EasyCreate an HTML document that includes a form with a dropdown menu. The form should have the following elements:
- A dropdown with the name "fruits".
- The dropdown should have four options with the following values and text:
- Value: "apple", Text: "Apple"
- Value: "banana", Text: "Banana"
- Value: "orange", Text: "Orange"
- Value: "grape", Text: "Grape"
Cheat sheet
To create a dropdown menu in HTML, use the <select> tag with <option> tags for individual items:
<select name="dropdown">
<option value="value1">Option 1</option>
<option value="value2">Option 2</option>
<option value="value3">Option 3</option>
</select><select>: Defines the dropdown menuname: Identifies the dropdown when form is submitted<option>: Defines each dropdown itemvalue: The value sent to server when option is selected- Option text: The visible text displayed in the dropdown
Example dropdown with color options:
<select name="colors">
<option value="red">Red</option>
<option value="green">Green</option>
<option value="blue">Blue</option>
</select>Try it yourself
<!DOCTYPE html>
<html>
<body>
<!-- Write code here -->
</body>
</html>This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
2Text and Formatting
HeadingsParagraphsLine BreaksBold and Italic TextBold and Italic AgainRecap - Formatting8Forms and Inputs Part 1
Form BasicsText InputsInput AttributesPassword FieldLabels for InputsRecap - Basic Form11Event Registration Page
Project OverviewHeader Section9Forms and Inputs Part 2
Radio ButtonsCheckboxesDropdownsButtonsButtons in FormsRecap - Forms #1Recap - Forms #2