Implementation (HTML)HTML forms - Drop-down menu

Learn about how HyperText Markup Language (HTML) tells a browser how to set out a web page.

Part ofComputing ScienceWeb design and development

HTML forms - Drop-down menu

We can also add drop-down menus to our HTML forms.

We can use the select element to implement these drop-down menus. Input choices are in “option” elements as shown in the example below.

A drop down menu of cities with the top option, Aberdeen, highlighted.

Code below:

<form>
Select city:
<select name="city">
<option value="Aberdeen">Aberdeen</option>
<option value="Dundee">Dundee</option>
<option value="Edinburgh">Edinburgh</option>
<option value="Glasgow">Glasgow</option>
<option value="Inverness">Inverness</option>
<option value="Perth">Perth</option>
<option value="Stirling">Stirling</option>
</select>
</form>

Each city has been set in the option value part of the element. The name=”city” and value attributes are not required at Higher, but they are useful to state.