HTML <optgroup> tag

HTML <optgroup> tag : Definition


• The HTML <optgroup> tag is used to group related options in a <select> element(dropdown list).

• These dropdown values are specified by a numbers of <option> tags and grouped using the <optgroup> tag.



Html <optgroup> tag example

<!DOCTYPE html>
<html>
<body>
  <label for="tutorial_choice">Course: </label>
  <select id="tutorial_choice">
    <optgroup label="BE/ B.TECH">
      <option value="html">CSE</option>
      <option value="css">IT</option>
      <option value="css">EEE</option>
      <option value="css">ECE</option>
      <option value="css">MECH</option>
      <option value="css">OTHERS</option>
    </optgroup>





    <optgroup label="DIPLOMA">
      <option value="html">AUTO ENGG</option>
      <option value="html">CSE</option>
      <option value="css">IT</option>
      <option value="css">EEE</option>
      <option value="css">ECE</option>
      <option value="css">OTHERS</option>
    </optgroup>
  </select>
</body>
</html>

Output :