Menu
Coddy logo textTech

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 icon

Challenge

Easy

Create an HTML document that includes a form with a dropdown menu. The form should have the following elements:

  1. A dropdown with the name "fruits".
  2. 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 menu
  • name: Identifies the dropdown when form is submitted
  • <option>: Defines each dropdown item
  • value: 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>
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals