Code has been added to clipboard!

HTML option Tag

Reading time 1 min
Published Jun 27, 2017
Updated Oct 2, 2019

HTML option: Main Tips

  • HTML <option> specifies the possible options in a drop-down menu.
  • <option> HTML works together with <select> element to create a drop-down menu for users to choose answers.
  • If the option list contains many suggested answers, it is better to divide them into groups with <optgroup>.

Purpose of option

<option> HTML sets suggested answers in <select> element list.

Example
<p>Which pet would you like to keep at home?</p>
  <select>
  <option value="cat">Cat</option>
  <option value="wolf">Wolf</option>
  <option value="llama">Llama</option>
</select>
Udacity
Pros
  • Simplistic design (no unnecessary information)
  • High-quality courses (even the free ones)
  • Variety of features
Main Features
  • Nanodegree programs
  • Suitable for enterprises
  • Paid certificates of completion
Coursera
Pros
  • Professional service
  • Flexible timetables
  • A variety of features to choose from
Main Features
  • Professional certificates of completion
  • University-level courses
  • Multiple Online degree programs
Datacamp
Pros
  • Great user experience
  • Offers quality content
  • Very transparent with their pricing
Main Features
  • Free certificates of completion
  • Focused on data science skills
  • Flexible learning timetable

Attributes for option

selected

Make a specific HTML option selected as soon as the list opens by applying the selected attribute.

Example
<p>Which pet would you like to keep at home?</p>
  <select>
  <option value="cat">Cat</option>
  <option value="wolf">Wolf</option>
  <option value="llama" selected>Llama</option>
</select>

disabled

When the opening HTML <option> tag contains the disabled attribute, the option won't be checkable.

Example
<p>Which pet would you like to keep at home?</p>
  <select>
  <option value="cat" disabled>Cat</option>
  <option value="wolf">Wolf</option>
  <option value="llama">Llama</option>
</select>

label

HTML option label defines a shorter name for an option. The final option HTML list contains the shortened version.

Example
<p>Which pet would you like to keep at home?</p>
  <select>
  <option label="Cat">Cat - the tiger of the house</option>
  <option label="Dog">Dog - best friend of the cat</option>
  <option label="Llama">Llama - just fabulous</option>
</select>

value

When the opening HTML <option> tag has the value attribute, it indicates the answer to be sent to a server (after an option is selected).

Example
<p>Which pet would you like to keep at home?</p>
  <select>
  <option value="cat">Cat</option>
  <option value="wolf">Wolf</option>
  <option value="llama">Llama</option>
</select>

Browser support

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

Mobile browser support

Browser image
Chrome
All
Browser image
Firefox
4+
Browser image
Opera
All
Browser image
Safari
All

Latest Udacity Coupon Found:

Verified STAFF PICK

75% OFF COURSES

Udacity Black Friday Offer

The best time to save on Udacity courses is now - follow this coupon to access a 75% Udacity Black Friday discount & enjoy learning at a very low cost!

Expiration date: 01/03/2021
3176 People Used
Only 97 Left
Rating
5.0