HTML readonly attribute

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

Example

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

readonly attribute values

readonly attribute is a boolean attribute.

Related Tags

The tags which support this attribute are as follows.

<textarea> tag

textarea tag defines multiline resizeable texte ara.

Example

<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.

Example


<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?

 

Email:

Message:

Get the newsletter