Creating sub options in a html dropdown <select>

Sometimes it is good to create sub options of an HTML drop down list <select></select>

For that purpose, <optgroup></optgroup> tags are used. Here is an example:

<form id="form2" name="form2" method="post" action="">

<select id="ddlcountries" name="ddlcountries">
    <option>--Select City--</option>
    <optgroup label="America">
        <option>United States</option>
    <optgroup label="Asia">
    <optgroup label="Africa">
        <option>South Africa</option>


Add a Comment

Your email address will not be published. Required fields are marked *