Code has been added to clipboard!

HTML select Tag

Reading time 3 min
Published Jun 29, 2017
Updated Sep 11, 2019

HTML select: Main Tips

  • HTML select tags define a select element - a form control with a menu of options.
  • Each option is wrapped in <option> tags.
  • You must include both starting and ending select tags.
  • Not only HTML select tags have eight tag-specific attributes, they also support global ones.

Usage of HTML select Tags

Wrapping content with HTML select tags creates a dropdown list with one or more options to select:

Example
<select name="housepets">
  <option value="cat">Cat</option>
  <option value="dog">Dog</option>
  <option value="llama">Llama</option>
  <option value="rabbit">Rabbit</option>
  <option value="animal">Animal</option>
</select>

It is mostly used within a <form> element to collect user input.

HTML select element contains <option> elements that define menu options. Each of them should have their own value as an attribute. If it is not included, the text content of the element is taken as the value.

Mostly Used select Tag Attributes

There are eight tag-specific attributes commonly used with HTML select tags.

autocomplete specifies if the browser can autofill field values:

Example
<select name="holiday_destination" autocomplete="off">
  <option value="bra">Sao Paulo</option>
  <option value="cub">Havana</option>
  <option value="fji">Suva</option>
  <option value="jam">Kingston</option>
  <option value="mdv">Male</option>
</select>

autofocus focuses the drop-down list automatically when the page loads:

Example
<select name="vehicles" autofocus>
  <option value="car">Car</option>
  <option value="bike">Bike</option>
  <option value="bicycle">Bicycle</option>
</select>

Note: only one form element can have autofocus in a single page.

disabled disables the drop-down list:

Example
<select name="mediatype" disabled>
  <option value="mp4">MP4</option>
  <option value="mov">MOV</option>
  <option value="flv">FLV</option>
</select>

form links the selected element to one or more forms:

Example
<form action="process.php" id="language">
  Primary Language: <input type="text" name="lang">
  <input type="submit">
</form>

<select name="expertise" form="language">
  <option value="speakwrite">Speak/Write</option>
  <option value="speak">Speak</option>
  <option value="write">Write</option>
</select>

multiple enables selection of multiple options at once:

Example
<select name="languages" multiple>
  <option value="english">English</option>
  <option value="french">French</option>
  <option value="russian">Russian</option>
  <option value="tamil">Tamil</option>
  <option value="spanish">Spanish</option>
</select>

Note: most browsers will replace the dropdown menu with a scrolling list box if you enable multiple.

name defines the name for the HTML dropdown menu:

Example
<select name="department">
  <option value="parks">Parks</option>
  <option value="rnd">R&D</option>
  <option value="finance">Finance</option>
  <option value="rec">Recreational</option>
  <option value="purchasing">Purchasing</option>
</select>

required makes the selection of an option within a list mandatory before submitting the form:

Example
<select name="pet" required>
  <option value="lama">Lama</option>
  <option value="racoon">Racoon</option>
  <option value="mouse">Mouse</option>
<input type="submit">
</select>

If the menu is presented by the browser as a scrolling list box, size defines the number of options to be displayed:

Example
<select name="meals" size="2">
  <option value="eggs">Eggs</option>
  <option value="salad">Salad</option>
  <option value="bread">Bread</option>
  <option value="ham">Ham</option>
</select>

Default Option vs. Placeholder

In the examples we reviewed, one option was always shown from the start. When using HTML select, default option is usually the first of the selection. If you wish to choose a different option as HTML select default value, you need to add the selected keyword:

Example
<select name="lunch">
  <option value="chic">Chicken pot pie</option>
  <option value="beef">Beef stew</option>
  <option value="pizza" selected>Pepperoni pizza</option>
  <option value="jelly">Jelly beans</option>
</select>

If you don't want any of the options to show as default, you can also create an HTML select placeholder. To do that, use both selected and disabled on an option that has no value:

Example
<select name="dessert">
  <option value="" disabled selected>Please choose one</option>
  <option value="choc">Chocolate cake</option>
  <option value="mango">Mango sorbet</option>
  <option value="car">Caramel pudding</option>
  <option value="pick">Pickles</option>
</select>

Browser Support

Chrome
All
Edge
All
Firefox
1+
IE
All
Opera
All
Safari
All

Mobile Browser Support

Chrome
All
Firefox
4+
Opera
All
Safari
All
Basics
Introduction
Syntax
Editors
Basic Examples
Head Section
<!DOCTYPE>
Tags and Elements
Semantic Elements
Tags Reference
Attributes
Comments
Block and Inline Elements
Forms
Form Elements
Input
Responsive Web Design
Inline Scripts
Uniform Resource Locator
Redirect
XHTML
Geolocation
Drag and Drop
Local Storage
Web Workers
Server-Sent Events
Character Encoding
Text Formatting
Quotation and Citation Elements
Headings
Paragraphs
Links
Tables
Lists
Symbols
Space
Tab
Styles
Computer Code
Layout
Classes
Colors
Images
iframes
Audio Player
Video Player
YouTube Videos
Multimedia
Canvas
SVG
<!-- -->
<a>
<abbr>
<acronym> DEPRECATED
<address>
<applet> DEPRECATED
<article>
<aside>
<audio>
<b>
<base>
<basefont> DEPRECATED
<bdi>
<bdo>
<big> DEPRECATED
<blink> DEPRECATED
<blockquote>
<body>
<br>
<button>
<canvas>
<caption>
<center> DEPRECATED
<cite>
<code>
<col>
<colgroup>
<datalist>
<dd>
<del>
<details>
<dfn>
<dialog>
<dir> DEPRECATED
<div>
<dl>
<dt>
<em>
<embed>
<fieldset>
<figcaption>
<figure>
<font> DEPRECATED
<footer>
<form>
<frame> DEPRECATED
<frameset> DEPRECATED
<h1> – <h6>
<head>
<header>
<hr>
<html>
<i>
<iframe>
<img>
<input>
<ins>
<kbd>
<keygen> DEPRECATED
<label>
<legend>
<li>
<link>
<main>
<map>
<mark>
<menu>
<menuitem> DEPRECATED
<meta>
<meter>
<nav>
<noframes> DEPRECATED
<noscript>
<object>
<ol>
<optgroup>
<option>
<output>
<p>
<param>
<pre>
<progress>
<q>
<rp>
<rt>
<ruby>
<s>
<samp>
<script>
<section>
<select>
<small>
<source>
<span>
<strike> DEPRECATED
<strong>
<style>
<sub>
<summary>
<sup>
<table>
<tbody>
<td>
<tfoot>
<th>
<thead>
<time>
<title>
<tr>
<track>
<tt> DEPRECATED
<u>
<ul>
<var>
<video>
<wbr>