Computer >> Computer tutorials >  >> Programming >> HTML

Create a selectable list in HTML


Use the <select> tag to create a selectable list. The HTML <select> tag is used within a form for defining a select list.

The HTML <select> tag also supports the following additional attributes −

Attribute
Value
Description
autofocusCreate a selectable list in HTML
autofocus
Specifies that on page load the drop-down list should automatically get focus.
disabled
Disabled
Disables the input control. The button won't accept changes from the user. It also cannot receive focus and will be skipped when tabbing.
formCreate a selectable list in HTML
form_id
Specifies one or more forms.
multiple
Multiple
When set, it specifies that multiple items can be selected at a time
name
Name
Assigns a name to the input control.
requiredCreate a selectable list in HTML
Required
Before submitting the form the user is required to select a value, else it won't proceed ahead.
size
Number
Defines the number of visible items in the drop-down list

Example

You can try to run the following code to create a selectable list in HTML −

<!DOCTYPE html>
<html>
   <head>
      <title>HTML select Tag</title>
   </head>
   <body>
      <form action = "/cgi-bin/dropdown.cgi" method = "post">
         <select name = "dropdown">
            <option value = "Data Structures" selected>Data Structures</option>
            <option value = "Data Mining">Data Mining</option>
         </select>
         <input type = "submit" value = "Submit" />
      </form>
   </body>
</html>