HTML Introduction | HTML Forms | HTML Select Input

Select input: the select element

The select element provides several options as a drop-down list and lets the user choose only one option from them. It is also called a combo box or pull-down menu.

The option element specifies each selectable option in the drop-down list.

좋아하는 과일은?
<select name="fruit">
  <option value="apple">사과</option>
  <option value="banana" selected>바나나</option>
  <option value="orange">오렌지</option>
  <option value="strawberry">딸기</option>
</select>

Run code

You can use the selected attribute to specify the option that is selected in advance when the drop-down list is first displayed.

option element

The option element is an item that can be selected from multiple items.

The value attribute used in the option element is slightly different from the value attribute in a text field. In a text field, entering a value in the value attribute sets the default value, but in the <option> tag, it specifies the value sent when that option is selected.

optgroup element

The optgroup element is a tag newly created in HTML 4 that can group options. It is supported by most web browsers.

당신의 취미는?
<select name="hobby">
  <option value="독서">독서</option>
  <optgroup label="스포츠">
    <option value="야구">야구</option>
    <option value="축구">축구</option>
  </optgroup>
  <option value="음악감상">음악감상</option>
</select>

Run code