Sometimes, we want to fix default select option is blank with HTML.
In this article, we’ll look at how to fix default select option is blank with HTML.
How to fix default select option is blank with HTML?
To fix default select option is blank with HTML, we add the selected
attribute to the default option.
For instance, we write
<select>
<option disabled selected value>-- select an option --</option>
<option>Option 1</option>
<option>Option 2</option>
<option>Option 3</option>
</select>
to add the default option with
<option disabled selected value>-- select an option --</option>
We add the selected
attribute to it to make it the default option.
Conclusion
To fix default select option is blank with HTML, we add the selected
attribute to the default option.