Categories
HTML

How to prevent user from typing in text field without disabling the field with HTML?

Spread the love

Sometimes, we want to prevent user from typing in text field without disabling the field with HTML.

In this article, we’ll look at how to prevent user from typing in text field without disabling the field with HTML.

How to prevent user from typing in text field without disabling the field with HTML?

To prevent user from typing in text field without disabling the field with HTML, we can add the readonly attribute to the input.

For instance, we write

<input readonly type="text" />

to stop users from enter text into the input without making it look disabled.

Conclusion

To prevent user from typing in text field without disabling the field with HTML, we can add the readonly attribute to the input.

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 *