How to make an input tag read-only using HTML?
Published March 12, 2021
To make an
input tag field readonly, you can pass an attribute called
readonly to the tag in HTML.
<!-- Make `Input` Tag Readonly in HTML --> <input type="text" readonly />
- Adding the
readonlyattribute to the
inputtag will restrict the user from entering text into the
inputbut the value in the
inputtag will be visible to the user if there is any.
For example, let's set a value in the
input tag using the
value attribute and make it readonly.
<input type="text" value="I'm a value which can only be copied" readonly />
That's all! 😃
See the above code live in JSBin