Select Tag in HTML5

Introduction 

 
The select element creates a drop-down list. This element is used in conjunction with the <option> element to produce a list of options that the user can choose from. The <select> tag is supported in all major browsers. You can use <optgroup> tag within <select> tag for grouping option.
 
Syntax
 
 <select>
<option>Text</option>
<option>Text</option>
</select >
 

Attributes

 
HTML tags can contain one or more attributes. Attributes are added to a tag to provide the browser with more information about how the tag should appear or behave. Attributes consist of a name and a value separated by an equals (=) sign, with the value surrounded by double-quotes.
 
There are 3 kinds of attributes that you can add to your HTML tags: Element-specific, global, and event handler content attributes. The attributes that you can add to this tag are listed below.
 

Element-Specific Attributes

 
The following table shows the attributes that are specific to this tag/element.
 
Attributes Introduced by HTML5
 
Attributes Description             
autofocus (New) Automatically gives focus to this control when the page loads. This allows the user to start using the control without having to select it first.
disabled Disables the input control. The button won't accept changes from the user.
multiple When present, it specifies that multiple items can be selected at a time.
Name Defines a unique name for the drop-down list.
size Defines the number of visible items in the drop-down list.
 

Global Attributes

 
The following attributes are standard across all HTML 5 tags.
 
HTML5 Global Attributes
accesskey draggable style
class hidden tabindex
dir spellcheck  
contenteditable id title
contextmenu lang  

 
Event Handler Content Attributes

 
Here are the standard HTML 5 event handler content attributes.
 
onabort onerror* onmousewheel
onblur* onfocus* onpause
oncanplay onformchange onplay
oncanplaythrough onforminput onplaying
onchange oninput onprogress
onclick oninvalid onratechange
oncontextmenu onkeydown onreadystatechange
ondblclick onkeypress onscroll
ondrag onkeyup onseeked
ondragend onload* onseeking
ondragenter onloadeddata onselect
ondragleave onloadedmetadata onshow
ondragover onloadstart onstalled
ondragstart onmousedown onsubmit
ondrop onmousemove onsuspend
ondurationchange onmouseout ontimeupdate
onemptied onmouseover onvolumechange
onended onmouseup onwaiting
 

autofocus (New) 

 
This is a new attribute in HTML5. This tag is used to automatically gives focus to this control when the page loads.
 
Syntax
 
<select autofocus="autofocus">
 
For Example
  1. <select autofocus="autofocus">  
  2.     <option value="volvo">-Select Color-</option>  
  3.     <option value="volvo">Red</option>  
  4.     <option value="saab">Green</option>  
  5.     <option value="opel">Pink</option>  
  6.     <option value="audi">Blue</option>  
  7. </select>  

Disabled attribute

 
The disabled attribute specifies that a drop-down list should be disabled. A disabled drop-down list is unusable and un-clickable.
 
Syntax
 
<select disabled="disabled">
 
For Example
  1. <select disabled ="disabled">  
  2.     <option value="volvo">-Select Color-</option>  
  3.     <option value="volvo">Red</option>  
  4.     <option value="saab">Green</option>  
  5.     <option value="opel">Pink</option>  
  6.     <option value="audi">Blue</option>  
  7. </select>  

Multiple Attribute

 
The multiple attribute specifies that multiple options can be selected at the same time.
 
Syntax
 
<select multiple="multiple">
 
For Example
  1. <select multiple="multiple" name="D1">  
  2.     <option value="volvo">-Select Color-</option>  
  3.     <option value="volvo">Red</option>  
  4.     <option value="saab">Green</option>  
  5.     <option value="opel">Pink</option>  
  6.     <option value="audi">Blue</option>  
  7. </select>  

Size Attribute

 
The size attribute specifies the number of visible options in a drop-down list.
 
Syntax
 
<select size="value">
 
For Example
  1. <select size="3">  
  2.     <option value="volvo">-Select Color-</option>  
  3.     <option value="volvo">Red</option>  
  4.     <option value="saab">Green</option>  
  5.     <option value="opel">Pink</option>  
  6.     <option value="audi">Blue</option>  
  7. </select>  

Using all Attribute

 
For Example
  1. <html>  
  2.     <body>  
  3.         <table style="width: 49%">  
  4.             <tr>  
  5.                 <td>  
  6.             Disabled attribute  
  7.         </td>  
  8.                 <td>  
  9.                     <select disabled="disabled">  
  10.                         <option value="volvo">-Select Color-</option>  
  11.                         <option value="volvo">Red</option>  
  12.                         <option value="saab">Green</option>  
  13.                         <option value="opel">Pink</option>  
  14.                         <option value="audi">Blue</option>  
  15.                     </select>  
  16.                 </td>  
  17.             </tr>  
  18.             <tr>  
  19.                 <td>  
  20.             AutoFocus Attribute  
  21.         </td>  
  22.                 <td>  
  23.                     <select autofocus="autofocus">  
  24.                         <option value="volvo">-Select Color-</option>  
  25.                         <option value="volvo">Red</option>  
  26.                         <option value="saab">Green</option>  
  27.                         <option value="opel">Pink</option>  
  28.                         <option value="audi">Blue</option>  
  29.                     </select>  
  30.                 </td>  
  31.             </tr>  
  32.             <tr>  
  33.                 <td>  
  34.             Multiple Attribute  
  35.         </td>  
  36.                 <td>  
  37.                     <select multiple="multiple" name="D1">  
  38.                         <option value="volvo">-Select Color-</option>  
  39.                         <option value="volvo">Red</option>  
  40.                         <option value="saab">Green</option>  
  41.                         <option value="opel">Pink</option>  
  42.                         <option value="audi">Blue</option>  
  43.                     </select>  
  44.                 </td>  
  45.             </tr>  
  46.             <tr>  
  47.                 <td>  
  48.             Size Attribute  
  49.         </td>  
  50.                 <td>  
  51.                     <select size="3">  
  52.                         <option value="volvo">-Select Color-</option>  
  53.                         <option value="volvo">Red</option>  
  54.                         <option value="saab">Green</option>  
  55.                         <option value="opel">Pink</option>  
  56.                         <option value="audi">Blue</option>  
  57.                     </select>  
  58.                 </td>  
  59.             </tr>  
  60.         </table>  
  61.     </body>  
  62. </html>  
Internet explorer
 
select1.gif 
 
Fire Fox  
 
select2.gif