HTML readonly attribute

The presence of readonly attribute makes the text uneditable. The user can only read the text and can not edit.

<p>First name: <input type="text" name="fname" value="john" readonly> </p>
<p>Last name: <input type="text" name="lname" value="david" > </p>
</>

First name:

Last name:

Attribute values

All possible values of readonly attribute

readonly attribute is a boolean attribute.

Related Tags

The tags that support readonly attribute

<textarea> tag

textarea tag defines multiline resizeable texte ara.

<textarea cols="50" rows="50" readonly> 
Here the text can not be entered. But the text is still focusable.
</textarea>
Try</>

<input> tag

Input element allows the user to enter data in the form. This element is used in the form element.

<input type="text" name="m" value="Mr." readonly>
Try</>

Difference between readonly and disabled attributes

readonly input elements are focusable and the text can be selected. The user can interact with the content of readonly elements. While disabled elements are not focusable.



Was this article helpful?