In this section, we will learn what the disabled attribute is and how to use it.
What is disabled Attribute in HTML <option> Tag?
The disabled attribute, as the name suggests, is used to disable the use of an <option> element.
This means users won’t be able to select that option from the list anymore.
We use this attribute when we want to temporarily stop users from picking a specific option from a list but also be able to see that option.
Note: browsers still display a disabled option in a list but in a gray shape to signal users that the option is not selectable.
HTML disabled Attribute in <option> Tag Syntax:
<option disabled> </option>
<option> Tag disabled Attribute Values
The disabled attribute is a boolean one and for this reason, we only need to put this attribute in the opening tag of the target <option> element. Basically, there’s no need to set a value for this attribute.
Example: using disabled attribute in HTML <option> tag
See the Pen using disabled attribute in HTML <option> tag by Omid Dehghan (@odehghan) on CodePen.
In this example, the red option is disabled and so users can’t pick that option.