HTML select

<select> tag in HTML

The <select> tag is used to create an drop down list box, that allows users to pick one among a number of given options.

The options in a <select> list are provided using th<option> tag.

Example

Try Yourself

attributes in <select> tag

<select> tag has attributes, we are going to see some of the important ones.

  • multiple
  • size

multiple attribute in <select> tag

It allows user to select more than one options from the list.

Example

Try Yourself

size attribute in <select> tag

It is used to display specified number of items.

Example

Try Yourself

<option> tag in HTML

The <option> tag represents an option in a <select> tag or in a <datalist> tag.

The behavior of this element varies slightly according to, in which of these two elements it's present on.


attributes of <option> tag


selected attribute in <option> tag

selected attribute is used to set an option as a default value in the dropdown list box.

Example

Try Yourself

In the above example Mango is selected in first load.


disabled attribute in <option> tag

This attribute is used to disable the specified list in the dropdown list box.

Example

Try Yourself

In the above example, you can not able to select the Mango list.


value attribute in <option> tag

This attribute is used to assign a value to each and every list items.

This attribute is accessed from javascript code.

Example 1

Try Yourself

Example 2 - Access the dropdown value using javascript

Try Yourself