<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.
- Code the select element where phrasing content is expected, usually inside a form element.
- 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. - 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. - Include any other attributes on the <select> tag as appropriate.
- Inside the select element, between the
<select>
start tag and</select>
end tag, code the inner HTML phrasing content. - 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.