Categories
HTML

How to make HTML select read only?

Spread the love

Sometimes, we want to make HTML select read only.

In this article, we’ll look at how to make HTML select read only.

How to make HTML select read only?

To make HTML select read only, we disable all the select’s options.

For instance, we write

<select>
  <option disabled>1</option>
  <option selected>2</option>
  <option disabled>3</option>
</select>

to disable the options we don’t want the user to select with the disabled attribute.

And we set the default option with the selected attribute.

Conclusion

To make HTML select read only, we disable all the select’s options.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

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