HTML <select> Tag for Drop-Down Lists

 

ATTENTION: THIS PAGE IS Valid HTML 5 AND IS BEST VIEWED WITH HTML 5 - Please upgrade your browser or download one of the HTML 5 compatible browsers such as Mozilla Firefox, Chrome, Opera or IE 9 (March 14, 2011 or later). For more information see HTML 5 browsers.


If you find this helpful, please click the Google +1 Button to the left, if it is white, to make it turn blue or red. Thank you! (It also helps find this page again more easily.)


PDF mobile

The <select> Tag in HTML 5

The <select> tag is used to create a drop-down box with a selection list in an HTML form. It is one of the tags for interactive content in HTML.


<select> Tag Syntax

<body>
   ...
   ... flow content expected ...
   <form id="form-id" method="GET|POST|etc." action="target-URL">
      ...
      ... phrasing content expected ...<select>
         <optgroup>
            <option>... phrasing content ...</option>
         </optgroup>
         ... and/or ...
         <option>... phrasing content ...</option>
      </select>...
      ...
   </form>
   ...
   ... phrasing content expected ...<select form="form-id">
      <optgroup>
         <option>... phrasing content ...</option>
      </optgroup>
      ... and/or ...
      <option>... phrasing content ...</option>
   </select>...
   ...
</body>
Rules for coding HTML select elements

Make sure you understand the difference between a tag and element and are familiar with the definitions of namespace and other HTML terms.

  1. Code the select element where phrasing content is expected, usually inside a form element.
  2. Begin the select element with a starting <select> tag. The element name uses lower case letters and should be in the HTML namespace, which it will pick up automatically from the xmlns attribute on the <html> tag.
  3. If the field is for a form that can be submitted but is outside that form element, include a form attribute referencing the form the select is to be associated with.
  4. Include any other attributes on the <select> tag as appropriate.
  5. Inside the select element, between the <select> start tag and </select> end tag, code the inner HTML phrasing content.
  6. End the select element with a matching </select> closing tag.
Content Model
Contents of the select element

The content of the select element can include HTML comments, text content and only those HTML tags that can be used in phrasing content.


<select> Tag Attributes

Attributes of the <select> tag
global attributes In addition to the personal attributes of the <select> tag below, any of the common HTML attributes can also be coded.
autofocus="autofocus" Sets the value of the <select autofocus> boolean attribute to true. Omitting it sets to false.
disabled="disabled" Sets the value of the <select disabled> boolean attribute to true. Omitting it sets to false.
form
multiple="multiple" Sets the value of the <select multiple> boolean attribute to true. Omitting it sets to false.
name
size

<select> Tag Examples

Examples of the select tag in HTML 5

Changes in HTML 5 - <select> Tag

What's new in HTML 5

The autofocus="autofocus" and form attributes have been added.

Differences between HTML 5 and earlier versions of HTML

The 2000-2010 Recommendations from the W3C HTML Working Group defined the HTML namespace for the select element type name along with the names of all HTML element types. In older (pre-2000) versions of HTML, element type names were not associated with a namespace.


Valid HTML 5