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
readonly
attribute to theinput
tag will restrict the user from entering text into theinput
but the value in theinput
tag 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