HTML - Select Element

1 - About

select is an HTML element that creates a drop-down list used in a form

3 - Structure

Inside a select, you may find:

  • an optgroup [optional] that group
    • option elements that defines the values.

4 - Example

4.1 - Option

Only with option has children.

For example, this HTML creates a drop-down list of colors:


<select>
  <option value="blue">Blue</option>
  <option value="yellow">yellow</option>
  <option value="red">Red</option>
  <option selected value="green">Green</option>
</select>

4.2 - OptGroup

HTML - Optgroup element (Group of Option)


<label for="country">Choose a country:</label>
<select id="country">
    <optgroup label="Europa">
        <option>England</option>
        <option>Germany</option>
        <option>Netherland</option>
    </optgroup>
    <optgroup label="Africa">
        <option>Marroco</option>
        <option>Algeria</option>
        <option>Tunisia</option>
    </optgroup>
</select>

5 - Library

6 - Attribute

6.1 - Multiple

Boolean attribute indicates that multiple options can be selected in the list by holding the ctrl key (Default: false)


<select multiple=true>
  <option value="blue">Blue</option>
  <option value="yellow">yellow</option>
  <option value="red">Red</option>
  <option selected value="green">Green</option>
</select>

6.2 - Form

If not used in a form element, you can set the form attribute with the id of the form to associate it with the select.

7 - Documentation / Reference


Data Science
Data Analysis
Statistics
Data Science
Linear Algebra Mathematics
Trigonometry

Powered by ComboStrap