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 theinputtag will restrict the user from entering text into theinputbut the value in theinputtag 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