HTML <option> tag

The <option> tag is used to add items to a drop down list. You should place the text that will appear for an item between <option> and </option>. The <option> tag goes inside the <select> tag.

Attributes

Attribute Description Possible values
disabled Disables an option (will be grayed out and inaccessible) disabled
label Specifies alternative text for an option which will be displayed instead of the text you put between the <option> and </option> tags altText
selected Specifies that an option will be automatically selected when the dropdown list loads. The first option in a dropdown list is always selected by default, you can change that using this attribute selected
value Specifies the value for an option. This value will be sent to the server when the user submits the form and it is processed theValue

Standard attributes

class, dir, id, lang, style, title, xml:lang

For more information on standard attributes, check out our HTML standard attributes reference page.

Event attributes

onclick, ondblclick, onmousedown, onmouseup, onmouseover, onmousemove, onmouseout, onkeypress, onkeydown, onkeyup

For more information on event attributes, check out our HTML event attributes reference page.

Example

<label for="browser">Which is your favorite web browser?</label> <select name="browser"> <option value="FF">Firefox</option> <option value="Opera" selected="selected">Opera</option> <option value="Chrome">Chrome</option> <option value="Safari">Safari</option> <option value="IE">Internet Explorer</option> </select>
Output:

Tips & notes

Use CSS to style form elements in many ways like setting a border, font size and color, background color, padding, and much more.

Use the <optgroup> tag to group together related elements in a dropdown list under one heading for better organization and usability.

Web Reference
  1. CSS reference
  2. RSS reference
  3. HTML reference


© Copyright 2011-2012 Landofcode.com
Terms of use | Privacy policy | Copyright information | Make a donation