To disable an input field, you can pass an attribute called disabled
to the tag in HTML.
<!-- Disable `Input` Tag in HTML -->
<input type="text" disabled />
- Adding the
disabled
attribute to theinput
tag will restrict the user to enter text or content to theinput
and will have a grayed-out color unless you specify a color for the disabled state in CSS.
For example, let's set a value in the input
tag using the value
attribute and then disable the input tag.
<input type="text" value="I'm a value which can only be copied" disabled />
That's all! 😃
See the above code live in JSBin