How to add default text which won’t be shown in drop-down list with HTML?

Spread the love

Sometimes, we want to add default text which won’t be shown in drop-down list with HTML.

In this article, we’ll look at how to add default text which won’t be shown in drop-down list with HTML.

How to add default text which won’t be shown in drop-down list with HTML?

To add default text which won’t be shown in drop-down list with HTML, we add a disabled option element.

For instance, we write

<select>
  <option selected disabled hidden>Choose here</option>
  <option value="1">One</option>
  <option value="2">Two</option>
  <option value="3">Three</option>
  <option value="4">Four</option>
  <option value="5">Five</option>
</select>

to disable the first option with the disabled attribute.

Thne the option can’t be selected but it’ll show in the drop down.

Conclusion

To add default text which won’t be shown in drop-down list with HTML, we add a disabled option element.

Leave a Reply

Your email address will not be published. Required fields are marked *