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

Feel free to share if you found this useful 😃.


Share on: Facebook Twitter