SELECT tag in HTML

26
Mr. Coder | 01-Oct-2024
Introduction

The select tag is more often used to collect the input from the user where the input should be from some particular list or options.

The syntax for <select> tag is as follows

<select>
     <option>Item1</option>
     <option>Item2</option>
     <option>Item3</option>
</select>

Output

<select> tag with <optgroup>
optgroup is used to define the groups between the list of options displayed  in the <select> tag.

The syntax for <select> tag with <optgroup>

<select>
     <optgroup label="Airbus">
          <option>320</option>
          <option>330</option>
          <option>380</option>
     </optgroup>
     <optgroup label="Boeing">
          <option>747</option>
          <option>777</option>
          <option>737</option>
     </optgroup>
</select>

Output :

To provide some particular value we provide value attribute to the <option> tag as shown below
<option value="747">Boeing 747</option>

logo
facebook youtube