Summary -

In this topic, we described about the <select> tag along with detailed example.

Form control option selection or simply drop down list for user selection. The <select> tag used to create the drop down lost for user selection. <select> element is mostly used in conjunction with <option> element.

<select> tag contains option elements can be grouped in optgroup elements. The tag can be specified like <select value=""></select> with the options in between the opening and closing.

Syntax -

<select>.... </select>

Optional Attributes -

autofocusSpecifies the drop down list automatically get focused when page loads.HTML5 attributeautofocus
disabledSpecifies the drop-down list should be disabled.HTML5 attributeDisabled
formSpecifies the select field belongs form nameForm_id
multipleSpecifies the multiple options can be selected at onceMultiple
nameSpecifies the name of the drop down listName
requiredSpecifies the user selection is mandatory before submitting the form.HTML5 attributeRequired
sizeSpecifies the number of visible options in drop-down listNumber.

Example -

<!DOCTYPE html>
		<title>select tag example.. </title>
		Select week from the list: 
			<option value="monday">Monday</option>
			<option value="tuesday">Tuesday</option>
			<option value="wednesday">Wednesday</option>
			<option value="thursday">Thursday</option>
			<option value="friday">Friday</option>
			<option value="saturday">Saturday</option>
			<option value="sunday">Sunday</option>
Select week from the list: