Drop Down in HTML

 To create a drop down list with multiple options, html provides <select> tag.

Example:
   create a drop down list with multiple options
       <label for="language">Choose a language</label>
       <select id="language">
            <option value="java">JAVA</option>
            <option value="cpp">C++</option>
            <option value="python">PYTHON</option>
            <option value="other">OTHERS</option>
       </select>

 Output:
        

<select> tag comes with some useful attributes which are as follows
  •    autofocus : it indicates that drop-down list will automatically gets focus when page will load
  •    disabled : used to disable the drop-down list
  •    multiple : specifies that you can select multiple options from the drop-down menu
  •    name : defines the name of the drop-down list
  •    required : specifies that user must select a value 
  •    size : used to define the number of options to be shown in a drop-down list
Let say we want to show 2 values in drop-down list then: use size attribute as
            <label for="language">Choose a language</label>
           <select id="language" size = "2">
                <option value="java">JAVA</option>
                <option value="cpp">C++</option>
                <option value="python">PYTHON</option>
                <option value="other">OTHERS</option>
           </select>
    
Output:
       

Continue Learning: Ordered And Unordered List



Comments

Popular Posts